Spaces:
Build error
Build error
Richard Hsu
commited on
Commit
·
f59bbd9
1
Parent(s):
01f0fe3
push
Browse files
app.py
CHANGED
@@ -1,16 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
|
4 |
-
def
|
5 |
-
|
6 |
-
|
7 |
-
text = "
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
9 |
return text
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
import fitz # PyMuPDF
|
3 |
|
4 |
+
def extract_text_from_pdf(pdf_file):
|
5 |
+
# Open the PDF file
|
6 |
+
pdf_document = fitz.open(pdf_file.name)
|
7 |
+
text = ""
|
8 |
+
|
9 |
+
# Extract text from each page
|
10 |
+
for page_num in range(len(pdf_document)):
|
11 |
+
page = pdf_document.load_page(page_num)
|
12 |
+
text += page.get_text()
|
13 |
+
|
14 |
return text
|
15 |
|
16 |
+
# Create a Gradio interface
|
17 |
+
interface = gr.Interface(
|
18 |
+
fn=extract_text_from_pdf,
|
19 |
+
inputs=gr.inputs.File(label="Upload PDF"),
|
20 |
+
outputs=gr.outputs.Textbox(label="Extracted Text"),
|
21 |
+
title="PDF Text Extractor",
|
22 |
+
description="Upload a PDF file to extract and display its text content."
|
23 |
+
)
|
24 |
|
25 |
+
# Launch the interface
|
26 |
+
interface.launch(share=True)
|