File size: 677 Bytes
80a9adc 93d7a55 80a9adc 93d7a55 80a9adc 93d7a55 80a9adc 93d7a55 80a9adc 93d7a55 80a9adc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import gradio as gr
from transformers import pipeline
# Load a question-answering model instead of a text generator
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
def get_answer(question):
context = """
London is the capital of the United Kingdom. The UK consists of England, Scotland, Wales, and Northern Ireland.
"""
answer = qa_pipeline(question=question, context=context)
return answer["answer"]
# Create Gradio Interface
iface = gr.Interface(
fn=get_answer,
inputs="text",
outputs="text",
title="Ask Any Question",
description="Ask factual questions and get precise answers."
)
iface.launch()
|