Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,36 @@
|
|
| 1 |
import torch
|
| 2 |
-
import gradio as gr
|
| 3 |
-
from PIL import Image
|
| 4 |
import requests
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
model_path = "best.pt"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
if not os.path.exists(model_path):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
with open(model_path, 'wb') as f:
|
| 12 |
f.write(r.content)
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
model = torch.hub.load('ultralytics/
|
| 16 |
|
| 17 |
-
#
|
| 18 |
def detect(image):
|
| 19 |
results = model(image)
|
| 20 |
-
return Image.fromarray(results.render()[0])
|
| 21 |
|
| 22 |
-
#
|
| 23 |
demo = gr.Interface(
|
| 24 |
fn=detect,
|
| 25 |
inputs=gr.Image(type="pil"),
|
| 26 |
outputs=gr.Image(type="pil"),
|
| 27 |
-
title="
|
| 28 |
-
description="Upload
|
| 29 |
)
|
| 30 |
|
| 31 |
-
demo.launch()
|
|
|
|
| 1 |
import torch
|
|
|
|
|
|
|
| 2 |
import requests
|
| 3 |
+
import os
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import gradio as gr
|
| 6 |
|
| 7 |
+
# ุงุณู
ุงูู
ูู ุงูู
ุญูู ููู
ูุฏูู
|
| 8 |
model_path = "best.pt"
|
| 9 |
+
|
| 10 |
+
# ุฑุงุจุท ุงูุชุญู
ูู ู
ู ุงูุฑูุจู ุจุชุงุนู ุนูู Hugging Face
|
| 11 |
+
model_url = "https://huggingface.co/AlaaElsayed/yolospace/resolve/main/best.pt"
|
| 12 |
+
|
| 13 |
+
# ุญู
ู ุงูู
ูุฏูู ูู ู
ุด ู
ูุฌูุฏ
|
| 14 |
if not os.path.exists(model_path):
|
| 15 |
+
r = requests.get(model_url)
|
| 16 |
+
with open(model_path, "wb") as f:
|
|
|
|
| 17 |
f.write(r.content)
|
| 18 |
|
| 19 |
+
# ุชุญู
ูู ู
ูุฏูู YOLO
|
| 20 |
+
model = torch.hub.load('ultralytics/yolov8', 'custom', path=model_path, source='local')
|
| 21 |
|
| 22 |
+
# ุฏุงูุฉ ุงููุดู
|
| 23 |
def detect(image):
|
| 24 |
results = model(image)
|
| 25 |
+
return Image.fromarray(results.render()[0])
|
| 26 |
|
| 27 |
+
# ูุงุฌูุฉ Gradio
|
| 28 |
demo = gr.Interface(
|
| 29 |
fn=detect,
|
| 30 |
inputs=gr.Image(type="pil"),
|
| 31 |
outputs=gr.Image(type="pil"),
|
| 32 |
+
title="YOLO Food Detector",
|
| 33 |
+
description="Upload a food image and yolo will detect the items!"
|
| 34 |
)
|
| 35 |
|
| 36 |
+
demo.launch()
|