gopichandra commited on
Commit
177439e
·
verified ·
1 Parent(s): b0980c1

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +6 -6
app.js CHANGED
@@ -5,10 +5,10 @@ import * as ImageManipulator from "expo-image-manipulator";
5
 
6
  const App = () => {
7
  const [hasPermission, setHasPermission] = useState(false);
8
- const [cameraType, setCameraType] = useState("rear"); // Default to rear camera
9
  const camera = useRef(null);
10
  const devices = useCameraDevices();
11
- const device = devices[cameraType];
12
 
13
  useEffect(() => {
14
  (async () => {
@@ -30,7 +30,7 @@ const App = () => {
30
  // Correct image orientation for the rear camera
31
  const fixedImage = await ImageManipulator.manipulateAsync(
32
  photo.path,
33
- [{ flip: cameraType === "rear" ? ImageManipulator.FlipType.Horizontal : undefined }], // Flip only for rear camera
34
  { compress: 1, format: ImageManipulator.SaveFormat.JPEG }
35
  );
36
 
@@ -44,7 +44,7 @@ const App = () => {
44
  name: "photo.jpg",
45
  });
46
 
47
- const response = await fetch("https://<your-gradio-url>", {
48
  method: "POST",
49
  body: formData,
50
  });
@@ -69,9 +69,9 @@ const App = () => {
69
  />
70
  <View style={styles.buttonContainer}>
71
  <Button
72
- title={`Switch to ${cameraType === "rear" ? "Front" : "Rear"} Camera`}
73
  onPress={() =>
74
- setCameraType((prev) => (prev === "rear" ? "front" : "rear"))
75
  }
76
  />
77
  <Button title="Capture Image" onPress={captureImage} />
 
5
 
6
  const App = () => {
7
  const [hasPermission, setHasPermission] = useState(false);
8
+ const [cameraType, setCameraType] = useState("back"); // Default to rear camera
9
  const camera = useRef(null);
10
  const devices = useCameraDevices();
11
+ const device = cameraType === "back" ? devices.back : devices.front;
12
 
13
  useEffect(() => {
14
  (async () => {
 
30
  // Correct image orientation for the rear camera
31
  const fixedImage = await ImageManipulator.manipulateAsync(
32
  photo.path,
33
+ [{ flip: cameraType === "back" ? ImageManipulator.FlipType.Horizontal : undefined }], // Flip for rear camera
34
  { compress: 1, format: ImageManipulator.SaveFormat.JPEG }
35
  );
36
 
 
44
  name: "photo.jpg",
45
  });
46
 
47
+ const response = await fetch("https://<your-gradio-backend-url>", {
48
  method: "POST",
49
  body: formData,
50
  });
 
69
  />
70
  <View style={styles.buttonContainer}>
71
  <Button
72
+ title={`Switch to ${cameraType === "back" ? "Front" : "Rear"} Camera`}
73
  onPress={() =>
74
+ setCameraType((prev) => (prev === "back" ? "front" : "back"))
75
  }
76
  />
77
  <Button title="Capture Image" onPress={captureImage} />