Download app.py from Dafne00/chatbot: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/Dafne00/chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/Dafne00/chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Dafne00/chatbot/resolve/main/app.py
1.17 kB
| import gradio as gr | |
| from rag_engine import recuperar_documentos, generar_respuesta | |
| def ask(query, top_k, umbral): | |
| docs = recuperar_documentos(query, int(top_k), float(umbral)) | |
| respuesta = generar_respuesta(query, docs) | |
| if docs: | |
| docs_formateados = "\n\n---\n\n".join(docs) | |
| else: | |
| docs_formateados = "No relevant documents found." | |
| return respuesta, docs_formateados | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# RAG Question Answering System") | |
| gr.Markdown("Ask a question based on the provided documents.") | |
| query = gr.Textbox( | |
| label="Your Question", | |
| placeholder="Type your question..." | |
| ) | |
| top_k = gr.Slider(1, 5, value=5, step=1, label="Top K Documents") | |
| umbral = gr.Slider(0.0, 1.0, value=0.55, step=0.05, label="Similarity Threshold") | |
| respuesta = gr.Textbox(label="Answer", lines=3) | |
| docs = gr.Textbox(label="Retrieved Documents", lines=6, max_lines=15) | |
| boton = gr.Button("Enviar") | |
| boton.click( | |
| fn=ask, | |
| inputs=[query, top_k, umbral], | |
| outputs=[respuesta, docs] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |