File size: 1,435 Bytes
e581cb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gradio as gr
import rag_engine

def ask(pregunta, num_docs, similitud):
    """ Esta funci贸n conecta la web con nuestro motor RAG """
    
    respuesta, docs = rag_engine.preguntar(pregunta, top_k=int(num_docs), umbral=float(similitud))
    
    
    if not docs:
        contexto_visible = "No se encontr贸 informaci贸n relevante."
    else:
        
        contexto_visible = "\n\n---\n\n".join(docs)
    
    return respuesta, contexto_visible


with gr.Blocks() as interfaz:
    gr.Markdown("# Asistente del Hospital")
    gr.Markdown("Escribe tu pregunta para buscar en los documentos del hospital.")

    with gr.Row():
        
        with gr.Column():
            entrada_texto = gr.Textbox(label="Tu pregunta:", placeholder="Ej: Where is the hospital?")
            slider_k = gr.Slider(1, 5, value=2, step=1, label="Cuantos documentos buscar")
            slider_u = gr.Slider(0.0, 1.0, value=0.4, step=0.1, label="Nivel de parecido (minimo)")
            boton = gr.Button("Preguntar", variant="primary")

        
        with gr.Column():
            salida_ia = gr.Textbox(label="Respuesta:", lines=4)
            salida_docs = gr.Textbox(label="Informacion utilizada:", lines=8)


    boton.click(
        fn=ask,
        inputs=[entrada_texto, slider_k, slider_u],
        outputs=[salida_ia, salida_docs]
    )


if __name__ == "__main__":
    interfaz.launch()