Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,64 +1,3 @@
|
|
| 1 |
-
# import torch
|
| 2 |
-
# import requests
|
| 3 |
-
# import os
|
| 4 |
-
# import pandas as pd
|
| 5 |
-
# from PIL import Image, ImageDraw, ImageFont
|
| 6 |
-
# import gradio as gr
|
| 7 |
-
|
| 8 |
-
# # روابط وتحميل الموديل
|
| 9 |
-
# model_path = "best.pt"
|
| 10 |
-
# model_url = "https://huggingface.co/AlaaElsayed/yolospace/resolve/main/best.pt"
|
| 11 |
-
# if not os.path.exists(model_path):
|
| 12 |
-
# r = requests.get(model_url)
|
| 13 |
-
# with open(model_path, "wb") as f:
|
| 14 |
-
# f.write(r.content)
|
| 15 |
-
|
| 16 |
-
# # تحميل الموديل
|
| 17 |
-
# model = torch.hub.load('ultralytics/yolov5', 'custom', path=model_path, source='local')
|
| 18 |
-
|
| 19 |
-
# # تحميل معلومات الطعام
|
| 20 |
-
# food_info = pd.read_csv("food_cleaned.csv")
|
| 21 |
-
|
| 22 |
-
# # دالة لإحضار البيانات الغذائية
|
| 23 |
-
# def get_nutrition(label):
|
| 24 |
-
# row = food_info[food_info["Food_Name"].str.lower() == label.lower()]
|
| 25 |
-
# if row.empty:
|
| 26 |
-
# return "No info", "?", "?", "?"
|
| 27 |
-
# cals = row["Calories_per_100g"].values[0]
|
| 28 |
-
# fat = row["Fat_g"].values[0]
|
| 29 |
-
# protein = row["Protein_g"].values[0]
|
| 30 |
-
# carbs = row["Carbs_g"].values[0]
|
| 31 |
-
# return f"{cals} kcal", f"{fat}g fat", f"{protein}g protein", f"{carbs}g carbs"
|
| 32 |
-
|
| 33 |
-
# # دالة الكشف
|
| 34 |
-
# def detect(image):
|
| 35 |
-
# results = model(image)
|
| 36 |
-
# labels = results.names
|
| 37 |
-
# df = results.pandas().xyxy[0]
|
| 38 |
-
|
| 39 |
-
# img = Image.fromarray(results.render()[0])
|
| 40 |
-
# draw = ImageDraw.Draw(img)
|
| 41 |
-
|
| 42 |
-
# for _, row in df.iterrows():
|
| 43 |
-
# label = row["name"]
|
| 44 |
-
# cal, fat, pro, carb = get_nutrition(label)
|
| 45 |
-
# text = f"{label}: {cal}, {fat}, {pro}, {carb}"
|
| 46 |
-
# draw.text((row["xmin"], row["ymin"] - 10), text, fill=(255, 0, 0))
|
| 47 |
-
|
| 48 |
-
# return img
|
| 49 |
-
|
| 50 |
-
# # Gradio app
|
| 51 |
-
# demo = gr.Interface(
|
| 52 |
-
# fn=detect,
|
| 53 |
-
# inputs=gr.Image(type="pil"),
|
| 54 |
-
# outputs=gr.Image(type="pil"),
|
| 55 |
-
# title="YOLOv5 Food Detector + Nutrition Info",
|
| 56 |
-
# description="Upload an image of food and see calories and nutrients!"
|
| 57 |
-
# )
|
| 58 |
-
|
| 59 |
-
# demo.launch()
|
| 60 |
-
|
| 61 |
-
|
| 62 |
from ultralytics import YOLO
|
| 63 |
import pandas as pd
|
| 64 |
from PIL import Image, ImageDraw
|
|
@@ -111,66 +50,3 @@ demo = gr.Interface(
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from ultralytics import YOLO
|
| 2 |
import pandas as pd
|
| 3 |
from PIL import Image, ImageDraw
|
|
|
|
| 50 |
|
| 51 |
demo.launch()
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|