capradeepgujaran commited on
Commit
49a323c
1 Parent(s): b6ce847

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
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 = Image.fromarray(frame)
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
- webcam = gr.Webcam(label="Webcam Feed")
100
- output_image = gr.Image(label="Analysis Feed")
101
 
102
- analysis_text = gr.Textbox(label="Safety Analysis", lines=5)
103
 
104
- def analyze_stream(image):
105
  if image is None:
106
- return None, "Webcam not started"
107
  processed_frame, analysis = monitor.process_frame(image)
108
  return processed_frame, analysis
109
 
110
- webcam.change(
111
- fn=analyze_stream,
112
- inputs=[webcam],
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