JairoCesar commited on
Commit
35002d9
·
verified ·
1 Parent(s): 609d9d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -24
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 ROBUSTA DE LA CLAVE API PARA HUGGING FACE ---
41
  def get_gemini_client():
42
- possible_keys = [
43
- "APIkeydetective", "APIKEYDETECTIVE", "ApiKeyDetective",
44
- "GEMINI_API_KEY", "GEMINI_KEY", "API_KEY"
45
- ]
46
- api_key = None
47
-
48
- # 1. Buscar en st.secrets de Streamlit
49
- try:
50
- for k in possible_keys:
51
- if k in st.secrets and st.secrets[k]:
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
- for k in possible_keys:
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("❌ No se encontró ninguna clave API válida para Gemini en secretos ni en variables de entorno.")
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
- # CORRECCIÓN DE PARÁMETROS: 8 PARÁMETROS PARA COINCIDIR CON LA LLAMADA DE TAB_MOL
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)