capradeepgujaran
commited on
Commit
•
49a323c
1
Parent(s):
b6ce847
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
from groq import Groq
|
5 |
import time
|
6 |
-
from PIL import Image
|
7 |
import io
|
8 |
import os
|
9 |
|
@@ -38,7 +39,7 @@ def create_monitor_interface():
|
|
38 |
if frame is None:
|
39 |
return "No frame received"
|
40 |
|
41 |
-
frame_pil =
|
42 |
img_byte_arr = io.BytesIO()
|
43 |
frame_pil.save(img_byte_arr, format='JPEG')
|
44 |
img_byte_arr = img_byte_arr.getvalue()
|
@@ -96,22 +97,29 @@ def create_monitor_interface():
|
|
96 |
gr.Markdown("# Real-time Safety Monitoring System")
|
97 |
|
98 |
with gr.Row():
|
99 |
-
|
100 |
-
output_image =
|
101 |
|
102 |
-
analysis_text =
|
103 |
|
104 |
-
def
|
105 |
if image is None:
|
106 |
-
return None, "
|
107 |
processed_frame, analysis = monitor.process_frame(image)
|
108 |
return processed_frame, analysis
|
109 |
|
110 |
-
|
111 |
-
fn=
|
112 |
-
inputs=[
|
113 |
outputs=[output_image, analysis_text],
|
114 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
return demo
|
117 |
|
|
|
1 |
import gradio as gr
|
2 |
+
from gradio.components import Image, Textbox, Markdown
|
3 |
import cv2
|
4 |
import numpy as np
|
5 |
from groq import Groq
|
6 |
import time
|
7 |
+
from PIL import Image as PILImage
|
8 |
import io
|
9 |
import os
|
10 |
|
|
|
39 |
if frame is None:
|
40 |
return "No frame received"
|
41 |
|
42 |
+
frame_pil = PILImage.fromarray(frame)
|
43 |
img_byte_arr = io.BytesIO()
|
44 |
frame_pil.save(img_byte_arr, format='JPEG')
|
45 |
img_byte_arr = img_byte_arr.getvalue()
|
|
|
97 |
gr.Markdown("# Real-time Safety Monitoring System")
|
98 |
|
99 |
with gr.Row():
|
100 |
+
input_image = Image(label="Input Image", type="numpy", tool="upload")
|
101 |
+
output_image = Image(label="Analysis Feed", type="numpy")
|
102 |
|
103 |
+
analysis_text = Textbox(label="Safety Analysis", lines=5)
|
104 |
|
105 |
+
def analyze_image(image):
|
106 |
if image is None:
|
107 |
+
return None, "No image provided"
|
108 |
processed_frame, analysis = monitor.process_frame(image)
|
109 |
return processed_frame, analysis
|
110 |
|
111 |
+
input_image.change(
|
112 |
+
fn=analyze_image,
|
113 |
+
inputs=[input_image],
|
114 |
outputs=[output_image, analysis_text],
|
115 |
)
|
116 |
+
|
117 |
+
gr.Markdown("""
|
118 |
+
## Instructions:
|
119 |
+
1. Upload an image using the input panel
|
120 |
+
2. The system will automatically analyze the image for safety concerns
|
121 |
+
3. Results will be shown in the analysis feed and text box
|
122 |
+
""")
|
123 |
|
124 |
return demo
|
125 |
|