tosin2013 commited on
Commit
9a7ccba
·
verified ·
1 Parent(s): e3572df

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the Question Answering pipeline
5
+ qa_model = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")
6
+
7
+ def answer_question(context, question):
8
+ result = qa_model(question=question, context=context)
9
+ answer = result['answer']
10
+ score = result['score']
11
+ return answer, f"{score:.2f}"
12
+
13
+ # Define the Gradio interface
14
+ with gr.Interface(
15
+ fn=answer_question,
16
+ inputs=[gr.inputs.Textbox(lines=10, placeholder="Enter the context here..."), gr.inputs.Textbox(lines=2, placeholder="Enter your question here...")],
17
+ outputs=[gr.outputs.Textbox(label="Answer"), gr.outputs.Textbox(label="Confidence Score")],
18
+ title="Question Answering System",
19
+ description="Upload a document and ask questions to get answers based on the context."
20
+ ) as qa_app:
21
+ qa_app.launch()