Spaces:
Runtime error
Runtime error
Update app.js
Browse files
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("
|
| 9 |
const camera = useRef(null);
|
| 10 |
const devices = useCameraDevices();
|
| 11 |
-
const device =
|
| 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 === "
|
| 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 === "
|
| 73 |
onPress={() =>
|
| 74 |
-
setCameraType((prev) => (prev === "
|
| 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} />
|