| import gradio as gr |
| from transformers import pipeline, AutoTokenizer, AutoModelForQuestionAnswering |
|
|
| |
| model_name = "distilbert-base-cased-distilled-squad" |
| tokenizer = AutoTokenizer.from_pretrained(model_name) |
| model = AutoModelForQuestionAnswering.from_pretrained(model_name) |
| qa_pipeline = pipeline("question-answering", model=model, tokenizer=tokenizer) |
|
|
| |
| iface = gr.Interface( |
| fn=lambda question: qa_pipeline(question=question, context=context)["answer"], |
| inputs=gr.Textbox(label="Enter a question"), |
| outputs="text", |
| live=True, |
| ) |
|
|
| |
| iface.launch() |
|
|