Add application file
Browse files
app2.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Cargar el pipeline de preguntas y respuestas
|
5 |
+
qa_pipeline = pipeline(
|
6 |
+
"question-answering",
|
7 |
+
model="mrm8488/bert-base-spanish-wwm-cased-finetuned-spa-squad2-es",
|
8 |
+
tokenizer="mrm8488/bert-base-spanish-wwm-cased-finetuned-spa-squad2-es"
|
9 |
+
)
|
10 |
+
|
11 |
+
# Función para obtener la respuesta
|
12 |
+
def responder(pregunta, contexto):
|
13 |
+
resultado = qa_pipeline(question=pregunta, context=contexto)
|
14 |
+
return resultado['answer']
|
15 |
+
|
16 |
+
# Interfaz de Gradio
|
17 |
+
interface = gr.Interface(
|
18 |
+
fn=responder,
|
19 |
+
inputs=[
|
20 |
+
gr.Textbox(lines=2, label="Pregunta"),
|
21 |
+
gr.Textbox(lines=10, label="Contexto")
|
22 |
+
],
|
23 |
+
outputs="text",
|
24 |
+
title="Preguntas y Respuestas en Español",
|
25 |
+
description="Modelo BETO afinado con SQuAD2.0 en español"
|
26 |
+
)
|
27 |
+
|
28 |
+
interface.launch()
|