File size: 904 Bytes
48a1259
 
4163cb4
023d531
 
ba09ced
48a1259
 
 
4163cb4
 
 
48a1259
 
 
 
 
023d531
 
48a1259
023d531
48a1259
 
 
 
 
adef1a2
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
import gradio as gr

# Load model from training checkpoint
from simpletransformers.question_answering import QuestionAnsweringModel, QuestionAnsweringArgs

model = QuestionAnsweringModel("bert", "./bert_outputs/bert/best_model", use_cuda=False)

# Função para realizar predições
def perform_prediction(context, question):
    to_predict = [{"context": context, "qas": [{"question": question, "id": "0"}]}]
    answers, probabilities = model.predict(to_predict, n_best_size=2)
    return answers[0]["answer"]

# Criando a interface do Gradio
iface = gr.Interface(
    fn=perform_prediction,
    inputs=[
        gr.Textbox(placeholder="Insira o contexto aqui...", label="Contexto"),
        gr.Textbox(placeholder="Faça uma pergunta sobre o contexto...", label="Pergunta")
    ],
    outputs=gr.Textbox(label="Resposta"),
    live=True,
    theme="compact",
)

# Iniciando a interface
iface.launch()