Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
|
7 |
-
def
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
)
|
15 |
-
return generated[0]['generated_text']
|
16 |
|
17 |
-
# Create
|
18 |
iface = gr.Interface(
|
19 |
-
fn=
|
20 |
inputs="text",
|
21 |
outputs="text",
|
22 |
title="Ask Any Question",
|
23 |
-
description="Ask
|
24 |
)
|
25 |
|
26 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load a Question Answering model
|
5 |
+
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
6 |
|
7 |
+
def get_answer(question):
|
8 |
+
# Define a context for factual answers
|
9 |
+
context = """
|
10 |
+
New Delhi is the capital of India. India is a country in South Asia and is the seventh-largest country by land area.
|
11 |
+
"""
|
12 |
+
answer = qa_pipeline(question=question, context=context)
|
13 |
+
return answer["answer"]
|
|
|
|
|
14 |
|
15 |
+
# Create Gradio Interface
|
16 |
iface = gr.Interface(
|
17 |
+
fn=get_answer,
|
18 |
inputs="text",
|
19 |
outputs="text",
|
20 |
title="Ask Any Question",
|
21 |
+
description="Ask factual questions and get precise answers."
|
22 |
)
|
23 |
|
24 |
iface.launch()
|