Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
qa_pipeline = pipeline("question-answering", model=model_name)
|
| 7 |
|
| 8 |
def answer_question(context, question):
|
| 9 |
-
"""
|
| 10 |
-
Function to run the QA pipeline and get the answer.
|
| 11 |
-
|
| 12 |
-
:param context: The context in which the question is asked.
|
| 13 |
-
:param question: The question that needs to be answered.
|
| 14 |
-
:return: Answer from the QA model.
|
| 15 |
-
"""
|
| 16 |
result = qa_pipeline({'context': context, 'question': question})
|
| 17 |
return result['answer']
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
interface = gr.Interface(
|
| 21 |
-
fn=answer_question,
|
| 22 |
-
inputs=[
|
| 23 |
-
gr.Textbox(label="Context", placeholder="Enter context here...", lines=4), # Left-side input
|
| 24 |
-
gr.Textbox(label="Question", placeholder="Ask a question here...", lines=1) # Right-side input
|
| 25 |
-
],
|
| 26 |
-
outputs="text", # Output as text
|
| 27 |
-
live=True, # Optional: Display results as the user types
|
| 28 |
-
layout="horizontal" # Align inputs side by side
|
| 29 |
-
)
|
| 30 |
|
| 31 |
# Launch the interface
|
| 32 |
-
|
| 33 |
-
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Initialize the custom pipeline
|
| 5 |
+
qa_pipeline = pipeline("question-answering")
|
|
|
|
| 6 |
|
| 7 |
def answer_question(context, question):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
result = qa_pipeline({'context': context, 'question': question})
|
| 9 |
return result['answer']
|
| 10 |
|
| 11 |
+
# Define the Gradio interface
|
| 12 |
+
interface = gr.Interface(fn=answer_question, inputs=["text", "text"], outputs="text")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# Launch the interface
|
| 15 |
+
interface.launch()
|
|
|