Neha555Altaf commited on
Commit
7ba3eff
·
verified ·
1 Parent(s): d66c9bc

Update App.py

Browse files
Files changed (1) hide show
  1. App.py +33 -32
App.py CHANGED
@@ -1,41 +1,42 @@
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()
 
 
1
  import pandas as pd
2
+ import gradio as gr
3
 
4
+ # Load the extended food data
5
  df = pd.read_csv("food_data_extended.csv")
6
 
7
+ # Convert food names to lowercase for matching
8
  df["food"] = df["food"].str.lower()
9
 
10
+ # Nutrient search function
11
+ def analyze_foods(food_query):
12
+ food_query = food_query.lower()
13
+ items = [item.strip() for item in food_query.split(",")]
14
+
15
+ results = []
16
+
17
+ for item in items:
18
+ match = df[df["food"].str.contains(item)]
19
+ if not match.empty:
20
+ results.append(match)
21
+ else:
22
+ results.append(pd.DataFrame([{
23
+ "food": item,
24
+ "calories": "Not found",
25
+ "protein": "Not found",
26
+ "carbs": "Not found",
27
+ "fat": "Not found"
28
+ }]))
29
+
30
+ final = pd.concat(results)
31
+ return final.reset_index(drop=True)
32
+
33
+ # Gradio UI
34
+ app = gr.Interface(
35
  fn=analyze_foods,
36
+ inputs=gr.Textbox(label="Enter food items (comma-separated)", placeholder="e.g. apple, rice, chicken biryani"),
37
+ outputs=gr.Dataframe(label="Nutritional Information"),
38
+ title="🍎 NutriTrack AI - Food Nutrient Analyzer",
39
+ description="Type any food(s) to get calories, protein, carbs & fat. Supports 200+ food items. Try: banana, pizza, milk, apple"
 
40
  )
41
 
42
+ app.launch()