namelessai commited on
Commit
d105ffe
·
verified ·
1 Parent(s): 8499a32

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -0
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from wand.image import Image
3
+ import tempfile
4
+ import os
5
+
6
+ def convert_eps_to_svg(eps_file):
7
+ """
8
+ Convert EPS file to SVG using Wand (ImageMagick wrapper)
9
+ """
10
+ if eps_file is None:
11
+ return None, "Please upload an EPS file"
12
+
13
+ try:
14
+ # Create temporary file for output
15
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.svg') as tmp_svg:
16
+ svg_path = tmp_svg.name
17
+
18
+ # Convert EPS to SVG using Wand
19
+ with Image(filename=eps_file.name) as img:
20
+ img.format = 'svg'
21
+ img.save(filename=svg_path)
22
+
23
+ # Read the SVG content for preview
24
+ with open(svg_path, 'r') as f:
25
+ svg_content = f.read()
26
+
27
+ return svg_path, "Conversion successful! Download your SVG file below."
28
+
29
+ except Exception as e:
30
+ return None, f"Error during conversion: {str(e)}"
31
+
32
+ # Create Gradio interface
33
+ with gr.Blocks(title="EPS to SVG Converter") as app:
34
+ gr.Markdown("# EPS to SVG Converter")
35
+ gr.Markdown("Upload an EPS file to convert it to SVG format using Ghostscript and ImageMagick.")
36
+
37
+ with gr.Row():
38
+ with gr.Column():
39
+ eps_input = gr.File(
40
+ label="Upload EPS File",
41
+ file_types=[".eps"],
42
+ type="filepath"
43
+ )
44
+ convert_btn = gr.Button("Convert to SVG", variant="primary")
45
+
46
+ with gr.Column():
47
+ status_output = gr.Textbox(label="Status", interactive=False)
48
+ svg_output = gr.File(label="Download SVG")
49
+
50
+ convert_btn.click(
51
+ fn=convert_eps_to_svg,
52
+ inputs=[eps_input],
53
+ outputs=[svg_output, status_output]
54
+ )
55
+
56
+ gr.Markdown("""
57
+ ### How to use:
58
+ 1. Upload an EPS file using the file picker
59
+ 2. Click 'Convert to SVG' button
60
+ 3. Download the converted SVG file
61
+
62
+ ### Requirements:
63
+ - Ghostscript (for EPS processing)
64
+ - ImageMagick (for format conversion)
65
+ - Python Wand library (ImageMagick binding)
66
+ """)
67
+
68
+ if __name__ == "__main__":
69
+ app.launch(server_name="0.0.0.0", server_port=7860)