Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -79,7 +79,7 @@ def identify_foods(description):
|
|
79 |
cooking_methods = ["cozido", "assado", "grelhado", "frito", "cru"]
|
80 |
for food in found_foods:
|
81 |
for method in cooking_methods:
|
82 |
-
if method in description
|
83 |
found_foods[food]["preparo"] = method
|
84 |
|
85 |
return found_foods
|
@@ -110,6 +110,7 @@ def analyze_foods(description):
|
|
110 |
foods_detail.append(f" - Variação encontrada: {info['variacao']}")
|
111 |
if 'preparo' in info:
|
112 |
foods_detail.append(f" - Método de preparo: {info['preparo']}")
|
|
|
113 |
|
114 |
# Soma nutrientes
|
115 |
for nutrient, value in NUTRITION_DB[food].items():
|
@@ -170,9 +171,59 @@ def analyze_image(image):
|
|
170 |
except Exception as e:
|
171 |
return str(e), None, None
|
172 |
|
173 |
-
# Interface Gradio
|
174 |
with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
|
177 |
if __name__ == "__main__":
|
178 |
print(f"Usando dispositivo: {'CUDA' if torch.cuda.is_available() else 'CPU'}")
|
|
|
79 |
cooking_methods = ["cozido", "assado", "grelhado", "frito", "cru"]
|
80 |
for food in found_foods:
|
81 |
for method in cooking_methods:
|
82 |
+
if method in description:
|
83 |
found_foods[food]["preparo"] = method
|
84 |
|
85 |
return found_foods
|
|
|
110 |
foods_detail.append(f" - Variação encontrada: {info['variacao']}")
|
111 |
if 'preparo' in info:
|
112 |
foods_detail.append(f" - Método de preparo: {info['preparo']}")
|
113 |
+
foods_detail.append("") # Linha em branco para separar
|
114 |
|
115 |
# Soma nutrientes
|
116 |
for nutrient, value in NUTRITION_DB[food].items():
|
|
|
171 |
except Exception as e:
|
172 |
return str(e), None, None
|
173 |
|
174 |
+
# Interface Gradio
|
175 |
with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
176 |
+
gr.Markdown("""
|
177 |
+
# 🍽️ Análise Nutricional com IA
|
178 |
+
Faça upload de uma foto do seu prato para análise nutricional detalhada.
|
179 |
+
""")
|
180 |
+
|
181 |
+
with gr.Row():
|
182 |
+
# Coluna de Input
|
183 |
+
with gr.Column():
|
184 |
+
image_input = gr.Image(
|
185 |
+
type="pil",
|
186 |
+
label="Foto do Prato",
|
187 |
+
sources=["upload", "webcam"]
|
188 |
+
)
|
189 |
+
analyze_btn = gr.Button("📊 Analisar", variant="primary", size="lg")
|
190 |
+
|
191 |
+
with gr.Accordion("📝 Dicas", open=False):
|
192 |
+
gr.Markdown("""
|
193 |
+
- Use fotos bem iluminadas
|
194 |
+
- Fotografe de cima para baixo
|
195 |
+
- Certifique-se que todos os alimentos estão visíveis
|
196 |
+
- Evite sombras ou reflexos fortes
|
197 |
+
""")
|
198 |
+
|
199 |
+
# Coluna de Output
|
200 |
+
with gr.Column():
|
201 |
+
# Análise textual
|
202 |
+
output_text = gr.Markdown()
|
203 |
+
|
204 |
+
with gr.Row():
|
205 |
+
# Tabela nutricional
|
206 |
+
output_table = gr.Dataframe(
|
207 |
+
headers=["Nutriente", "Quantidade"],
|
208 |
+
label="Informação Nutricional",
|
209 |
+
wrap=True
|
210 |
+
)
|
211 |
+
|
212 |
+
# Gráfico
|
213 |
+
output_plot = gr.BarPlot(
|
214 |
+
x="Nutriente",
|
215 |
+
y="Quantidade",
|
216 |
+
title="Macronutrientes (g)",
|
217 |
+
height=300,
|
218 |
+
tooltip=["Nutriente", "Quantidade"]
|
219 |
+
)
|
220 |
+
|
221 |
+
# Eventos
|
222 |
+
analyze_btn.click(
|
223 |
+
fn=analyze_image,
|
224 |
+
inputs=[image_input],
|
225 |
+
outputs=[output_text, output_table, output_plot]
|
226 |
+
)
|
227 |
|
228 |
if __name__ == "__main__":
|
229 |
print(f"Usando dispositivo: {'CUDA' if torch.cuda.is_available() else 'CPU'}")
|