-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathStyleTransferScreen.tsx
78 lines (72 loc) · 1.66 KB
/
StyleTransferScreen.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import Spinner from 'react-native-loading-spinner-overlay';
import { BottomBar } from '../components/BottomBar';
import { candy } from '../models/style_transfer';
import { getImageUri } from '../utils';
import { useStyleTransfer } from 'react-native-executorch';
import { View, StyleSheet, Image } from 'react-native';
export const StyleTransferScreen = ({
imageUri,
setImageUri,
}: {
imageUri: string;
setImageUri: (imageUri: string) => void;
}) => {
const model = useStyleTransfer({
modulePath: candy,
});
const handleCameraPress = async (isCamera: boolean) => {
const uri = await getImageUri(isCamera);
if (typeof uri === 'string') {
setImageUri(uri as string);
}
};
const runForward = async () => {
if (imageUri) {
try {
const output = await model.forward(imageUri);
setImageUri(output);
} catch (e) {
console.error(e);
}
}
};
if (!model.isModelReady) {
return (
<Spinner
visible={!model.isModelReady}
textContent={`Loading the model...`}
/>
);
}
return (
<>
<View style={styles.imageContainer}>
<Image
style={styles.image}
resizeMode="contain"
source={
imageUri
? { uri: imageUri }
: require('../assets/icons/executorch_logo.png')
}
/>
</View>
<BottomBar
handleCameraPress={handleCameraPress}
runForward={runForward}
/>
</>
);
};
const styles = StyleSheet.create({
imageContainer: {
flex: 6,
width: '100%',
padding: 16,
},
image: {
flex: 1,
borderRadius: 8,
width: '100%',
},
});