Spaces:
Sleeping
Sleeping
muhammadIsmail
commited on
Commit
•
392f965
1
Parent(s):
bc3e9a1
Update app.py
Browse files
app.py
CHANGED
@@ -26,7 +26,21 @@ path = [['image_0.jpg'], ['image_1.jpg']]
|
|
26 |
video_path = [['video.mp4']]
|
27 |
|
28 |
def show_preds_image(image_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
image = cv2.imread(image_path)
|
|
|
|
|
30 |
outputs = model.predict(source=image_path)
|
31 |
results = outputs[0].cpu().numpy()
|
32 |
for i, det in enumerate(results.boxes.xyxy):
|
@@ -57,6 +71,8 @@ interface_image = gr.Interface(
|
|
57 |
|
58 |
def show_preds_video(video_path):
|
59 |
cap = cv2.VideoCapture(video_path)
|
|
|
|
|
60 |
while cap.isOpened():
|
61 |
ret, frame = cap.read()
|
62 |
if ret:
|
|
|
26 |
video_path = [['video.mp4']]
|
27 |
|
28 |
def show_preds_image(image_path):
|
29 |
+
# Save the user-uploaded image to the local directory
|
30 |
+
save_path = 'uploaded_image.jpg'
|
31 |
+
if isinstance(image_path, str) and image_path.startswith('data:'):
|
32 |
+
# Convert base64 to image
|
33 |
+
import base64
|
34 |
+
from io import BytesIO
|
35 |
+
from PIL import Image
|
36 |
+
base64_str = image_path.split(',')[1]
|
37 |
+
image = Image.open(BytesIO(base64.b64decode(base64_str)))
|
38 |
+
image.save(save_path)
|
39 |
+
image_path = save_path
|
40 |
+
|
41 |
image = cv2.imread(image_path)
|
42 |
+
if image is None:
|
43 |
+
raise ValueError(f"Image at path {image_path} could not be loaded.")
|
44 |
outputs = model.predict(source=image_path)
|
45 |
results = outputs[0].cpu().numpy()
|
46 |
for i, det in enumerate(results.boxes.xyxy):
|
|
|
71 |
|
72 |
def show_preds_video(video_path):
|
73 |
cap = cv2.VideoCapture(video_path)
|
74 |
+
if not cap.isOpened():
|
75 |
+
raise ValueError(f"Video at path {video_path} could not be loaded.")
|
76 |
while cap.isOpened():
|
77 |
ret, frame = cap.read()
|
78 |
if ret:
|