File size: 789 Bytes
80a9adc 2a9c43f 19bcb2f 2a9c43f 617f7ab 19bcb2f 2a9c43f 19bcb2f 2a9c43f 80a9adc 2a9c43f 80a9adc 2a9c43f 80a9adc 93d7a55 2a9c43f 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 25 26 27 28 |
import gradio as gr
from transformers import pipeline
def get_answer(question):
# Reload the pipeline every time a query is made (fixes single-response issue)
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
# Define a general knowledge context
context = """
Washington, D.C. is the capital of the United States of America.
New Delhi is the capital of India.
London is the capital of the United Kingdom.
"""
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()
|