Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Data: Nutritional Information for the healthiest dishes
|
| 6 |
+
nutritional_data = {
|
| 7 |
+
"Idli with Vegetable Sambar": {
|
| 8 |
+
"Energy (kcal)": 100, "Protein (g)": 5.5, "Fat (g)": 1.5, "Carbohydrate (g)": 17.0, "Fiber (g)": 3.0, "Calcium (mg)": 35, "Iron (mg)": 1.0, "Vitamin C (mg)": 8.0
|
| 9 |
+
},
|
| 10 |
+
"Khichdi": {
|
| 11 |
+
"Energy (kcal)": 120, "Protein (g)": 4.0, "Fat (g)": 2.5, "Carbohydrate (g)": 20.0, "Fiber (g)": 2.5, "Calcium (mg)": 40, "Iron (mg)": 1.0, "Vitamin C (mg)": 5.0
|
| 12 |
+
},
|
| 13 |
+
"Tandoori Chicken": {
|
| 14 |
+
"Energy (kcal)": 150, "Protein (g)": 18.0, "Fat (g)": 7.0, "Carbohydrate (g)": 3.0, "Fiber (g)": 0.5, "Calcium (mg)": 15, "Iron (mg)": 1.2, "Vitamin C (mg)": 1.5
|
| 15 |
+
},
|
| 16 |
+
"Palak Paneer": {
|
| 17 |
+
"Energy (kcal)": 140, "Protein (g)": 7.5, "Fat (g)": 10.0, "Carbohydrate (g)": 6.0, "Fiber (g)": 3.0, "Calcium (mg)": 200, "Iron (mg)": 3.0, "Vitamin C (mg)": 15.0
|
| 18 |
+
},
|
| 19 |
+
"Raita": {
|
| 20 |
+
"Energy (kcal)": 60, "Protein (g)": 3.5, "Fat (g)": 2.0, "Carbohydrate (g)": 6.5, "Fiber (g)": 0.5, "Calcium (mg)": 100, "Iron (mg)": 0.5, "Vitamin C (mg)": 2.0
|
| 21 |
+
},
|
| 22 |
+
"Rajma": {
|
| 23 |
+
"Energy (kcal)": 140, "Protein (g)": 7.5, "Fat (g)": 5.0, "Carbohydrate (g)": 20.0, "Fiber (g)": 6.0, "Calcium (mg)": 50, "Iron (mg)": 3.5, "Vitamin C (mg)": 4.0
|
| 24 |
+
},
|
| 25 |
+
"Baingan Bharta": {
|
| 26 |
+
"Energy (kcal)": 70, "Protein (g)": 2.5, "Fat (g)": 3.0, "Carbohydrate (g)": 10.0, "Fiber (g)": 4.0, "Calcium (mg)": 30, "Iron (mg)": 0.7, "Vitamin C (mg)": 6.0
|
| 27 |
+
},
|
| 28 |
+
"Besan Chilla": {
|
| 29 |
+
"Energy (kcal)": 180, "Protein (g)": 8.0, "Fat (g)": 7.0, "Carbohydrate (g)": 20.0, "Fiber (g)": 5.0, "Calcium (mg)": 30, "Iron (mg)": 2.5, "Vitamin C (mg)": 1.0
|
| 30 |
+
},
|
| 31 |
+
"Masoor Dal": {
|
| 32 |
+
"Energy (kcal)": 110, "Protein (g)": 7.5, "Fat (g)": 2.0, "Carbohydrate (g)": 16.0, "Fiber (g)": 5.5, "Calcium (mg)": 25, "Iron (mg)": 3.0, "Vitamin C (mg)": 4.0
|
| 33 |
+
},
|
| 34 |
+
"Upma": {
|
| 35 |
+
"Energy (kcal)": 150, "Protein (g)": 4.0, "Fat (g)": 6.0, "Carbohydrate (g)": 25.0, "Fiber (g)": 3.0, "Calcium (mg)": 30, "Iron (mg)": 1.0, "Vitamin C (mg)": 3.0
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
def plot_nutritional_comparison(dish):
|
| 40 |
+
"""Plots a radar chart comparing the nutritional values of the selected dish."""
|
| 41 |
+
labels = list(nutritional_data[dish].keys())
|
| 42 |
+
values = list(nutritional_data[dish].values())
|
| 43 |
+
|
| 44 |
+
# Normalize values for better comparison on the radar chart
|
| 45 |
+
max_values = [max(nutritional_data[d][label] for d in nutritional_data) for label in labels]
|
| 46 |
+
normalized_values = [value / max_val if max_val > 0 else 0 for value, max_val in zip(values, max_values)]
|
| 47 |
+
|
| 48 |
+
# Setup the radar chart
|
| 49 |
+
angles = np.linspace(0, 2 * np.pi, len(labels), endpoint=False).tolist()
|
| 50 |
+
values += values[:1] # repeat the first value to close the circle
|
| 51 |
+
normalized_values += normalized_values[:1]
|
| 52 |
+
angles += angles[:1]
|
| 53 |
+
|
| 54 |
+
fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(polar=True))
|
| 55 |
+
ax.fill(angles, normalized_values, color='blue', alpha=0.25)
|
| 56 |
+
ax.plot(angles, normalized_values, color='blue', linewidth=2)
|
| 57 |
+
ax.set_yticklabels([])
|
| 58 |
+
ax.set_xticks(angles[:-1])
|
| 59 |
+
ax.set_xticklabels(labels)
|
| 60 |
+
ax.set_title(f'Nutritional Profile for {dish}', size=15, color='blue', y=1.1)
|
| 61 |
+
|
| 62 |
+
return fig
|
| 63 |
+
|
| 64 |
+
# Gradio Interface
|
| 65 |
+
def create_interface():
|
| 66 |
+
dishes = list(nutritional_data.keys())
|
| 67 |
+
|
| 68 |
+
with gr.Blocks() as demo:
|
| 69 |
+
gr.Markdown("# Nutritional Comparison of Healthiest Dishes")
|
| 70 |
+
dish_selector = gr.Dropdown(choices=dishes, label="Select a Dish", value=dishes[0])
|
| 71 |
+
nutritional_comparison_output = gr.Plot(label="Nutritional Comparison")
|
| 72 |
+
|
| 73 |
+
# Update the plot based on the selected dish
|
| 74 |
+
def update_nutritional_comparison(dish):
|
| 75 |
+
return plot_nutritional_comparison(dish)
|
| 76 |
+
|
| 77 |
+
dish_selector.change(fn=update_nutritional_comparison, inputs=dish_selector, outputs=nutritional_comparison_output)
|
| 78 |
+
|
| 79 |
+
gr.Row(dish_selector, nutritional_comparison_output)
|
| 80 |
+
|
| 81 |
+
return demo
|
| 82 |
+
|
| 83 |
+
# Launch the interface
|
| 84 |
+
demo = create_interface()
|
| 85 |
+
demo.launch(share=True)
|