SathvikGanta
commited on
Commit
•
ed48751
1
Parent(s):
320fd56
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
import streamlit as st
|
3 |
from pdf_to_svg import convert_pdf_to_svg
|
4 |
from svg_editor import apply_transformations
|
|
|
5 |
import datetime
|
6 |
|
7 |
# Folder paths
|
@@ -11,23 +12,23 @@ LOG_FOLDER = "./logs/"
|
|
11 |
SVG_OUTPUT = os.path.join(OUTPUT_FOLDER, "processed_diagram.svg")
|
12 |
PDF_OUTPUT = os.path.join(OUTPUT_FOLDER, "processed_diagram.pdf")
|
13 |
|
14 |
-
|
15 |
# Ensure required folders exist
|
16 |
os.makedirs(INPUT_FOLDER, exist_ok=True)
|
17 |
os.makedirs(OUTPUT_FOLDER, exist_ok=True)
|
18 |
os.makedirs(LOG_FOLDER, exist_ok=True)
|
19 |
|
20 |
# Function to log conversion steps
|
21 |
-
def log_conversion(status, input_pdf, output_svg):
|
22 |
log_path = os.path.join(LOG_FOLDER, "conversion_log.txt")
|
23 |
with open(log_path, "a") as log_file:
|
24 |
log_file.write(f"{datetime.datetime.now()} - Status: {status}\n")
|
25 |
log_file.write(f"Input PDF: {input_pdf}\n")
|
26 |
-
log_file.write(f"Output SVG: {output_svg}\n
|
|
|
27 |
|
28 |
# Streamlit app interface
|
29 |
def main():
|
30 |
-
st.title("PDF to Editable SVG Converter")
|
31 |
|
32 |
# File upload
|
33 |
uploaded_file = st.file_uploader("Upload your PDF file", type="pdf")
|
@@ -53,16 +54,20 @@ def main():
|
|
53 |
# Step 2: Apply transformations to the SVG
|
54 |
apply_transformations(SVG_OUTPUT, brightness, text_scale, line_scale)
|
55 |
|
56 |
-
# Step 3:
|
57 |
-
|
|
|
|
|
|
|
58 |
|
59 |
-
# Provide download
|
60 |
st.success("File processed successfully!")
|
61 |
st.download_button("Download SVG", open(SVG_OUTPUT, "rb"), file_name="processed_diagram.svg")
|
62 |
-
st.
|
|
|
63 |
except Exception as e:
|
64 |
-
log_conversion("Failed", input_pdf, SVG_OUTPUT)
|
65 |
st.error(f"Error processing file: {e}")
|
66 |
|
67 |
if __name__ == "__main__":
|
68 |
-
main()
|
|
|
2 |
import streamlit as st
|
3 |
from pdf_to_svg import convert_pdf_to_svg
|
4 |
from svg_editor import apply_transformations
|
5 |
+
from svg_to_pdf import convert_svg_to_pdf
|
6 |
import datetime
|
7 |
|
8 |
# Folder paths
|
|
|
12 |
SVG_OUTPUT = os.path.join(OUTPUT_FOLDER, "processed_diagram.svg")
|
13 |
PDF_OUTPUT = os.path.join(OUTPUT_FOLDER, "processed_diagram.pdf")
|
14 |
|
|
|
15 |
# Ensure required folders exist
|
16 |
os.makedirs(INPUT_FOLDER, exist_ok=True)
|
17 |
os.makedirs(OUTPUT_FOLDER, exist_ok=True)
|
18 |
os.makedirs(LOG_FOLDER, exist_ok=True)
|
19 |
|
20 |
# Function to log conversion steps
|
21 |
+
def log_conversion(status, input_pdf, output_svg, output_pdf):
|
22 |
log_path = os.path.join(LOG_FOLDER, "conversion_log.txt")
|
23 |
with open(log_path, "a") as log_file:
|
24 |
log_file.write(f"{datetime.datetime.now()} - Status: {status}\n")
|
25 |
log_file.write(f"Input PDF: {input_pdf}\n")
|
26 |
+
log_file.write(f"Output SVG: {output_svg}\n")
|
27 |
+
log_file.write(f"Output PDF: {output_pdf}\n\n")
|
28 |
|
29 |
# Streamlit app interface
|
30 |
def main():
|
31 |
+
st.title("PDF to Editable SVG and PDF Converter")
|
32 |
|
33 |
# File upload
|
34 |
uploaded_file = st.file_uploader("Upload your PDF file", type="pdf")
|
|
|
54 |
# Step 2: Apply transformations to the SVG
|
55 |
apply_transformations(SVG_OUTPUT, brightness, text_scale, line_scale)
|
56 |
|
57 |
+
# Step 3: Convert SVG to PDF
|
58 |
+
convert_svg_to_pdf(SVG_OUTPUT, PDF_OUTPUT)
|
59 |
+
|
60 |
+
# Step 4: Log the process
|
61 |
+
log_conversion("Success", input_pdf, SVG_OUTPUT, PDF_OUTPUT)
|
62 |
|
63 |
+
# Provide download links
|
64 |
st.success("File processed successfully!")
|
65 |
st.download_button("Download SVG", open(SVG_OUTPUT, "rb"), file_name="processed_diagram.svg")
|
66 |
+
st.download_button("Download PDF", open(PDF_OUTPUT, "rb"), file_name="processed_diagram.pdf")
|
67 |
+
st.info("Both SVG and PDF outputs are ready for download.")
|
68 |
except Exception as e:
|
69 |
+
log_conversion("Failed", input_pdf, SVG_OUTPUT, PDF_OUTPUT)
|
70 |
st.error(f"Error processing file: {e}")
|
71 |
|
72 |
if __name__ == "__main__":
|
73 |
+
main()
|