Aumkeshchy2003 commited on
Commit
aeec4bb
·
verified ·
1 Parent(s): c1a4fa5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -74
app.py CHANGED
@@ -59,7 +59,7 @@ def process_video(video_path):
59
  while cap.isOpened():
60
  ret, frame = cap.read()
61
  if not ret:
62
- break # Break if no more frames
63
 
64
  start_time = time.time()
65
 
@@ -109,15 +109,6 @@ def process_image(image):
109
  return Image.fromarray(img)
110
 
111
 
112
- def use_example_image():
113
- # Function to load the example image
114
- example_path = "pexels-hikaique-109919.jpg"
115
- if os.path.exists(example_path):
116
- return Image.open(example_path)
117
- else:
118
- print(f"Warning: Example image not found at {example_path}")
119
- return None
120
-
121
  css = """
122
  #title {
123
  text-align: center;
@@ -155,11 +146,6 @@ css = """
155
  border: none;
156
  }
157
 
158
- #example-btn {
159
- background-color: #27AE60;
160
- border: none;
161
- }
162
-
163
  .output-container {
164
  margin-top: 1.5rem;
165
  border: 2px dashed #3498DB;
@@ -207,68 +193,47 @@ with gr.Blocks(css=css, title="Real-Time YOLOv5 Video & Image Object Detection")
207
  )
208
 
209
  with gr.TabItem("Image Detection", elem_classes="tab-item"):
210
- # Define image_output before it's referenced
211
- image_output = gr.Image(
212
- label="Detected Objects",
213
- elem_id="image-output"
214
- )
215
-
216
- with gr.Row():
217
- image_input = gr.Image(
218
- type="pil",
219
- label="Upload Image",
220
- interactive=True
221
- )
222
-
223
- # Place buttons immediately below the upload section
224
- with gr.Row(elem_classes="button-row"):
225
- clear_button = gr.Button(
226
- "Clear",
227
- variant="secondary",
228
- elem_id="clear-btn"
229
- )
230
- example_button = gr.Button(
231
- "Use Example Image",
232
- variant="secondary",
233
- elem_id="example-btn"
234
- )
235
- submit_button = gr.Button(
236
- "Detect Objects",
237
- variant="primary",
238
- elem_id="submit-btn"
239
- )
240
-
241
- with gr.Row(elem_classes="output-container"):
242
- pass
243
-
244
- # Button click functions
245
- clear_button.click(
246
- fn=lambda: None,
247
- inputs=None,
248
- outputs=image_input
249
- )
250
-
251
- clear_button.click(
252
- fn=lambda: None,
253
- inputs=None,
254
- outputs=image_output
255
- )
256
-
257
- example_button.click(
258
- fn=use_example_image,
259
- inputs=None,
260
- outputs=image_input
261
- )
262
-
263
- submit_button.click(
264
- fn=process_image,
265
- inputs=image_input,
266
- outputs=image_output
267
- )
268
 
269
  gr.Markdown("""
270
  ### Powered by YOLOv5.
271
  This application allows real-time object detection using the YOLOv5 model.
272
  """, elem_classes="footer")
273
 
274
- demo.launch()
 
59
  while cap.isOpened():
60
  ret, frame = cap.read()
61
  if not ret:
62
+ break
63
 
64
  start_time = time.time()
65
 
 
109
  return Image.fromarray(img)
110
 
111
 
 
 
 
 
 
 
 
 
 
112
  css = """
113
  #title {
114
  text-align: center;
 
146
  border: none;
147
  }
148
 
 
 
 
 
 
149
  .output-container {
150
  margin-top: 1.5rem;
151
  border: 2px dashed #3498DB;
 
193
  )
194
 
195
  with gr.TabItem("Image Detection", elem_classes="tab-item"):
196
+ with gr.Row():
197
+ image_input = gr.Image(
198
+ type="pil",
199
+ label="Upload Image",
200
+ interactive=True
201
+ )
202
+
203
+ with gr.Row(elem_classes="button-row"): # Move button row here just below image_input
204
+ clear_button = gr.Button(
205
+ "Clear",
206
+ variant="secondary",
207
+ elem_id="clear-btn"
208
+ )
209
+ submit_button = gr.Button(
210
+ "Detect Objects",
211
+ variant="primary",
212
+ elem_id="submit-btn"
213
+ )
214
+
215
+ # Define image_output below input and buttons
216
+ image_output = gr.Image(
217
+ label="Detected Objects",
218
+ elem_id="image-output"
219
+ )
220
+
221
+ clear_button.click(
222
+ fn=lambda: None,
223
+ inputs=None,
224
+ outputs=image_output
225
+ )
226
+
227
+ submit_button.click(
228
+ fn=process_image,
229
+ inputs=image_input,
230
+ outputs=image_output
231
+ )
232
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
 
234
  gr.Markdown("""
235
  ### Powered by YOLOv5.
236
  This application allows real-time object detection using the YOLOv5 model.
237
  """, elem_classes="footer")
238
 
239
+ demo.launch()