Spaces:
Running
Running
RakanAlsheraiwi
commited on
Commit
•
4136b14
1
Parent(s):
b97f088
Update app.py
Browse files
app.py
CHANGED
@@ -5,9 +5,11 @@ import gradio as gr
|
|
5 |
import pandas as pd
|
6 |
from transformers import pipeline
|
7 |
|
|
|
8 |
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
|
9 |
translator = pipeline("translation_en_to_ar", model="Helsinki-NLP/opus-mt-en-ar")
|
10 |
|
|
|
11 |
def detect_and_draw_image(input_image):
|
12 |
results = model(input_image)
|
13 |
detections = results.xyxy[0].numpy()
|
@@ -31,6 +33,7 @@ def detect_and_draw_image(input_image):
|
|
31 |
|
32 |
return input_image, df
|
33 |
|
|
|
34 |
def detect_and_draw_video(video_path):
|
35 |
cap = cv2.VideoCapture(video_path)
|
36 |
frames = []
|
@@ -73,16 +76,19 @@ def detect_and_draw_video(video_path):
|
|
73 |
|
74 |
return output_path, df
|
75 |
|
|
|
76 |
image_interface = gr.Interface(
|
77 |
fn=detect_and_draw_image,
|
78 |
inputs=gr.Image(type="pil", label="Upload Image"),
|
79 |
outputs=[gr.Image(type="pil"), gr.Dataframe(label="Object Counts")],
|
80 |
title="Object Detection for Images",
|
81 |
description="Upload an image to see the objects detected and their counts.",
|
82 |
-
gr.Examples(['assets/MessiVsAlhilal.jpg', 'assets/Manhattan002_0.webp'], inputs=input_image)
|
83 |
-
|
84 |
)
|
85 |
|
|
|
|
|
|
|
|
|
86 |
video_interface = gr.Interface(
|
87 |
fn=detect_and_draw_video,
|
88 |
inputs=gr.Video(label="Upload Video"),
|
@@ -91,5 +97,6 @@ video_interface = gr.Interface(
|
|
91 |
description="Upload a video to see the objects detected and their counts."
|
92 |
)
|
93 |
|
|
|
94 |
app = gr.TabbedInterface([image_interface, video_interface], ["Image Detection", "Video Detection"])
|
95 |
app.launch(debug=True)
|
|
|
5 |
import pandas as pd
|
6 |
from transformers import pipeline
|
7 |
|
8 |
+
# تحميل النموذج
|
9 |
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
|
10 |
translator = pipeline("translation_en_to_ar", model="Helsinki-NLP/opus-mt-en-ar")
|
11 |
|
12 |
+
# دالة لاكتشاف الكائنات في الصور
|
13 |
def detect_and_draw_image(input_image):
|
14 |
results = model(input_image)
|
15 |
detections = results.xyxy[0].numpy()
|
|
|
33 |
|
34 |
return input_image, df
|
35 |
|
36 |
+
# دالة لاكتشاف الكائنات في الفيديو
|
37 |
def detect_and_draw_video(video_path):
|
38 |
cap = cv2.VideoCapture(video_path)
|
39 |
frames = []
|
|
|
76 |
|
77 |
return output_path, df
|
78 |
|
79 |
+
# واجهة صورة
|
80 |
image_interface = gr.Interface(
|
81 |
fn=detect_and_draw_image,
|
82 |
inputs=gr.Image(type="pil", label="Upload Image"),
|
83 |
outputs=[gr.Image(type="pil"), gr.Dataframe(label="Object Counts")],
|
84 |
title="Object Detection for Images",
|
85 |
description="Upload an image to see the objects detected and their counts.",
|
|
|
|
|
86 |
)
|
87 |
|
88 |
+
# إضافة أمثلة للواجهة
|
89 |
+
image_interface.examples = ['assets/MessiVsAlhilal.jpg', 'assets/Manhattan002_0.webp']
|
90 |
+
|
91 |
+
# واجهة فيديو
|
92 |
video_interface = gr.Interface(
|
93 |
fn=detect_and_draw_video,
|
94 |
inputs=gr.Video(label="Upload Video"),
|
|
|
97 |
description="Upload a video to see the objects detected and their counts."
|
98 |
)
|
99 |
|
100 |
+
# دمج الواجهات
|
101 |
app = gr.TabbedInterface([image_interface, video_interface], ["Image Detection", "Video Detection"])
|
102 |
app.launch(debug=True)
|