belalmunsh commited on
Commit
e29378a
1 Parent(s): 3f4a0bf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import pdf2image
4
+ import pytesseract
5
+
6
+ # Initialize model
7
+ qa_model = pipeline("question-answering")
8
+
9
+ def process_pdf(pdf_file):
10
+ # Convert PDF to text
11
+ text = extract_text_from_pdf(pdf_file)
12
+ return text
13
+
14
+ def answer_question(question, context):
15
+ # Get answer from model
16
+ answer = qa_model(question=question, context=context)
17
+ return answer['answer']
18
+
19
+ # Create interface
20
+ with gr.Blocks() as demo:
21
+ gr.Markdown("# My Study Assistant")
22
+
23
+ # File upload
24
+ file_input = gr.File(label="Upload PDF")
25
+
26
+ # Text display
27
+ text_output = gr.Textbox(label="Extracted Text")
28
+
29
+ # Chat interface
30
+ question = gr.Textbox(label="Ask a question")
31
+ answer = gr.Textbox(label="Answer")
32
+
33
+ # Buttons
34
+ upload_btn = gr.Button("Process PDF")
35
+ ask_btn = gr.Button("Ask")
36
+
37
+ # Set up actions
38
+ upload_btn.click(process_pdf, inputs=file_input, outputs=text_output)
39
+ ask_btn.click(answer_question, inputs=[question, text_output], outputs=answer)
40
+
41
+ demo.launch()