Question Answering
Adapters
English
File size: 1,272 Bytes
3930735
7ba3eff
3930735
7ba3eff
3930735
 
7ba3eff
3930735
 
7ba3eff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3930735
7ba3eff
 
 
 
3930735
 
7ba3eff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pandas as pd
import gradio as gr

# Load the extended food data
df = pd.read_csv("food_data_extended.csv")

# Convert food names to lowercase for matching
df["food"] = df["food"].str.lower()

# Nutrient search function
def analyze_foods(food_query):
    food_query = food_query.lower()
    items = [item.strip() for item in food_query.split(",")]

    results = []

    for item in items:
        match = df[df["food"].str.contains(item)]
        if not match.empty:
            results.append(match)
        else:
            results.append(pd.DataFrame([{
                "food": item,
                "calories": "Not found",
                "protein": "Not found",
                "carbs": "Not found",
                "fat": "Not found"
            }]))

    final = pd.concat(results)
    return final.reset_index(drop=True)

# Gradio UI
app = gr.Interface(
    fn=analyze_foods,
    inputs=gr.Textbox(label="Enter food items (comma-separated)", placeholder="e.g. apple, rice, chicken biryani"),
    outputs=gr.Dataframe(label="Nutritional Information"),
    title="馃崕 NutriTrack AI - Food Nutrient Analyzer",
    description="Type any food(s) to get calories, protein, carbs & fat. Supports 200+ food items. Try: banana, pizza, milk, apple"
)

app.launch()