Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import gradio as gr
|
3 |
+
from datasets import load_dataset
|
4 |
+
|
5 |
+
# Cargar el dataset desde Hugging Face
|
6 |
+
dataset = load_dataset("Biophin/datospreguntas")
|
7 |
+
|
8 |
+
# Funci贸n para responder preguntas
|
9 |
+
def answer_question(question):
|
10 |
+
question = question.lower()
|
11 |
+
for item in dataset["train"]: # Recorre los datos del dataset
|
12 |
+
if question in item["question"].lower(): # Usar 'question' en lugar de 'pregunta'
|
13 |
+
return item["answer"] # Devuelve 'answer'
|
14 |
+
return "Lo siento, no tengo una respuesta para esa pregunta."
|
15 |
+
|
16 |
+
# Crear la interfaz de Gradio
|
17 |
+
interface = gr.Interface(
|
18 |
+
fn=answer_question,
|
19 |
+
inputs="text",
|
20 |
+
outputs="text",
|
21 |
+
title="Chatbot de Preguntas y Respuestas Mejorado",
|
22 |
+
description="Escribe una pregunta relacionada con el contenido del archivo JSON. El bot buscar谩 la respuesta m谩s relevante.",
|
23 |
+
)
|
24 |
+
|
25 |
+
# Lanzar la aplicaci贸n
|
26 |
+
interface.launch(share=True)
|
27 |
+
|
28 |
+
|
29 |
+
|