SathvikGanta
commited on
Commit
•
aea88e6
1
Parent(s):
d359b2e
Update app.py
Browse files
app.py
CHANGED
@@ -31,10 +31,14 @@ def log_conversion(status, input_pdf, output_svg, output_pdf, error_message=None
|
|
31 |
# Gradio interface function
|
32 |
def process_pdf(file, width, height):
|
33 |
try:
|
|
|
|
|
|
|
|
|
34 |
# Save the uploaded file to disk
|
35 |
input_pdf = os.path.join(INPUT_FOLDER, os.path.basename(file.name))
|
36 |
with open(input_pdf, "wb") as f:
|
37 |
-
f.write(file.read())
|
38 |
|
39 |
# Step 1: Convert PDF to SVG
|
40 |
convert_pdf_to_svg(input_pdf, SVG_OUTPUT, width, height)
|
@@ -50,7 +54,7 @@ def process_pdf(file, width, height):
|
|
50 |
except Exception as e:
|
51 |
# Log the error
|
52 |
log_conversion("Failed", "N/A", "N/A", "N/A", str(e))
|
53 |
-
#
|
54 |
return None, None
|
55 |
|
56 |
# Gradio interface
|
@@ -58,16 +62,16 @@ iface = gr.Interface(
|
|
58 |
fn=process_pdf,
|
59 |
inputs=[
|
60 |
gr.File(label="Upload your PDF file", file_types=[".pdf"]),
|
61 |
-
gr.Number(label="Width (in inches)", value=8.0),
|
62 |
-
gr.Number(label="Height (in inches)", value=11.0),
|
63 |
],
|
64 |
outputs=[
|
65 |
gr.File(label="Download SVG"),
|
66 |
gr.File(label="Download PDF"),
|
67 |
],
|
68 |
title="PDF to Editable SVG and PDF Converter",
|
69 |
-
description="Upload a PDF file, specify
|
70 |
)
|
71 |
|
72 |
if __name__ == "__main__":
|
73 |
-
iface.launch()
|
|
|
31 |
# Gradio interface function
|
32 |
def process_pdf(file, width, height):
|
33 |
try:
|
34 |
+
# Check if file is uploaded
|
35 |
+
if not file:
|
36 |
+
raise ValueError("No file uploaded.")
|
37 |
+
|
38 |
# Save the uploaded file to disk
|
39 |
input_pdf = os.path.join(INPUT_FOLDER, os.path.basename(file.name))
|
40 |
with open(input_pdf, "wb") as f:
|
41 |
+
f.write(file.read())
|
42 |
|
43 |
# Step 1: Convert PDF to SVG
|
44 |
convert_pdf_to_svg(input_pdf, SVG_OUTPUT, width, height)
|
|
|
54 |
except Exception as e:
|
55 |
# Log the error
|
56 |
log_conversion("Failed", "N/A", "N/A", "N/A", str(e))
|
57 |
+
# Raise an error to be shown in Gradio UI
|
58 |
return None, None
|
59 |
|
60 |
# Gradio interface
|
|
|
62 |
fn=process_pdf,
|
63 |
inputs=[
|
64 |
gr.File(label="Upload your PDF file", file_types=[".pdf"]),
|
65 |
+
gr.Number(label="Width (in inches)", value=8.0, precision=1),
|
66 |
+
gr.Number(label="Height (in inches)", value=11.0, precision=1),
|
67 |
],
|
68 |
outputs=[
|
69 |
gr.File(label="Download SVG"),
|
70 |
gr.File(label="Download PDF"),
|
71 |
],
|
72 |
title="PDF to Editable SVG and PDF Converter",
|
73 |
+
description="Upload a PDF file, specify output dimensions (in inches), and convert it to editable SVG and PDF files.",
|
74 |
)
|
75 |
|
76 |
if __name__ == "__main__":
|
77 |
+
iface.launch(debug=True)
|