Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- app.py +46 -0
- best (1).pt +3 -0
- cleaned_nutrition_values.csv +92 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import pandas as pd
|
3 |
+
import gradio as gr
|
4 |
+
from PIL import Image
|
5 |
+
from ultralytics import YOLO
|
6 |
+
|
7 |
+
# Load YOLOv8 model
|
8 |
+
model = YOLO("best (1).pt") # Ensure "best.pt" is in the same directory
|
9 |
+
|
10 |
+
# Load nutrition data CSV
|
11 |
+
nutrition_df = pd.read_csv("cleaned_nutrition_values.csv")
|
12 |
+
|
13 |
+
# Function to get nutrition info
|
14 |
+
def get_nutrition_info(food):
|
15 |
+
food_lower = food.lower()
|
16 |
+
nutrition_info = nutrition_df[nutrition_df["Food Item"].str.lower() == food_lower]
|
17 |
+
|
18 |
+
if not nutrition_info.empty:
|
19 |
+
return nutrition_info.to_dict(orient="records")[0]
|
20 |
+
else:
|
21 |
+
return "No nutrition data available."
|
22 |
+
|
23 |
+
# Function to process image and return food detection + nutrition
|
24 |
+
def detect_food(image):
|
25 |
+
results = model(image) # Run YOLO model on the image
|
26 |
+
detected_foods = [model.names[int(box.cls)] for r in results for box in r.boxes]
|
27 |
+
|
28 |
+
output = []
|
29 |
+
for food in detected_foods:
|
30 |
+
nutrition_info = get_nutrition_info(food)
|
31 |
+
output.append({"food": food, "nutrition": nutrition_info})
|
32 |
+
|
33 |
+
return output
|
34 |
+
|
35 |
+
# Gradio UI
|
36 |
+
iface = gr.Interface(
|
37 |
+
fn=detect_food,
|
38 |
+
inputs=gr.Image(type="pil"),
|
39 |
+
outputs="json",
|
40 |
+
title="🍕 Food Detection & Nutrition Lookup",
|
41 |
+
description="Upload an image of food, and this app will detect the food item and provide its nutrition details.",
|
42 |
+
)
|
43 |
+
|
44 |
+
# Run Gradio App
|
45 |
+
if __name__ == "__main__":
|
46 |
+
iface.launch()
|
best (1).pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:00b6cf93829db8099c7ddfc4e0edb7c0ef2ecf9f961b572acc257cbe73b6d8b8
|
3 |
+
size 52167755
|
cleaned_nutrition_values.csv
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Food Item,Calories (kcal),Protein (g),Carbohydrates (g),Fat (g),Sugar (g),Cholesterol (mg)
|
2 |
+
Chicken,239,27.0,0.0,14.0,0.0,88
|
3 |
+
Curd,98,11.0,4.0,5.0,4.0,17
|
4 |
+
Gulab Jamun,432,5.0,60.0,20.0,35.0,10
|
5 |
+
Kadai Paneer,270,14.0,10.0,20.0,4.0,40
|
6 |
+
Kadhi Pakoda,130,5.0,15.0,6.0,3.0,15
|
7 |
+
Kalakand,347,8.0,45.0,15.0,30.0,25
|
8 |
+
Naan,275,9.0,50.0,5.0,3.0,2
|
9 |
+
Palak Paneer,180,10.0,8.0,12.0,3.0,30
|
10 |
+
Paneer Butter Masala,320,12.0,15.0,25.0,6.0,45
|
11 |
+
Soan Papdi,540,5.0,60.0,30.0,40.0,0
|
12 |
+
Banana,89,1.1,23.0,0.3,12.0,0
|
13 |
+
Basundi,200,6.0,20.0,10.0,18.0,30
|
14 |
+
Beans,35,2.0,7.0,0.2,1.0,0
|
15 |
+
Bindi (Okra),33,2.0,7.0,0.1,1.0,0
|
16 |
+
Biryani,290,12.0,40.0,10.0,2.0,40
|
17 |
+
Black Beans,132,9.0,24.0,0.5,1.0,0
|
18 |
+
Brinjal Gravy,150,3.0,10.0,12.0,2.0,10
|
19 |
+
Buttermilk,40,3.0,5.0,1.0,4.0,5
|
20 |
+
Cabbage,25,1.3,6.0,0.1,3.0,0
|
21 |
+
Cauliflower,25,2.0,5.0,0.3,2.0,0
|
22 |
+
Channa Masala,180,8.0,20.0,6.0,3.0,10
|
23 |
+
Chapati,200,6.0,40.0,4.0,2.0,0
|
24 |
+
Chicken Tikka Masala,150,12.0,5.0,10.0,3.0,50
|
25 |
+
Curd Rice,120,5.0,20.0,4.0,3.0,15
|
26 |
+
Dal Tadka,126,6.0,15.0,4.0,2.0,10
|
27 |
+
Dosa,168,4.0,30.0,4.0,2.0,0
|
28 |
+
Egg,155,13.0,1.0,11.0,1.0,373
|
29 |
+
Egg Gravy,180,10.0,8.0,12.0,2.0,220
|
30 |
+
Fish Curry,120,15.0,5.0,6.0,2.0,50
|
31 |
+
Fish Fry,220,20.0,10.0,12.0,1.0,65
|
32 |
+
Idli,140,3.0,28.0,1.0,1.0,0
|
33 |
+
Jalebi,300,2.0,60.0,10.0,50.0,5
|
34 |
+
Kachori,290,7.0,35.0,15.0,5.0,10
|
35 |
+
Lemon Rice,210,4.0,35.0,8.0,2.0,5
|
36 |
+
Momos,200,8.0,30.0,6.0,1.0,10
|
37 |
+
Omelette,160,12.0,2.0,12.0,1.0,260
|
38 |
+
Paneer,265,18.0,2.0,21.0,1.0,50
|
39 |
+
Papad,371,22.0,55.0,2.0,1.0,0
|
40 |
+
Parotta,270,6.0,45.0,10.0,3.0,5
|
41 |
+
Pickle,60,2.0,10.0,2.0,4.0,0
|
42 |
+
Pizza,280,12.0,35.0,10.0,3.0,25
|
43 |
+
Poha,212,4.0,35.0,7.0,2.0,5
|
44 |
+
Pongal,210,5.0,35.0,7.0,3.0,10
|
45 |
+
Poori,260,6.0,40.0,12.0,3.0,5
|
46 |
+
Prawn,99,20.0,1.0,1.0,0.0,195
|
47 |
+
Pulav,250,5.0,40.0,8.0,2.0,15
|
48 |
+
Rabri,250,6.0,30.0,10.0,25.0,30
|
49 |
+
Raita,80,3.0,8.0,3.0,4.0,10
|
50 |
+
Rasam,40,2.0,6.0,1.0,2.0,0
|
51 |
+
Rasgulla,186,4.0,35.0,5.0,30.0,10
|
52 |
+
Rice,130,2.7,28.0,0.3,0.1,0
|
53 |
+
Roti,200,6.0,40.0,4.0,2.0,0
|
54 |
+
Sambar,120,6.0,15.0,4.0,2.0,5
|
55 |
+
Sheera,250,4.0,35.0,10.0,25.0,5
|
56 |
+
Soft Drink,40,0.0,10.0,0.0,10.0,0
|
57 |
+
Spaghetti,160,6.0,31.0,1.0,2.0,0
|
58 |
+
Sweet,400,5.0,60.0,15.0,40.0,10
|
59 |
+
Tandoori Chicken,220,25.0,5.0,10.0,2.0,65
|
60 |
+
Vada,290,8.0,35.0,15.0,3.0,5
|
61 |
+
Vegetables,50,2.0,10.0,0.5,3.0,0
|
62 |
+
White Rice,130,2.7,28.0,0.3,0.1,0
|
63 |
+
Apple,52,0.3,14.0,0.2,10.0,0
|
64 |
+
Banana,89,1.1,23.0,0.3,12.0,0
|
65 |
+
Carrot,41,0.9,10.0,0.2,4.7,0
|
66 |
+
Tomato,18,0.9,3.9,0.2,2.6,0
|
67 |
+
Potato,77,2.0,17.0,0.1,0.8,0
|
68 |
+
Spinach,23,2.9,3.6,0.4,0.4,0
|
69 |
+
Milk,42,3.4,5.0,1.0,5.0,5
|
70 |
+
Egg,155,13.0,1.1,11.0,1.1,373
|
71 |
+
Almonds,579,21.0,22.0,50.0,4.4,0
|
72 |
+
Rice (Cooked),130,2.7,28.0,0.3,0.1,0
|
73 |
+
Wheat Flour,340,13.2,72.0,2.5,0.4,0
|
74 |
+
Orange,47,0.9,12.0,0.1,9.0,0
|
75 |
+
Mango,60,0.8,15.0,0.4,14.0,0
|
76 |
+
Pineapple,50,0.5,13.0,0.1,10.0,0
|
77 |
+
Strawberry,32,0.7,7.7,0.3,4.9,0
|
78 |
+
Cabbage,25,1.3,6.0,0.1,3.2,0
|
79 |
+
Broccoli,34,2.8,7.0,0.4,1.7,0
|
80 |
+
Peanuts,567,25.8,16.0,49.0,4.7,0
|
81 |
+
Lentils,116,9.0,20.0,0.4,1.8,0
|
82 |
+
Chickpeas,164,8.9,27.4,2.6,4.8,0
|
83 |
+
Grapes,69,0.7,18.0,0.2,15.0,0
|
84 |
+
Papaya,43,0.5,11.0,0.3,8.0,0
|
85 |
+
Guava,68,2.6,14.0,0.9,9.0,0
|
86 |
+
Pomegranate,83,1.7,19.0,1.2,14.0,0
|
87 |
+
Watermelon,30,0.6,8.0,0.2,6.0,0
|
88 |
+
Avocado,160,2.0,9.0,15.0,0.7,0
|
89 |
+
Kiwi,61,1.1,15.0,0.5,9.0,0
|
90 |
+
Chia Seeds,486,16.0,42.0,31.0,0.0,0
|
91 |
+
Sunflower Seeds,584,21.0,20.0,51.0,2.6,0
|
92 |
+
Sesame Seeds,573,18.0,23.0,50.0,0.3,0
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
ultralytics
|
2 |
+
torch
|
3 |
+
torchvision
|
4 |
+
gradio
|
5 |
+
huggingface_hub
|