-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
43 lines (39 loc) · 1.12 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React, { useRef } from 'react';
import { View, Text, Image, Button } from 'react-native';
import { useTensor } from './hooks/useTensor';
import Canvas from 'react-native-canvas';
const App = () => {
const image = require('./chicken.jpg');
const imageRef = useRef(null);
const canvasRef = useRef(null);
const { isTfReady, result, load, isLoadingResult } = useTensor(canvasRef);
return (
<View
style={{
height: '100%',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
}}
>
<Image
ref={imageRef}
source={require('./chicken.jpg')}
style={{ width: 200, height: 200 }}
/>
{!isTfReady && <Text>Loading TFJS model...</Text>}
{isTfReady && result === '' && <Text>Model Ready</Text>}
{result !== '' && <Text>{result}</Text>}
{isLoadingResult ? <Text>Loading result...</Text> : <Button
title="Classify"
onPress={async () => {
await load(image);
}}
/>}
<Canvas
ref={imageRef} />
</View>
);
};
export default App;