File size: 632 Bytes
e7ee46c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from transformers import pipeline

# Replace this with your own checkpoint
model_checkpoint = "huggingface-course/bert-finetuned-squad"
model = pipeline("question-answering", model=model_checkpoint)

def question_answer(context, question,model):
  to_predict = [
    {
        "context": context,
        "qas": [
            {
                "question": question,
                "id": "0",
            }
                ],
    }
    ]
  answers, probabilities = model.predict(to_predict)
  return answers[0]['answer'][0]

gr.Interface(fn=question_answer, inputs=["text", "text"], outputs=["textbox"]).launch()