JairoCesar commited on
Commit
d8d54a1
verified
1 Parent(s): cb37c3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -32
app.py CHANGED
@@ -1,5 +1,5 @@
1
- # ==================== El Detective de Alimentos (Versi贸n 10.0 - Producci贸n) =====================================
2
- # Mejoras: Generador de informes, sugerencias de consulta y refinamientos finales de UI.
3
 
4
  import streamlit as st
5
  import google.generativeai as genai
@@ -218,10 +218,8 @@ def create_relevance_chart(results):
218
  tooltip=[alt.Tooltip('Condici贸n:N', title='Condici贸n'), alt.Tooltip('Relevancia:Q', title='Puntuaci贸n')]
219
  ).properties(title='Principales Coincidencias seg煤n tu Caso').configure_axis(labelFontSize=12, titleFontSize=14).configure_title(fontSize=16, anchor='start')
220
  return chart
221
-
222
-
223
- # --- NUEVA FUNCI脫N PARA GENERAR EL INFORME ---
224
  def generate_report_text(query, results):
 
225
  report_lines = []
226
  report_lines.append("="*50)
227
  report_lines.append("INFORME DEL DETECTIVE DE ALIMENTOS")
@@ -229,36 +227,34 @@ def generate_report_text(query, results):
229
  report_lines.append(f"Fecha: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
230
  report_lines.append(f"CONSULTA ORIGINAL DEL USUARIO:\n'{query}'\n")
231
  report_lines.append("-"*50)
232
-
233
- # An谩lisis del resultado principal
234
  if results:
235
  best_match = results[0]['entry']
236
  report_lines.append("PRINCIPAL COINCIDENCIA ENCONTRADA:\n")
237
  report_lines.append(f"Condici贸n: {best_match.get('condicion_asociada', 'N/A')}")
238
  report_lines.append(f"Mecanismo Posible: {best_match.get('mecanismo_fisiologico', 'N/A')}")
239
  report_lines.append(f"Recomendaciones Generales: {best_match.get('recomendaciones_examenes', 'N/A')}\n")
240
-
241
- # Diagn贸stico diferencial
242
  if len(results) > 1:
243
  report_lines.append("-"*50)
244
  report_lines.append("OTRAS POSIBILIDADES CONSIDERADAS (DIAGN脫STICO DIFERENCIAL):\n")
245
  for i, res in enumerate(results[1:4]):
246
  entry = res['entry']
247
  report_lines.append(f"{i+2}. {entry.get('condicion_asociada', 'N/A')} (Puntuaci贸n: {res['score']['total']})")
248
-
249
  report_lines.append("\n" + "="*50)
250
- report_lines.append("IMPORTANTE: Este informe es generado por una herramienta de IA y no constituye un diagn贸stico m茅dico. Su prop贸sito es facilitar la conversaci贸n con un profesional de la salud cualificado.")
251
-
252
  return "\n".join(report_lines)
253
 
254
  # --- INTERFAZ DE USUARIO Y L脫GICA PRINCIPAL ---
255
- col_img, col_text = st.columns([1, 4], gap="medium")
256
- with col_img:
 
257
  if os.path.exists("imagen.png"):
258
  st.image("imagen.png", width=150)
259
  with col_text:
260
  st.title("El Detective de Alimentos")
261
  st.markdown("##### Describe lo que sientes y lo que comiste para descubrir posibles intolerancias.")
 
 
 
262
  st.markdown("---")
263
 
264
  # MANEJO DE ESTADO
@@ -277,7 +273,7 @@ def clear_search_state():
277
  def set_query_from_example(example_text):
278
  st.session_state.query = example_text
279
 
280
- # NUEVA SECCI脫N: EJEMPLOS DE CONSULTA
281
  st.write("**驴No sabes por d贸nde empezar? Prueba con un ejemplo:**")
282
  example_cols = st.columns(3)
283
  example_queries = [
@@ -324,7 +320,6 @@ if st.session_state.search_results is not None:
324
  if not results:
325
  st.warning(f"No se encontraron coincidencias claras para tu caso: '{st.session_state.user_query}'.")
326
  else:
327
- # --- NUEVO BOT脫N DE DESCARGA ---
328
  col1, col2 = st.columns([3,1])
329
  with col1:
330
  st.success(f"Hemos encontrado {len(results)} posible(s) causa(s) relacionada(s) con tu caso.")
@@ -386,22 +381,8 @@ if st.session_state.search_results is not None:
386
  if 'best_match_analysis' not in st.session_state.analysis_cache:
387
  st.session_state.analysis_cache['best_match_analysis'] = generate_detailed_analysis(st.session_state.user_query, best_match)
388
  st.markdown(st.session_state.analysis_cache['best_match_analysis'])
389
- st.markdown("---")
390
- feedback_placeholder = st.empty()
391
- with feedback_placeholder.container():
392
- st.write("**驴Te fue 煤til este an谩lisis?**")
393
- feedback_cols = st.columns(8)
394
- if feedback_cols[0].button("馃憤 脷til", key=f"util_{best_match['condicion_asociada']}"):
395
- log_feedback(st.session_state.user_query, best_match_data, "util")
396
- feedback_placeholder.success("隆Gracias por tu feedback!")
397
- time.sleep(2)
398
- feedback_placeholder.empty()
399
- if feedback_cols[1].button("馃憥 No 煤til", key=f"no_util_{best_match['condicion_asociada']}"):
400
- log_feedback(st.session_state.user_query, best_match_data, "no_util")
401
- feedback_placeholder.warning("Gracias. Usaremos tu feedback para mejorar.")
402
- time.sleep(2)
403
- feedback_placeholder.empty()
404
-
405
  if len(results) > 1:
406
  with st.expander("**Otras Posibilidades Relevantes (Diagn贸stico Diferencial)**"):
407
  for i, result in enumerate(results[1:4]):
 
1
+ # ==================== El Detective de Alimentos (Versi贸n 10.1 - UI Personalizada) =====================================
2
+ # Mejoras: Cabecera con dos im谩genes y eliminaci贸n de la funcionalidad de feedback.
3
 
4
  import streamlit as st
5
  import google.generativeai as genai
 
218
  tooltip=[alt.Tooltip('Condici贸n:N', title='Condici贸n'), alt.Tooltip('Relevancia:Q', title='Puntuaci贸n')]
219
  ).properties(title='Principales Coincidencias seg煤n tu Caso').configure_axis(labelFontSize=12, titleFontSize=14).configure_title(fontSize=16, anchor='start')
220
  return chart
 
 
 
221
  def generate_report_text(query, results):
222
+ # ... (Sin cambios)
223
  report_lines = []
224
  report_lines.append("="*50)
225
  report_lines.append("INFORME DEL DETECTIVE DE ALIMENTOS")
 
227
  report_lines.append(f"Fecha: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
228
  report_lines.append(f"CONSULTA ORIGINAL DEL USUARIO:\n'{query}'\n")
229
  report_lines.append("-"*50)
 
 
230
  if results:
231
  best_match = results[0]['entry']
232
  report_lines.append("PRINCIPAL COINCIDENCIA ENCONTRADA:\n")
233
  report_lines.append(f"Condici贸n: {best_match.get('condicion_asociada', 'N/A')}")
234
  report_lines.append(f"Mecanismo Posible: {best_match.get('mecanismo_fisiologico', 'N/A')}")
235
  report_lines.append(f"Recomendaciones Generales: {best_match.get('recomendaciones_examenes', 'N/A')}\n")
 
 
236
  if len(results) > 1:
237
  report_lines.append("-"*50)
238
  report_lines.append("OTRAS POSIBILIDADES CONSIDERADAS (DIAGN脫STICO DIFERENCIAL):\n")
239
  for i, res in enumerate(results[1:4]):
240
  entry = res['entry']
241
  report_lines.append(f"{i+2}. {entry.get('condicion_asociada', 'N/A')} (Puntuaci贸n: {res['score']['total']})")
 
242
  report_lines.append("\n" + "="*50)
243
+ report_lines.append("IMPORTANTE: Este informe es generado por una herramienta de IA y no constituye un diagn贸stico m茅dico...")
 
244
  return "\n".join(report_lines)
245
 
246
  # --- INTERFAZ DE USUARIO Y L脫GICA PRINCIPAL ---
247
+ # --- BLOQUE DE ENCABEZADO MODIFICADO ---
248
+ col_img1, col_text, col_img2 = st.columns([1, 4, 1], gap="medium")
249
+ with col_img1:
250
  if os.path.exists("imagen.png"):
251
  st.image("imagen.png", width=150)
252
  with col_text:
253
  st.title("El Detective de Alimentos")
254
  st.markdown("##### Describe lo que sientes y lo que comiste para descubrir posibles intolerancias.")
255
+ with col_img2:
256
+ if os.path.exists("buho.png"):
257
+ st.image("buho.png", width=120)
258
  st.markdown("---")
259
 
260
  # MANEJO DE ESTADO
 
273
  def set_query_from_example(example_text):
274
  st.session_state.query = example_text
275
 
276
+ # SECCI脫N: EJEMPLOS DE CONSULTA
277
  st.write("**驴No sabes por d贸nde empezar? Prueba con un ejemplo:**")
278
  example_cols = st.columns(3)
279
  example_queries = [
 
320
  if not results:
321
  st.warning(f"No se encontraron coincidencias claras para tu caso: '{st.session_state.user_query}'.")
322
  else:
 
323
  col1, col2 = st.columns([3,1])
324
  with col1:
325
  st.success(f"Hemos encontrado {len(results)} posible(s) causa(s) relacionada(s) con tu caso.")
 
381
  if 'best_match_analysis' not in st.session_state.analysis_cache:
382
  st.session_state.analysis_cache['best_match_analysis'] = generate_detailed_analysis(st.session_state.user_query, best_match)
383
  st.markdown(st.session_state.analysis_cache['best_match_analysis'])
384
+
385
+ # --- SECCI脫N DE DIAGN脫STICO DIFERENCIAL (SIN FEEDBACK) ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
  if len(results) > 1:
387
  with st.expander("**Otras Posibilidades Relevantes (Diagn贸stico Diferencial)**"):
388
  for i, result in enumerate(results[1:4]):