rahul7star commited on
Commit
01eb127
·
verified ·
1 Parent(s): 4a2feb0

Create app.py

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