Walid-Ahmed commited on
Commit
adf29ba
·
verified ·
1 Parent(s): 5f075ed

Upload 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
+
8
+ def answer_question(context, question):
9
+ result = qa_pipeline(question=question, context=context)
10
+ return result['answer']
11
+
12
+
13
+ def process(context_file, question):
14
+ # Read the context from the uploaded file
15
+ with open(context_file.name, 'r') as file:
16
+ context = file.read()
17
+
18
+ answer = answer_question(context, question)
19
+ return answer
20
+
21
+
22
+ # Gradio interface
23
+ demo = gr.Interface(
24
+ fn=process,
25
+ inputs=[gr.File(label="Upload Context File"), gr.Textbox(label="Question")],
26
+ outputs=[gr.Textbox(label="Answer")],
27
+ title="Question Answering",
28
+ description="Upload a file with context and ask a question. The answer will be displayed."
29
+ )
30
+
31
+ if __name__ == "__main__":
32
+ demo.launch()