Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -33,40 +33,25 @@ def detect_flash(image: Image.Image):
|
|
33 |
|
34 |
return output_image, message
|
35 |
|
36 |
-
def
|
37 |
-
|
38 |
-
success, frame = cap.read()
|
39 |
-
cap.release()
|
40 |
-
if success:
|
41 |
-
# Convert BGR to RGB
|
42 |
-
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
43 |
-
return Image.fromarray(frame_rgb)
|
44 |
-
return None
|
45 |
-
|
46 |
-
def process_webcam_video(video):
|
47 |
-
image = extract_first_frame(video)
|
48 |
-
if image:
|
49 |
-
return detect_flash(image)
|
50 |
-
else:
|
51 |
-
return None, "Could not read frame from video."
|
52 |
|
53 |
# Gradio interface
|
54 |
with gr.Blocks() as demo:
|
55 |
gr.Markdown("Flash Detection with YOLOv8")
|
56 |
-
gr.Markdown("Upload an image
|
57 |
|
58 |
-
with gr.
|
59 |
img_input = gr.Image(type="pil", label="Upload Image")
|
60 |
-
detect_btn = gr.Button("Detect Flash")
|
61 |
output_img = gr.Image(type="pil", label="Detected Image")
|
62 |
-
output_text = gr.Textbox(label="Detection Info")
|
63 |
-
detect_btn.click(fn=detect_flash, inputs=img_input, outputs=[output_img, output_text])
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
71 |
|
72 |
demo.launch()
|
|
|
33 |
|
34 |
return output_image, message
|
35 |
|
36 |
+
def clear_all():
|
37 |
+
return None, None, ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# Gradio interface
|
40 |
with gr.Blocks() as demo:
|
41 |
gr.Markdown("Flash Detection with YOLOv8")
|
42 |
+
gr.Markdown("Upload an image to detect flash.")
|
43 |
|
44 |
+
with gr.Row():
|
45 |
img_input = gr.Image(type="pil", label="Upload Image")
|
|
|
46 |
output_img = gr.Image(type="pil", label="Detected Image")
|
|
|
|
|
47 |
|
48 |
+
output_text = gr.Textbox(label="Detection Info", lines=6)
|
49 |
+
|
50 |
+
with gr.Row():
|
51 |
+
detect_btn = gr.Button("Detect Flash")
|
52 |
+
clear_btn = gr.Button("Clear")
|
53 |
+
|
54 |
+
detect_btn.click(fn=detect_flash, inputs=img_input, outputs=[output_img, output_text])
|
55 |
+
clear_btn.click(fn=clear_all, inputs=[], outputs=[img_input, output_img, output_text])
|
56 |
|
57 |
demo.launch()
|