Amamrnaf commited on
Commit
bd3440d
·
1 Parent(s): f1cd6fb

added stuff

Browse files
Files changed (1) hide show
  1. app.py +34 -3
app.py CHANGED
@@ -1,7 +1,38 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
  demo.launch()
 
1
  import gradio as gr
2
+ import fitz # PyMuPDF for handling PDF files
3
 
4
+ def process_pdf(file, option):
5
+ if file is None:
6
+ return "Please upload a PDF file."
7
+
8
+ try:
9
+ # Open the PDF file
10
+ doc = fitz.open(file.name)
11
+ text = ""
12
+ for page in doc:
13
+ text += page.get_text()
14
+ doc.close()
15
+
16
+ # Process based on the selected option
17
+ if option == "Option 1":
18
+ return f"Option 1 selected. Extracted text:\n{text[:500]}..." # Truncated for brevity
19
+ elif option == "Option 2":
20
+ return f"Option 2 selected. Extracted text:\n{text[:500]}..." # Truncated for brevity
21
+ else:
22
+ return "Invalid option selected."
23
+ except Exception as e:
24
+ return f"An error occurred: {e}"
25
+
26
+ # Define the Gradio interface
27
+ demo = gr.Interface(
28
+ fn=process_pdf,
29
+ inputs=[
30
+ gr.File(label="Upload PDF"), # File upload input
31
+ gr.Radio(["Option 1", "Option 2"], label="Choose an option") # Radio buttons for options
32
+ ],
33
+ outputs="text", # Text output
34
+ title="PDF Processor",
35
+ description="Upload a PDF and choose an option to process the text."
36
+ )
37
 
 
38
  demo.launch()