Cristobal299 commited on
Commit
4f4f869
·
verified ·
1 Parent(s): 6ba37ce

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -26
app.py CHANGED
@@ -96,6 +96,7 @@ def traducir_capitulo_con_groq(pares):
96
  req = urllib.request.Request(GROQ_URL, data=data, method="POST")
97
  req.add_header("Content-Type", "application/json")
98
  req.add_header("Authorization", f"Bearer {GROQ_KEY}")
 
99
  with urllib.request.urlopen(req, timeout=120) as r:
100
  d = json.load(r)
101
  salida = (d["choices"][0]["message"]["content"] or "").strip()
@@ -464,6 +465,7 @@ def estudiar(mensaje, historial, contexto):
464
  req = urllib.request.Request(GROQ_URL, data=data, method="POST")
465
  req.add_header("Content-Type", "application/json")
466
  req.add_header("Authorization", f"Bearer {GROQ_KEY}")
 
467
  with urllib.request.urlopen(req, timeout=90) as r:
468
  d = json.load(r)
469
  return (d["choices"][0]["message"]["content"] or "").strip()
@@ -525,31 +527,6 @@ with gr.Blocks(theme=fenix_theme(), css=FENIX_CSS, title="Centralita Torá") as
525
 
526
  q_btn.click(buscar, q, q_out)
527
 
528
- with gr.Tab("Buscar"):
529
- q = gr.Textbox(label="Palabra o frase (hebreo o español)", placeholder="ej. luz / אור")
530
- q_btn = gr.Button("Buscar", variant="primary")
531
- q_out = gr.HTML()
532
-
533
- def buscar(texto):
534
- t = (texto or "").strip().lower()
535
- if not t:
536
- return "<p>Escribe algo para buscar.</p>"
537
- filas = []
538
- for lid in IDS:
539
- d = LIBROS[lid]
540
- for c, vs in d.get("capitulos", {}).items():
541
- for v in vs:
542
- campos = " ".join(filter(None, [v.get("es"), v.get("he")])).lower()
543
- if t in campos:
544
- ref = f"{d.get('es', lid)} {c}:{v.get('n')}"
545
- txt = html.escape(_limpiar_entidades(v.get("es") or v.get("he") or ""))
546
- filas.append(f"<div class='resultado'><span class='ref'>{ref}</span> — {txt}</div>")
547
- if len(filas) >= 120:
548
- return "".join(filas)
549
- return "".join(filas) if filas else "<p>Sin resultados en los libros cargados.</p>"
550
-
551
- q_btn.click(buscar, q, q_out)
552
-
553
  with gr.Tab("Estudiar"):
554
  gr.Markdown("La IA usa el capítulo abierto en **Leer** como contexto.")
555
  chat = gr.Chatbot(type="messages", height=360)
@@ -582,4 +559,4 @@ with gr.Blocks(theme=fenix_theme(), css=FENIX_CSS, title="Centralita Torá") as
582
  )
583
 
584
  if __name__ == "__main__":
585
- demo.launch(ssr_mode=False)
 
96
  req = urllib.request.Request(GROQ_URL, data=data, method="POST")
97
  req.add_header("Content-Type", "application/json")
98
  req.add_header("Authorization", f"Bearer {GROQ_KEY}")
99
+ req.add_header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0 Safari/537.36")
100
  with urllib.request.urlopen(req, timeout=120) as r:
101
  d = json.load(r)
102
  salida = (d["choices"][0]["message"]["content"] or "").strip()
 
465
  req = urllib.request.Request(GROQ_URL, data=data, method="POST")
466
  req.add_header("Content-Type", "application/json")
467
  req.add_header("Authorization", f"Bearer {GROQ_KEY}")
468
+ req.add_header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0 Safari/537.36")
469
  with urllib.request.urlopen(req, timeout=90) as r:
470
  d = json.load(r)
471
  return (d["choices"][0]["message"]["content"] or "").strip()
 
527
 
528
  q_btn.click(buscar, q, q_out)
529
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
530
  with gr.Tab("Estudiar"):
531
  gr.Markdown("La IA usa el capítulo abierto en **Leer** como contexto.")
532
  chat = gr.Chatbot(type="messages", height=360)
 
559
  )
560
 
561
  if __name__ == "__main__":
562
+ demo.launch(ssr_mode=False)