Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -84,11 +84,11 @@ def analyze_nutrition(image):
|
|
84 |
recommendations_text = "\n".join(recommendations) if recommendations else "• Continue mantendo uma alimentação equilibrada!"
|
85 |
|
86 |
return (
|
87 |
-
identified_foods,
|
88 |
table_data,
|
89 |
plot_data,
|
90 |
-
analysis_text,
|
91 |
-
recommendations_text,
|
92 |
"success" # Status para UI
|
93 |
)
|
94 |
|
@@ -99,12 +99,32 @@ def analyze_nutrition(image):
|
|
99 |
"error" # Status para UI
|
100 |
)
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
# Interface Gradio
|
103 |
-
with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
104 |
# Cabeçalho
|
105 |
-
with gr.Row(
|
106 |
gr.Markdown("""
|
107 |
# 🍽️ Análise Nutricional com IA
|
|
|
108 |
""")
|
109 |
|
110 |
# Container Principal
|
@@ -121,8 +141,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
121 |
with gr.Row():
|
122 |
analyze_btn = gr.Button("🔍 Analisar Prato", variant="primary", size="lg")
|
123 |
clear_btn = gr.Button("🔄 Limpar", size="lg")
|
124 |
-
|
125 |
-
with gr.Accordion("📝 Dicas
|
126 |
gr.Markdown("""
|
127 |
- Use fotos bem iluminadas
|
128 |
- Fotografe de cima para baixo
|
@@ -137,23 +157,19 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
137 |
|
138 |
with gr.Tabs():
|
139 |
# Tab de Identificação
|
140 |
-
with gr.Tab("🔍
|
141 |
-
|
142 |
-
|
143 |
-
value="Faça o upload de uma imagem e clique em Analisar"
|
144 |
-
)
|
145 |
|
146 |
# Tab de Nutrientes
|
147 |
-
with gr.Tab("📊
|
148 |
-
with gr.
|
149 |
nutri_table = gr.Dataframe(
|
150 |
headers=["Nutriente", "Quantidade"],
|
151 |
-
label="",
|
152 |
wrap=True
|
153 |
)
|
154 |
-
with gr.Row():
|
155 |
macro_plot = gr.BarPlot(
|
156 |
-
label="",
|
157 |
title="Distribuição de Macronutrientes (g)",
|
158 |
x="Nutriente",
|
159 |
y="Quantidade",
|
@@ -162,19 +178,16 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
162 |
)
|
163 |
|
164 |
# Tab de Análise
|
165 |
-
with gr.Tab("💡 Análise
|
166 |
-
with gr.
|
167 |
-
gr.Markdown("#### 📋 Análise")
|
168 |
analysis_output = gr.Markdown()
|
169 |
-
|
170 |
-
with gr.Box():
|
171 |
-
gr.Markdown("#### ✨ Recomendações")
|
172 |
recommendations_output = gr.Markdown()
|
173 |
|
174 |
# Event handlers
|
175 |
def clear_outputs():
|
176 |
return {
|
177 |
-
foods_detected:
|
178 |
nutri_table: None,
|
179 |
macro_plot: None,
|
180 |
analysis_output: None,
|
|
|
84 |
recommendations_text = "\n".join(recommendations) if recommendations else "• Continue mantendo uma alimentação equilibrada!"
|
85 |
|
86 |
return (
|
87 |
+
f"### Alimentos Identificados\n{identified_foods}",
|
88 |
table_data,
|
89 |
plot_data,
|
90 |
+
f"### Análise\n{analysis_text}",
|
91 |
+
f"### Recomendações\n{recommendations_text}",
|
92 |
"success" # Status para UI
|
93 |
)
|
94 |
|
|
|
99 |
"error" # Status para UI
|
100 |
)
|
101 |
|
102 |
+
css = """
|
103 |
+
.container {
|
104 |
+
max-width: 1200px;
|
105 |
+
margin: auto;
|
106 |
+
padding: 20px;
|
107 |
+
}
|
108 |
+
.header {
|
109 |
+
text-align: center;
|
110 |
+
margin-bottom: 30px;
|
111 |
+
}
|
112 |
+
.result-box {
|
113 |
+
border: 1px solid #ddd;
|
114 |
+
border-radius: 8px;
|
115 |
+
padding: 15px;
|
116 |
+
margin: 10px 0;
|
117 |
+
background-color: #fff;
|
118 |
+
}
|
119 |
+
"""
|
120 |
+
|
121 |
# Interface Gradio
|
122 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=css) as iface:
|
123 |
# Cabeçalho
|
124 |
+
with gr.Row(elem_classes="header"):
|
125 |
gr.Markdown("""
|
126 |
# 🍽️ Análise Nutricional com IA
|
127 |
+
Faça upload da foto do seu prato para análise nutricional detalhada
|
128 |
""")
|
129 |
|
130 |
# Container Principal
|
|
|
141 |
with gr.Row():
|
142 |
analyze_btn = gr.Button("🔍 Analisar Prato", variant="primary", size="lg")
|
143 |
clear_btn = gr.Button("🔄 Limpar", size="lg")
|
144 |
+
|
145 |
+
with gr.Accordion("📝 Dicas", open=False):
|
146 |
gr.Markdown("""
|
147 |
- Use fotos bem iluminadas
|
148 |
- Fotografe de cima para baixo
|
|
|
157 |
|
158 |
with gr.Tabs():
|
159 |
# Tab de Identificação
|
160 |
+
with gr.Tab("🔍 Identificação"):
|
161 |
+
with gr.Group(elem_classes="result-box"):
|
162 |
+
foods_detected = gr.Markdown()
|
|
|
|
|
163 |
|
164 |
# Tab de Nutrientes
|
165 |
+
with gr.Tab("📊 Nutrição"):
|
166 |
+
with gr.Group(elem_classes="result-box"):
|
167 |
nutri_table = gr.Dataframe(
|
168 |
headers=["Nutriente", "Quantidade"],
|
169 |
+
label="Informação Nutricional",
|
170 |
wrap=True
|
171 |
)
|
|
|
172 |
macro_plot = gr.BarPlot(
|
|
|
173 |
title="Distribuição de Macronutrientes (g)",
|
174 |
x="Nutriente",
|
175 |
y="Quantidade",
|
|
|
178 |
)
|
179 |
|
180 |
# Tab de Análise
|
181 |
+
with gr.Tab("💡 Análise"):
|
182 |
+
with gr.Group(elem_classes="result-box"):
|
|
|
183 |
analysis_output = gr.Markdown()
|
184 |
+
gr.Markdown("---")
|
|
|
|
|
185 |
recommendations_output = gr.Markdown()
|
186 |
|
187 |
# Event handlers
|
188 |
def clear_outputs():
|
189 |
return {
|
190 |
+
foods_detected: None,
|
191 |
nutri_table: None,
|
192 |
macro_plot: None,
|
193 |
analysis_output: None,
|