Spaces:
Running
Running
Create gradio_app.py
Browse files- gradio_app.py +42 -0
gradio_app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import sys
|
4 |
+
from animationPipeline import animateLogo
|
5 |
+
|
6 |
+
def process_svg(uploaded_file):
|
7 |
+
if uploaded_file is None:
|
8 |
+
return None
|
9 |
+
|
10 |
+
file_details = {"FileName": uploaded_file.name, "FileType": uploaded_file.type}
|
11 |
+
if not uploaded_file.name.lower().endswith('.svg'):
|
12 |
+
return "Please upload an SVG file."
|
13 |
+
|
14 |
+
if not os.path.exists('tempDir'):
|
15 |
+
os.mkdir('tempDir')
|
16 |
+
|
17 |
+
path = os.path.join('tempDir', uploaded_file.name)
|
18 |
+
targetPath = os.path.join('tempDir', uploaded_file.name[:-4] + "_animated.svg")
|
19 |
+
|
20 |
+
with open(path, "wb") as f:
|
21 |
+
f.write(uploaded_file.read())
|
22 |
+
|
23 |
+
sys.setrecursionlimit(1500)
|
24 |
+
success = animateLogo(path, targetPath)
|
25 |
+
|
26 |
+
if success:
|
27 |
+
return targetPath
|
28 |
+
else:
|
29 |
+
return "This SVG cannot be animated due to limitations of the used DeepSVG library. Please use another file."
|
30 |
+
|
31 |
+
iface = gr.Interface(
|
32 |
+
fn=process_svg,
|
33 |
+
inputs=gr.File(label="Upload SVG file", file_types=[".svg"]),
|
34 |
+
outputs=[
|
35 |
+
gr.File(label="Download animated SVG"),
|
36 |
+
gr.Textbox(label="Status")
|
37 |
+
],
|
38 |
+
title="SVG Animation Tool",
|
39 |
+
description="Upload an SVG file to animate it using DeepSVG library"
|
40 |
+
)
|
41 |
+
|
42 |
+
iface.launch(share = True)
|