Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the trained model
|
| 5 |
+
model_path = "bart_QA"
|
| 6 |
+
qa_pipeline = pipeline("question-answering", model=model_path, tokenizer=model_path)
|
| 7 |
+
|
| 8 |
+
def answer_question(question, context):
|
| 9 |
+
if question.strip() == "" or context.strip() == "":
|
| 10 |
+
return "Please provide both a question and context."
|
| 11 |
+
|
| 12 |
+
result = qa_pipeline(question=question, context=context)
|
| 13 |
+
return result['answer']
|
| 14 |
+
|
| 15 |
+
# Define the Gradio interface
|
| 16 |
+
input_question = gr.inputs.Textbox(label="Question", placeholder="Enter your question here")
|
| 17 |
+
input_context = gr.inputs.Textbox(label="Context", placeholder="Enter the context here", lines=5)
|
| 18 |
+
output_answer = gr.outputs.Textbox(label="Answer")
|
| 19 |
+
|
| 20 |
+
interface = gr.Interface(
|
| 21 |
+
fn=answer_question,
|
| 22 |
+
inputs=[input_question, input_context],
|
| 23 |
+
outputs=output_answer,
|
| 24 |
+
title="BART QA System",
|
| 25 |
+
description="Provide a question and context, and get an answer based on the context."
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
interface.launch()
|