Marolahy commited on
Commit
7ab3ff1
Β·
1 Parent(s): 0c2fb6c

Add video sample

Browse files
app.py CHANGED
@@ -1,19 +1,9 @@
1
  import gradio as gr
2
  import cv2
3
- import requests
4
- import os
5
 
6
  from ultralytics import YOLO
7
 
8
 
9
- # Function to download files
10
- def fetch_file(url, filename):
11
- if not os.path.exists(filename):
12
- response = requests.get(url)
13
- with open(filename, "wb") as file:
14
- file.write(response.content)
15
-
16
-
17
  # Function to process and display predictions on images
18
  def process_image(image_path):
19
  img = cv2.imread(image_path)
@@ -81,7 +71,7 @@ image_interface = gr.Interface(
81
  inputs=[gr.components.Image(type="filepath", label="Select Image")],
82
  outputs=[gr.components.Image(type="numpy", label="Processed Image")],
83
  title="Tomato Ripeness Detection",
84
- examples=["downloaded_image_0.jpg", "downloaded_image_1.jpg", "downloaded_image_1.jpg"],
85
  cache_examples=False,
86
  )
87
 
@@ -90,25 +80,11 @@ video_interface = gr.Interface(
90
  inputs=[gr.components.Video(label="Select Video")],
91
  outputs=[gr.components.Image(type="numpy", label="Processed Frame")],
92
  title="Tomato Ripeness Detection in Video",
93
- examples=["downloaded_video.mp4"],
94
  cache_examples=False,
95
  )
96
 
97
  if __name__ == "__main__":
98
- # URLs for image and video files
99
- media_urls = [
100
- "https://cdn.pixabay.com/photo/2021/04/03/00/39/tomatoes-6146243_640.jpg",
101
- "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHDLF2oUAlSLcxcxrRKz4ud0LKP5S7doeWRA&s",
102
- "https://freerangestock.com/sample/133867/cherry-tomatoes-with-green-leaves.jpg"
103
- ]
104
-
105
- # Downloading media files
106
- for index, url in enumerate(media_urls):
107
- if url.endswith(".mp4"):
108
- fetch_file(url, "downloaded_video.mp4")
109
- else:
110
- fetch_file(url, f"downloaded_image_{index}.jpg")
111
-
112
  # Create a tabbed interface for both image and video processing
113
  gr.TabbedInterface(
114
  [image_interface, video_interface],
 
1
  import gradio as gr
2
  import cv2
 
 
3
 
4
  from ultralytics import YOLO
5
 
6
 
 
 
 
 
 
 
 
 
7
  # Function to process and display predictions on images
8
  def process_image(image_path):
9
  img = cv2.imread(image_path)
 
71
  inputs=[gr.components.Image(type="filepath", label="Select Image")],
72
  outputs=[gr.components.Image(type="numpy", label="Processed Image")],
73
  title="Tomato Ripeness Detection",
74
+ examples=["samples/image_0.jpg", "samples/image_1.jpg", "samples/image_1.jpg"],
75
  cache_examples=False,
76
  )
77
 
 
80
  inputs=[gr.components.Video(label="Select Video")],
81
  outputs=[gr.components.Image(type="numpy", label="Processed Frame")],
82
  title="Tomato Ripeness Detection in Video",
83
+ examples=["samples/video.mp4"],
84
  cache_examples=False,
85
  )
86
 
87
  if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  # Create a tabbed interface for both image and video processing
89
  gr.TabbedInterface(
90
  [image_interface, video_interface],
downloaded_image_0.jpg β†’ samples/image_0.jpg RENAMED
File without changes
downloaded_image_1.jpg β†’ samples/image_1.jpg RENAMED
File without changes
downloaded_image_2.jpg β†’ samples/image_2.jpg RENAMED
File without changes
samples/video.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:439a7d87b9aaf5b49d87e5bb6d4b423860f570cfdd4ec870a4b1e4b79b1fdd50
3
+ size 3661477