carlosDev1995 commited on
Commit
48a1259
·
verified ·
1 Parent(s): 208eb72

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +27 -0
  2. requeriments.txt +4 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # Load model from training checkpoint
4
+ from simpletransformers.question_answering import QuestionAnsweringModel
5
+
6
+ model = QuestionAnsweringModel("bert", "outputs/bert/best_model", use_cuda=False)
7
+
8
+ # Função para realizar predições
9
+ def perform_prediction(context, question):
10
+ to_predict = [{"context": context, "qas": [{"question": question, "id": "0"}]}]
11
+ answers, probabilities = model.predict(to_predict, n_best_size=2)
12
+ return answers[0]["answer"]
13
+
14
+ # Criando a interface do Gradio
15
+ iface = gr.Interface(
16
+ fn=perform_prediction,
17
+ inputs=[
18
+ gr.Textbox(placeholder="Insert context here...", label="Contexto"),
19
+ gr.Textbox(placeholder="Ask a question about the context...", label="Pergunta")
20
+ ],
21
+ outputs=gr.Textbox(label="Response"),
22
+ live=True,
23
+ theme="compact",
24
+ )
25
+
26
+ # Iniciando a interface
27
+ iface.launch()
requeriments.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ gradio_client
3
+ torch
4
+ simpletransformers