Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,28 +59,16 @@
|
|
| 59 |
# demo.launch()
|
| 60 |
|
| 61 |
|
| 62 |
-
|
| 63 |
-
import os
|
| 64 |
-
import requests
|
| 65 |
from ultralytics import YOLO
|
| 66 |
import pandas as pd
|
| 67 |
from PIL import Image, ImageDraw
|
| 68 |
import gradio as gr
|
| 69 |
|
| 70 |
-
# تحميل الموديل من Hugging Face لو مش موجود
|
| 71 |
-
model_path = "best.pt"
|
| 72 |
-
model_url = "https://huggingface.co/AlaaElsayed/yolospace/resolve/main/best.pt"
|
| 73 |
-
|
| 74 |
-
if not os.path.exists(model_path):
|
| 75 |
-
r = requests.get(model_url)
|
| 76 |
-
with open(model_path, "wb") as f:
|
| 77 |
-
f.write(r.content)
|
| 78 |
-
|
| 79 |
# تحميل الموديل
|
| 80 |
-
model = YOLO(
|
| 81 |
|
| 82 |
# تحميل بيانات التغذية
|
| 83 |
-
food_df = pd.read_csv("
|
| 84 |
|
| 85 |
# جلب القيم الغذائية
|
| 86 |
def get_nutrition(label):
|
|
@@ -100,7 +88,7 @@ def detect(image):
|
|
| 100 |
boxes = result.boxes
|
| 101 |
names = model.names
|
| 102 |
|
| 103 |
-
img = Image.fromarray(result.plot()) # الصورة
|
| 104 |
draw = ImageDraw.Draw(img)
|
| 105 |
|
| 106 |
for box in boxes:
|
|
@@ -123,3 +111,66 @@ demo = gr.Interface(
|
|
| 123 |
|
| 124 |
demo.launch()
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
# demo.launch()
|
| 60 |
|
| 61 |
|
|
|
|
|
|
|
|
|
|
| 62 |
from ultralytics import YOLO
|
| 63 |
import pandas as pd
|
| 64 |
from PIL import Image, ImageDraw
|
| 65 |
import gradio as gr
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
# تحميل الموديل
|
| 68 |
+
model = YOLO("best.pt")
|
| 69 |
|
| 70 |
# تحميل بيانات التغذية
|
| 71 |
+
food_df = pd.read_csv("Food.csv")
|
| 72 |
|
| 73 |
# جلب القيم الغذائية
|
| 74 |
def get_nutrition(label):
|
|
|
|
| 88 |
boxes = result.boxes
|
| 89 |
names = model.names
|
| 90 |
|
| 91 |
+
img = Image.fromarray(result.plot()) # الصورة عليها البوكسات
|
| 92 |
draw = ImageDraw.Draw(img)
|
| 93 |
|
| 94 |
for box in boxes:
|
|
|
|
| 111 |
|
| 112 |
demo.launch()
|
| 113 |
|
| 114 |
+
# import os
|
| 115 |
+
# import requests
|
| 116 |
+
# from ultralytics import YOLO
|
| 117 |
+
# import pandas as pd
|
| 118 |
+
# from PIL import Image, ImageDraw
|
| 119 |
+
# import gradio as gr
|
| 120 |
+
|
| 121 |
+
# # تحميل الموديل من Hugging Face لو مش موجود
|
| 122 |
+
# model_path = "best.pt"
|
| 123 |
+
# model_url = "https://huggingface.co/AlaaElsayed/yolospace/resolve/main/best.pt"
|
| 124 |
+
|
| 125 |
+
# if not os.path.exists(model_path):
|
| 126 |
+
# r = requests.get(model_url)
|
| 127 |
+
# with open(model_path, "wb") as f:
|
| 128 |
+
# f.write(r.content)
|
| 129 |
+
|
| 130 |
+
# # تحميل الموديل
|
| 131 |
+
# model = YOLO(model_path)
|
| 132 |
+
|
| 133 |
+
# # تحميل بيانات التغذية
|
| 134 |
+
# food_df = pd.read_csv("food_cleaned.csv")
|
| 135 |
+
|
| 136 |
+
# # جلب القيم الغذائية
|
| 137 |
+
# def get_nutrition(label):
|
| 138 |
+
# row = food_df[food_df["Food_Name"].str.lower() == label.lower()]
|
| 139 |
+
# if row.empty:
|
| 140 |
+
# return "No data"
|
| 141 |
+
# cals = row["Calories_per_100g"].values[0]
|
| 142 |
+
# fat = row["Fat_g"].values[0]
|
| 143 |
+
# protein = row["Protein_g"].values[0]
|
| 144 |
+
# carbs = row["Carbs_g"].values[0]
|
| 145 |
+
# return f"{label}: {cals} kcal, {fat}g fat, {protein}g protein, {carbs}g carbs"
|
| 146 |
+
|
| 147 |
+
# # دالة الكشف والرسم
|
| 148 |
+
# def detect(image):
|
| 149 |
+
# results = model.predict(image)
|
| 150 |
+
# result = results[0]
|
| 151 |
+
# boxes = result.boxes
|
| 152 |
+
# names = model.names
|
| 153 |
+
|
| 154 |
+
# img = Image.fromarray(result.plot()) # الصورة مع البوكسات
|
| 155 |
+
# draw = ImageDraw.Draw(img)
|
| 156 |
+
|
| 157 |
+
# for box in boxes:
|
| 158 |
+
# cls_id = int(box.cls[0])
|
| 159 |
+
# label = names[cls_id]
|
| 160 |
+
# nutrition = get_nutrition(label)
|
| 161 |
+
# xy = box.xyxy[0].tolist()
|
| 162 |
+
# draw.text((xy[0], xy[1] - 10), nutrition, fill=(255, 0, 0))
|
| 163 |
+
|
| 164 |
+
# return img
|
| 165 |
+
|
| 166 |
+
# # Gradio app
|
| 167 |
+
# demo = gr.Interface(
|
| 168 |
+
# fn=detect,
|
| 169 |
+
# inputs=gr.Image(type="pil"),
|
| 170 |
+
# outputs=gr.Image(type="pil"),
|
| 171 |
+
# title="YOLOv8 Food Detector + Nutrition Info",
|
| 172 |
+
# description="Upload an image of food and see calories and nutrients!"
|
| 173 |
+
# )
|
| 174 |
+
|
| 175 |
+
# demo.launch()
|
| 176 |
+
|