prat1003 commited on
Commit
cf33e18
·
verified ·
1 Parent(s): 97cf84f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pdfplumber
3
+
4
+ def read_pdf(file, format_type):
5
+ if file is None:
6
+ return "Please upload a PDF file."
7
+ text = ""
8
+ with pdfplumber.open(file.name) as pdf:
9
+ for page in pdf.pages:
10
+ text += page.extract_text() or ""
11
+ if format_type == "HTML":
12
+ return f"<html><body><p>{text}</p></body></html>"
13
+ else:
14
+ return f"<xml><content>{text}</content></xml>"
15
+
16
+ app = gr.Interface(
17
+ fn=read_pdf,
18
+ inputs=[gr.File(label="Upload PDF"), gr.Radio(["HTML", "XML"], label="Output Format")],
19
+ outputs="text",
20
+ title="PDF to HTML/XML Converter"
21
+ )
22
+
23
+ app.launch()