Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,33 +37,24 @@ Este análisis es una herramienta informativa de IA y **NO es un diagnóstico m
|
|
| 37 |
**Si tus síntomas son severos, busca ayuda médica urgente.**
|
| 38 |
"""
|
| 39 |
|
| 40 |
-
# --- CONFIGURACIÓN
|
| 41 |
def get_gemini_client():
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
api_key = str(st.secrets[k]).strip()
|
| 53 |
-
break
|
| 54 |
-
except Exception:
|
| 55 |
-
pass
|
| 56 |
|
| 57 |
-
# 2. Buscar en variables de entorno os.getenv de Hugging Face
|
| 58 |
if not api_key:
|
| 59 |
-
|
| 60 |
-
v = os.getenv(k)
|
| 61 |
-
if v and v.strip():
|
| 62 |
-
api_key = v.strip()
|
| 63 |
-
break
|
| 64 |
|
| 65 |
if not api_key:
|
| 66 |
-
logger.warning("❌
|
| 67 |
return None
|
| 68 |
|
| 69 |
try:
|
|
@@ -974,7 +965,7 @@ def generate_neuro_report_text(entities, food_map, neuro_map):
|
|
| 974 |
|
| 975 |
return "\n".join(report_lines)
|
| 976 |
|
| 977 |
-
#
|
| 978 |
def generate_molecular_report_text(best_match, entities, _foodb_index, _foodb_lower_map, food_name_map, synonym_map, food_compound_map, neuro_map):
|
| 979 |
report_lines = ["\n### 🔬 Análisis Molecular y Efectos Bioactivos"]
|
| 980 |
user_foods = entities.get("alimentos", [])
|
|
@@ -1101,7 +1092,7 @@ if submitted:
|
|
| 1101 |
st.session_state.search_results = None
|
| 1102 |
st.session_state.entities = None
|
| 1103 |
|
| 1104 |
-
with st.spinner("🔍 Analizando pistas..."):
|
| 1105 |
raw_entities = extract_entities_with_gemini(current_query)
|
| 1106 |
reinforced = reinforce_entities_with_keywords(raw_entities, current_query, FOOD_TO_COMPOUND_MAP, MASTER_SYMPTOM_MAP)
|
| 1107 |
final_symptoms = translate_symptoms_local(reinforced.get("sintomas", []), MASTER_SYMPTOM_MAP)
|
|
|
|
| 37 |
**Si tus síntomas son severos, busca ayuda médica urgente.**
|
| 38 |
"""
|
| 39 |
|
| 40 |
+
# --- CONFIGURACIÓN GEMINI CON LA VARIABLE GEMINI_API_KEY ---
|
| 41 |
def get_gemini_client():
|
| 42 |
+
api_key = os.getenv("GEMINI_API_KEY")
|
| 43 |
+
|
| 44 |
+
if not api_key:
|
| 45 |
+
try:
|
| 46 |
+
if "GEMINI_API_KEY" in st.secrets:
|
| 47 |
+
api_key = st.secrets["GEMINI_API_KEY"]
|
| 48 |
+
elif "APIkeydetective" in st.secrets:
|
| 49 |
+
api_key = st.secrets["APIkeydetective"]
|
| 50 |
+
except Exception:
|
| 51 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
|
|
|
| 53 |
if not api_key:
|
| 54 |
+
api_key = os.getenv("APIkeydetective")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
if not api_key:
|
| 57 |
+
logger.warning("❌ GEMINI_API_KEY no encontrada en variables de entorno ni en secretos.")
|
| 58 |
return None
|
| 59 |
|
| 60 |
try:
|
|
|
|
| 965 |
|
| 966 |
return "\n".join(report_lines)
|
| 967 |
|
| 968 |
+
# FIX PARÁMETROS DE REPORTE MOLECULAR (8 PARÁMETROS)
|
| 969 |
def generate_molecular_report_text(best_match, entities, _foodb_index, _foodb_lower_map, food_name_map, synonym_map, food_compound_map, neuro_map):
|
| 970 |
report_lines = ["\n### 🔬 Análisis Molecular y Efectos Bioactivos"]
|
| 971 |
user_foods = entities.get("alimentos", [])
|
|
|
|
| 1092 |
st.session_state.search_results = None
|
| 1093 |
st.session_state.entities = None
|
| 1094 |
|
| 1095 |
+
with st.spinner("🔍 Analizando pistas con Gemini..."):
|
| 1096 |
raw_entities = extract_entities_with_gemini(current_query)
|
| 1097 |
reinforced = reinforce_entities_with_keywords(raw_entities, current_query, FOOD_TO_COMPOUND_MAP, MASTER_SYMPTOM_MAP)
|
| 1098 |
final_symptoms = translate_symptoms_local(reinforced.get("sintomas", []), MASTER_SYMPTOM_MAP)
|