Spaces:
Configuration error
Configuration error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
import uuid
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
def capture_image(image):
|
| 8 |
+
if image is None:
|
| 9 |
+
return None, "No image captured"
|
| 10 |
+
|
| 11 |
+
# Create temp directory if not exists
|
| 12 |
+
os.makedirs("temp_images", exist_ok=True)
|
| 13 |
+
|
| 14 |
+
# Generate unique filename
|
| 15 |
+
filename = f"temp_images/{uuid.uuid4().hex}.png"
|
| 16 |
+
cv2.imwrite(filename, cv2.cvtColor(image, cv2.COLOR_RGB2BGR))
|
| 17 |
+
|
| 18 |
+
return image, f"Image saved as {filename}"
|
| 19 |
+
|
| 20 |
+
# Gradio Interface
|
| 21 |
+
demo = gr.Interface(
|
| 22 |
+
fn=capture_image,
|
| 23 |
+
inputs=gr.Image(label="Capture from Webcam", type="numpy", image_mode="RGB"),
|
| 24 |
+
outputs=[gr.Image(label="Captured Image"), gr.Textbox(label="Status")],
|
| 25 |
+
live=True,
|
| 26 |
+
allow_flagging="never",
|
| 27 |
+
title="Step 1: Capture Webcam Image"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
demo.launch()
|