Skip to content

Commit 65b2171

Browse files
committed
Merge branch 'main' into use-our-fork-for-test
2 parents 6f6844d + 2b7c23e commit 65b2171

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+61
-120
lines changed

components/models/ImageClassification.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { useState, useEffect, useCallback } from 'react';
22
import { Image, StyleSheet } from 'react-native';
3-
import { launchCamera, launchImageLibrary } from 'react-native-image-picker';
43
import SelectField from '../form/SelectField';
54
import TextField from '../form/TextField';
65
import Button from '../form/Button';
76
import Progress from '../Progress';
7+
import { usePhoto } from '../../utils/photo';
88

99
export const title = 'Image Classification';
1010

@@ -38,15 +38,7 @@ export function Interact({ runPipe }: InteractProps): JSX.Element {
3838
setWIP(false);
3939
}, []);
4040

41-
const takePhoto = useCallback(async () => {
42-
const { assets: [ { uri } ] } = await launchCamera();
43-
call(uri);
44-
}, []);
45-
46-
const selectPhoto = useCallback(async () => {
47-
const { assets: [ { uri } ] } = await launchImageLibrary();
48-
call(uri);
49-
}, []);
41+
const { selectPhoto, takePhoto } = usePhoto((uri) => call(uri));
5042

5143
return (
5244
<>

components/models/ImageSegmentation.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useState, useEffect, useCallback, useRef } from 'react';
2-
import { launchCamera, launchImageLibrary } from 'react-native-image-picker';
32
import { StyleSheet } from 'react-native';
43
import { GCanvasView } from '@flyskywhy/react-native-gcanvas';
54
import { RawImage } from '@xenova/transformers/src/utils/image';
@@ -10,6 +9,7 @@ import Button from '../form/Button';
109
import Progress from '../Progress';
1110
import Canvas from '../Canvas';
1211
import { getImageData, createRawImage } from '../../utils/image';
12+
import { usePhoto } from '../../utils/photo';
1313

1414
export const title = 'Image Segmentation';
1515

@@ -45,16 +45,6 @@ export function Interact({ runPipe }: InteractProps): JSX.Element {
4545
setWIP(false);
4646
}, []);
4747

48-
const takePhoto = useCallback(async () => {
49-
const { assets: [ { uri } ] } = await launchCamera();
50-
call(uri);
51-
}, []);
52-
53-
const selectPhoto = useCallback(async () => {
54-
const { assets: [ { uri } ] } = await launchImageLibrary();
55-
call(uri);
56-
}, []);
57-
5848
useEffect(() => {
5949
const canvas = canvasRef.current;
6050
const ctx = canvas?.getContext('2d');
@@ -90,6 +80,8 @@ export function Interact({ runPipe }: InteractProps): JSX.Element {
9080
}
9181
}, [results]);
9282

83+
const { selectPhoto, takePhoto } = usePhoto((uri) => call(uri));
84+
9385
return (
9486
<>
9587
<Button

components/models/ImageToText.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { launchCamera, launchImageLibrary } from 'react-native-image-picker';
21
import React, { useState, useEffect, useCallback, useRef } from 'react';
32
import { Image, StyleSheet, Text } from 'react-native';
43
import SelectField from '../form/SelectField';
@@ -8,6 +7,7 @@ import BooleanField from '../form/BooleanField';
87
import Button from '../form/Button';
98
import Recorder from '../../utils/recorder';
109
import { useColor } from '../../utils/style';
10+
import { usePhoto } from '../../utils/photo';
1111

1212
export const title = 'Image to Text';
1313

@@ -36,15 +36,7 @@ export function Interact({ params, runPipe }: InteractProps): JSX.Element {
3636
setWIP(false);
3737
}, [params]);
3838

39-
const takePhoto = useCallback(async () => {
40-
const { assets: [ { uri } ] } = await launchCamera();
41-
call(uri);
42-
}, []);
43-
44-
const selectPhoto = useCallback(async () => {
45-
const { assets: [ { uri } ] } = await launchImageLibrary();
46-
call(uri);
47-
}, []);
39+
const { selectPhoto, takePhoto } = usePhoto((uri) => call(uri));
4840

4941
return (
5042
<>

components/models/ObjectDetection.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useState, useEffect, useCallback, useRef } from 'react';
2-
import { launchCamera, launchImageLibrary } from 'react-native-image-picker';
32
import { StyleSheet } from 'react-native';
43
import uniqolor from 'uniqolor';
54
import SelectField from '../form/SelectField';
@@ -8,6 +7,7 @@ import Button from '../form/Button';
87
import Progress from '../Progress';
98
import Canvas from '../Canvas';
109
import { getImageData, createRawImage } from '../../utils/image';
10+
import { usePhoto } from '../../utils/photo';
1111

1212
export const title = 'Object Detection';
1313

@@ -44,15 +44,7 @@ export function Interact({ runPipe }: InteractProps): JSX.Element {
4444
setWIP(false);
4545
}, []);
4646

47-
const takePhoto = useCallback(async () => {
48-
const { assets: [ { uri } ] } = await launchCamera();
49-
call(uri);
50-
}, []);
51-
52-
const selectPhoto = useCallback(async () => {
53-
const { assets: [ { uri } ] } = await launchImageLibrary();
54-
call(uri);
55-
}, []);
47+
const { selectPhoto, takePhoto } = usePhoto((uri) => call(uri));
5648

5749
useEffect(() => {
5850
const ctx = canvasRef.current?.getContext('2d');

components/models/ZeroShotImageClassification.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, { useState, useEffect, useCallback, useRef } from 'react';
2-
import { launchCamera, launchImageLibrary } from 'react-native-image-picker';
32
import { StyleSheet, Image } from 'react-native';
43
import TextField from '../form/TextField';
54
import BooleanField from '../form/BooleanField';
65
import Button from '../form/Button';
76
import Progress from '../Progress';
87
import { getImageData, createRawImage } from '../../utils/image';
8+
import { usePhoto } from '../../utils/photo';
99

1010
export const title = 'Zero Shot Image Classification';
1111

@@ -69,17 +69,10 @@ export function Interact({ runPipe }: InteractProps): JSX.Element {
6969
setWIP(false);
7070
}, [input, classes]);
7171

72-
const takePhoto = useCallback(async () => {
73-
const { assets: [ file ] } = await launchCamera();
74-
inferImage.current = await getImageData(file.uri, 512);
75-
setInput(file.uri);
76-
}, []);
77-
78-
const selectPhoto = useCallback(async () => {
79-
const { assets: [ file ] } = await launchImageLibrary();
80-
inferImage.current = await getImageData(file.uri, 512);
81-
setInput(file.uri);
82-
}, []);
72+
const { selectPhoto, takePhoto } = usePhoto(async (uri) => {
73+
inferImage.current = await getImageData(uri, 512);
74+
setInput(uri);
75+
});
8376

8477
return (
8578
<>
11.1 KB
11.5 KB
314 KB
13.4 KB
14.3 KB

0 commit comments

Comments
 (0)