Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -907,8 +907,7 @@ if st.session_state.search_results is not None:
|
|
| 907 |
score_col2.metric("Puntos por Síntomas", f"{best_match_data['score']['symptoms']}")
|
| 908 |
score_col3.metric("PUNTUACIÓN TOTAL", f"{best_match_data['score']['total']}", delta="Máxima coincidencia")
|
| 909 |
|
| 910 |
-
|
| 911 |
-
|
| 912 |
st.write("")
|
| 913 |
if foodb_index:
|
| 914 |
with st.popover("🔬 Componentes Moleculares del Diagnóstico"):
|
|
@@ -920,40 +919,47 @@ if st.session_state.search_results is not None:
|
|
| 920 |
if not user_foods_mentioned:
|
| 921 |
st.warning("No se identificó un alimento específico para buscar.")
|
| 922 |
else:
|
| 923 |
-
#
|
| 924 |
-
|
| 925 |
-
|
| 926 |
-
target_keywords = set(re.findall(r'\b\w+\b', re.sub(r'\(.*?\)', '', target_compounds_text)))
|
| 927 |
-
|
| 928 |
-
# 2. ENCONTRAR LOS ALIMENTOS MÁS RELEVANTES
|
| 929 |
-
best_food_matches = find_best_foodb_matches(user_foods_mentioned, foodb_index.keys(), FOOD_NAME_TO_FOODB_KEY)
|
| 930 |
|
| 931 |
-
|
| 932 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 933 |
else:
|
| 934 |
-
|
| 935 |
-
|
| 936 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 937 |
|
| 938 |
-
|
| 939 |
-
|
| 940 |
-
for item in compounds_data:
|
| 941 |
-
compound_name_lower = item['compound'].lower()
|
| 942 |
-
# Comprobar si el nombre del compuesto está relacionado con los objetivos
|
| 943 |
-
if any(keyword in compound_name_lower for keyword in target_keywords):
|
| 944 |
-
relevant_compounds.append(item)
|
| 945 |
-
|
| 946 |
-
if relevant_compounds:
|
| 947 |
-
found_any_data = True
|
| 948 |
-
with st.container(border=True):
|
| 949 |
-
st.subheader(f"Análisis de: {food_key.capitalize()}")
|
| 950 |
-
st.markdown("###### 🔬 Compuestos Relevantes para el Diagnóstico:")
|
| 951 |
-
for item in relevant_compounds[:5]:
|
| 952 |
-
st.write(f"**Compuesto:** {item['compound']}")
|
| 953 |
-
st.caption(f"Este compuesto está directamente relacionado con '{best_match.get('condicion_asociada')}'.")
|
| 954 |
-
|
| 955 |
-
if not found_any_data:
|
| 956 |
-
st.warning(f"No se encontraron los compuestos específicos de '{best_match.get('condicion_asociada')}' en los alimentos analizados en la base de datos FoodB.")
|
| 957 |
|
| 958 |
st.markdown("---")
|
| 959 |
|
|
|
|
| 907 |
score_col2.metric("Puntos por Síntomas", f"{best_match_data['score']['symptoms']}")
|
| 908 |
score_col3.metric("PUNTUACIÓN TOTAL", f"{best_match_data['score']['total']}", delta="Máxima coincidencia")
|
| 909 |
|
| 910 |
+
with col2_expander:
|
|
|
|
| 911 |
st.write("")
|
| 912 |
if foodb_index:
|
| 913 |
with st.popover("🔬 Componentes Moleculares del Diagnóstico"):
|
|
|
|
| 919 |
if not user_foods_mentioned:
|
| 920 |
st.warning("No se identificó un alimento específico para buscar.")
|
| 921 |
else:
|
| 922 |
+
# --- NUEVA LÓGICA INTELIGENTE ---
|
| 923 |
+
# 1. IDENTIFICAR LOS SÍNTOMAS CLAVE DEL DIAGNÓSTICO PRINCIPAL
|
| 924 |
+
main_diagnosis_symptoms = set(s.lower() for s in best_match.get("sintomas_clave", []))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 925 |
|
| 926 |
+
# 2. ENCONTRAR LOS COMPUESTOS DESENCADENANTES PARA ESOS SÍNTOMAS USANDO NUESTRO CONOCIMIENTO EXPERTO
|
| 927 |
+
target_compounds = set()
|
| 928 |
+
for compound, triggered_symptoms in KNOWN_TRIGGERS_MAP.items():
|
| 929 |
+
if any(symptom in main_diagnosis_symptoms for symptom in triggered_symptoms):
|
| 930 |
+
target_compounds.add(compound.lower())
|
| 931 |
+
|
| 932 |
+
if not target_compounds:
|
| 933 |
+
st.warning(f"No se pudieron determinar los compuestos moleculares clave para '{best_match.get('condicion_asociada')}'.")
|
| 934 |
else:
|
| 935 |
+
# 3. ENCONTRAR LOS ALIMENTOS MÁS RELEVANTES MENCIONADOS POR EL USUARIO
|
| 936 |
+
best_food_matches = find_best_foodb_matches(user_foods_mentioned, foodb_index.keys(), FOOD_NAME_TO_FOODB_KEY)
|
| 937 |
+
|
| 938 |
+
if not best_food_matches:
|
| 939 |
+
st.warning("No se encontraron datos moleculares para los alimentos específicos mencionados.")
|
| 940 |
+
else:
|
| 941 |
+
found_any_data = False
|
| 942 |
+
for food_key in best_food_matches:
|
| 943 |
+
compounds_data = foodb_index.get(food_key, [])
|
| 944 |
+
|
| 945 |
+
# 4. BUSCAR LOS COMPUESTOS OBJETIVO EN CADA ALIMENTO
|
| 946 |
+
relevant_compounds = []
|
| 947 |
+
for item in compounds_data:
|
| 948 |
+
compound_name_lower = item['compound'].lower()
|
| 949 |
+
if any(target in compound_name_lower for target in target_compounds):
|
| 950 |
+
relevant_compounds.append(item)
|
| 951 |
+
|
| 952 |
+
if relevant_compounds:
|
| 953 |
+
found_any_data = True
|
| 954 |
+
with st.container(border=True):
|
| 955 |
+
st.subheader(f"Análisis de: {food_key.capitalize()}")
|
| 956 |
+
st.markdown("###### 🔬 Compuestos Relevantes para el Diagnóstico:")
|
| 957 |
+
for item in relevant_compounds[:5]:
|
| 958 |
+
st.write(f"**Compuesto:** {item['compound']}")
|
| 959 |
+
st.caption(f"Este compuesto está directamente relacionado con '{best_match.get('condicion_asociada')}'.")
|
| 960 |
|
| 961 |
+
if not found_any_data:
|
| 962 |
+
st.warning(f"No se encontraron los compuestos específicos de '{best_match.get('condicion_asociada')}' en los alimentos analizados en la base de datos FoodB.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 963 |
|
| 964 |
st.markdown("---")
|
| 965 |
|