SathvikGanta
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -17,13 +17,16 @@ os.makedirs(OUTPUT_FOLDER, exist_ok=True)
|
|
17 |
os.makedirs(LOG_FOLDER, exist_ok=True)
|
18 |
|
19 |
# Function to log conversion steps
|
20 |
-
def log_conversion(status, input_pdf, output_svg, output_pdf):
|
21 |
log_path = os.path.join(LOG_FOLDER, "conversion_log.txt")
|
22 |
with open(log_path, "a") as log_file:
|
23 |
log_file.write(f"{datetime.datetime.now()} - Status: {status}\n")
|
24 |
log_file.write(f"Input PDF: {input_pdf}\n")
|
25 |
log_file.write(f"Output SVG: {output_svg}\n")
|
26 |
-
log_file.write(f"Output PDF: {output_pdf}\n
|
|
|
|
|
|
|
27 |
|
28 |
# Gradio interface function
|
29 |
def process_pdf(file, width, height):
|
@@ -31,7 +34,7 @@ def process_pdf(file, width, height):
|
|
31 |
# Save the uploaded file to disk
|
32 |
input_pdf = os.path.join(INPUT_FOLDER, os.path.basename(file.name))
|
33 |
with open(input_pdf, "wb") as f:
|
34 |
-
f.write(file.read()) #
|
35 |
|
36 |
# Step 1: Convert PDF to SVG
|
37 |
convert_pdf_to_svg(input_pdf, SVG_OUTPUT, width, height)
|
@@ -46,8 +49,8 @@ def process_pdf(file, width, height):
|
|
46 |
return SVG_OUTPUT, PDF_OUTPUT
|
47 |
except Exception as e:
|
48 |
# Log the error
|
49 |
-
log_conversion("Failed", "N/A", "N/A", "N/A")
|
50 |
-
# Return None for files
|
51 |
return None, None
|
52 |
|
53 |
# Gradio interface
|
@@ -63,6 +66,7 @@ iface = gr.Interface(
|
|
63 |
gr.File(label="Download PDF"),
|
64 |
],
|
65 |
title="PDF to Editable SVG and PDF Converter",
|
|
|
66 |
)
|
67 |
|
68 |
if __name__ == "__main__":
|
|
|
17 |
os.makedirs(LOG_FOLDER, exist_ok=True)
|
18 |
|
19 |
# Function to log conversion steps
|
20 |
+
def log_conversion(status, input_pdf, output_svg, output_pdf, error_message=None):
|
21 |
log_path = os.path.join(LOG_FOLDER, "conversion_log.txt")
|
22 |
with open(log_path, "a") as log_file:
|
23 |
log_file.write(f"{datetime.datetime.now()} - Status: {status}\n")
|
24 |
log_file.write(f"Input PDF: {input_pdf}\n")
|
25 |
log_file.write(f"Output SVG: {output_svg}\n")
|
26 |
+
log_file.write(f"Output PDF: {output_pdf}\n")
|
27 |
+
if error_message:
|
28 |
+
log_file.write(f"Error: {error_message}\n")
|
29 |
+
log_file.write("\n")
|
30 |
|
31 |
# Gradio interface function
|
32 |
def process_pdf(file, width, height):
|
|
|
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()) # Extract file content
|
38 |
|
39 |
# Step 1: Convert PDF to SVG
|
40 |
convert_pdf_to_svg(input_pdf, SVG_OUTPUT, width, height)
|
|
|
49 |
return SVG_OUTPUT, PDF_OUTPUT
|
50 |
except Exception as e:
|
51 |
# Log the error
|
52 |
+
log_conversion("Failed", "N/A", "N/A", "N/A", str(e))
|
53 |
+
# Return None for files and show an error message
|
54 |
return None, None
|
55 |
|
56 |
# Gradio interface
|
|
|
66 |
gr.File(label="Download PDF"),
|
67 |
],
|
68 |
title="PDF to Editable SVG and PDF Converter",
|
69 |
+
description="Upload a PDF file, specify the output dimensions (in inches), and convert it into editable SVG and PDF files.",
|
70 |
)
|
71 |
|
72 |
if __name__ == "__main__":
|