SathvikGanta
commited on
Commit
•
e89d11f
1
Parent(s):
4cc513d
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
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
|
8 |
+
INPUT_FOLDER = "./input/"
|
9 |
+
OUTPUT_FOLDER = "./output/"
|
10 |
+
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\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")
|
34 |
+
if uploaded_file:
|
35 |
+
input_pdf = os.path.join(INPUT_FOLDER, "uploaded_file.pdf")
|
36 |
+
with open(input_pdf, "wb") as f:
|
37 |
+
f.write(uploaded_file.read())
|
38 |
+
st.success(f"File uploaded: {uploaded_file.name}")
|
39 |
+
|
40 |
+
# User controls for adjustments
|
41 |
+
brightness = st.slider("Brightness (0.5 to 5.0)", 0.5, 5.0, 1.0, step=0.5)
|
42 |
+
text_scale = st.slider("Text Size Scale (0.5 to 2.0)", 0.5, 2.0, 1.0, step=0.1)
|
43 |
+
line_scale = st.slider("Line Thickness Scale (0.5 to 5.0)", 0.5, 5.0, 1.0, step=0.5)
|
44 |
+
width = st.number_input("Width (in inches)", value=8.0, step=0.1)
|
45 |
+
height = st.number_input("Height (in inches)", value=11.0, step=0.1)
|
46 |
+
|
47 |
+
# Process the file
|
48 |
+
if st.button("Process PDF"):
|
49 |
+
try:
|
50 |
+
# Step 1: Convert PDF to SVG
|
51 |
+
convert_pdf_to_svg(input_pdf, SVG_OUTPUT, width, height)
|
52 |
+
|
53 |
+
# Step 2: Apply transformations to the SVG
|
54 |
+
apply_transformations(SVG_OUTPUT, brightness, text_scale, line_scale)
|
55 |
+
|
56 |
+
# Step 3: Log the process
|
57 |
+
log_conversion("Success", input_pdf, SVG_OUTPUT)
|
58 |
+
|
59 |
+
# Provide download link
|
60 |
+
st.success("File processed successfully!")
|
61 |
+
st.download_button("Download SVG", open(SVG_OUTPUT, "rb"), file_name="processed_diagram.svg")
|
62 |
+
st.info("You can now import this SVG into CorelDRAW.")
|
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()
|