Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,17 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load a question-answering model instead of a text generator
|
| 5 |
-
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
| 6 |
-
|
| 7 |
def get_answer(question):
|
| 8 |
-
#
|
|
|
|
|
|
|
|
|
|
| 9 |
context = """
|
| 10 |
Washington, D.C. is the capital of the United States of America.
|
|
|
|
|
|
|
| 11 |
"""
|
|
|
|
| 12 |
answer = qa_pipeline(question=question, context=context)
|
| 13 |
return answer["answer"]
|
| 14 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
def get_answer(question):
|
| 5 |
+
# Reload the pipeline every time a query is made (fixes single-response issue)
|
| 6 |
+
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
| 7 |
+
|
| 8 |
+
# Define a general knowledge context
|
| 9 |
context = """
|
| 10 |
Washington, D.C. is the capital of the United States of America.
|
| 11 |
+
New Delhi is the capital of India.
|
| 12 |
+
London is the capital of the United Kingdom.
|
| 13 |
"""
|
| 14 |
+
|
| 15 |
answer = qa_pipeline(question=question, context=context)
|
| 16 |
return answer["answer"]
|
| 17 |
|