Create App.py
Browse files
App.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
# Load food data CSV
|
| 5 |
+
df = pd.read_csv("food_data_extended.csv")
|
| 6 |
+
|
| 7 |
+
# Lowercase for consistent matching
|
| 8 |
+
df["food"] = df["food"].str.lower()
|
| 9 |
+
|
| 10 |
+
def analyze_foods(input_text):
|
| 11 |
+
input_items = [item.strip().lower() for item in input_text.split(",")]
|
| 12 |
+
|
| 13 |
+
matched = df[df["food"].isin(input_items)]
|
| 14 |
+
|
| 15 |
+
if matched.empty:
|
| 16 |
+
return "❌ Koi bhi food item match nahi hua. Dobara try karein."
|
| 17 |
+
|
| 18 |
+
result = ""
|
| 19 |
+
for _, row in matched.iterrows():
|
| 20 |
+
result += (
|
| 21 |
+
f"🍽️ **{row['food'].title()}**\n"
|
| 22 |
+
f" 🔹 Calories: {row['calories']} kcal\n"
|
| 23 |
+
f" 🔹 Protein: {row['protein']} g\n"
|
| 24 |
+
f" 🔹 Carbs: {row['carbs']} g\n"
|
| 25 |
+
f" 🔹 Fat: {row['fat']} g\n\n"
|
| 26 |
+
)
|
| 27 |
+
return result
|
| 28 |
+
|
| 29 |
+
title = "🥗 NutriTrack AI - Food Nutrient Analyzer"
|
| 30 |
+
description = "Kisi bhi food item ka naam likhein (1 ya zyada, comma se alag karein) aur iske calories, protein, carbs aur fat ka accurate data paayein. Example: `egg, milk, rice`"
|
| 31 |
+
|
| 32 |
+
iface = gr.Interface(
|
| 33 |
+
fn=analyze_foods,
|
| 34 |
+
inputs=gr.Textbox(lines=2, placeholder="e.g. egg, chicken, rice"),
|
| 35 |
+
outputs=gr.Markdown(),
|
| 36 |
+
title=title,
|
| 37 |
+
description=description,
|
| 38 |
+
allow_flagging="never"
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
iface.launch()
|