AlaaElsayed commited on
Commit
851add9
ยท
verified ยท
1 Parent(s): 3a86daf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -14
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
- # Download the model from Hugging Face model repo
7
  model_path = "best.pt"
 
 
 
 
 
8
  if not os.path.exists(model_path):
9
- url = "https://huggingface.co/AlaaElsayed/YoloModel/resolve/main/best.pt"
10
- r = requests.get(url)
11
- with open(model_path, 'wb') as f:
12
  f.write(r.content)
13
 
14
- # Load the YOLOv5 model
15
- model = torch.hub.load('ultralytics/yolov5', 'custom', path=model_path, source='local')
16
 
17
- # Define the detection function
18
  def detect(image):
19
  results = model(image)
20
- return Image.fromarray(results.render()[0]) # Convert to PIL for Gradio
21
 
22
- # Create Gradio interface
23
  demo = gr.Interface(
24
  fn=detect,
25
  inputs=gr.Image(type="pil"),
26
  outputs=gr.Image(type="pil"),
27
- title="YOLOv5 Object Detector",
28
- description="Upload an image and let YOLOv5 detect objects using your custom model!"
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()