Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
import vtracer
|
3 |
import os
|
4 |
-
from svglib.svglib import svg2rlg
|
5 |
-
from reportlab.graphics import renderPDF
|
6 |
|
7 |
-
def
|
8 |
-
"""SVG를
|
9 |
try:
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
14 |
except Exception as e:
|
15 |
-
print(f"
|
16 |
return None
|
17 |
|
18 |
def convert_svg_to_ai(svg_path):
|
@@ -59,10 +62,10 @@ def convert_svg_to_ai(svg_path):
|
|
59 |
ai_file.write("\n%%EndDocument\n")
|
60 |
ai_file.write("\n%%Trailer\n%%EOF\n")
|
61 |
|
62 |
-
#
|
63 |
-
|
64 |
|
65 |
-
return ai_path,
|
66 |
|
67 |
def convert_to_vector(
|
68 |
image,
|
@@ -122,10 +125,9 @@ def convert_to_vector(
|
|
122 |
|
123 |
# AI 파일 처리
|
124 |
if save_ai:
|
125 |
-
ai_path,
|
126 |
outputs.append(ai_path)
|
127 |
-
|
128 |
-
ai_preview = pdf_preview
|
129 |
|
130 |
if not save_svg: # SVG가 선택되지 않았다면 임시 파일 삭제
|
131 |
os.remove(svg_path)
|
@@ -224,7 +226,7 @@ with gr.Blocks(css=css) as app:
|
|
224 |
preview = gr.HTML(label="SVG Preview")
|
225 |
svg_output = gr.File(label="Download SVG", visible=True)
|
226 |
with gr.Tab("AI Preview"):
|
227 |
-
ai_preview = gr.
|
228 |
ai_output = gr.File(label="Download AI", visible=True)
|
229 |
|
230 |
examples = [
|
|
|
1 |
import gradio as gr
|
2 |
import vtracer
|
3 |
import os
|
|
|
|
|
4 |
|
5 |
+
def create_preview_html(svg_path):
|
6 |
+
"""SVG를 HTML 미리보기로 변환"""
|
7 |
try:
|
8 |
+
with open(svg_path, 'r', encoding='utf-8') as f:
|
9 |
+
svg_content = f.read()
|
10 |
+
# SVG를 HTML로 감싸서 반환
|
11 |
+
preview_html = f'''
|
12 |
+
<div style="width:100%; height:100%; background-color: white; padding: 20px;">
|
13 |
+
{svg_content}
|
14 |
+
</div>
|
15 |
+
'''
|
16 |
+
return preview_html
|
17 |
except Exception as e:
|
18 |
+
print(f"미리보기 생성 실패: {str(e)}")
|
19 |
return None
|
20 |
|
21 |
def convert_svg_to_ai(svg_path):
|
|
|
62 |
ai_file.write("\n%%EndDocument\n")
|
63 |
ai_file.write("\n%%Trailer\n%%EOF\n")
|
64 |
|
65 |
+
# HTML 미리보기 생성
|
66 |
+
preview_html = create_preview_html(svg_path)
|
67 |
|
68 |
+
return ai_path, preview_html
|
69 |
|
70 |
def convert_to_vector(
|
71 |
image,
|
|
|
125 |
|
126 |
# AI 파일 처리
|
127 |
if save_ai:
|
128 |
+
ai_path, preview_html = convert_svg_to_ai(svg_path)
|
129 |
outputs.append(ai_path)
|
130 |
+
ai_preview = preview_html
|
|
|
131 |
|
132 |
if not save_svg: # SVG가 선택되지 않았다면 임시 파일 삭제
|
133 |
os.remove(svg_path)
|
|
|
226 |
preview = gr.HTML(label="SVG Preview")
|
227 |
svg_output = gr.File(label="Download SVG", visible=True)
|
228 |
with gr.Tab("AI Preview"):
|
229 |
+
ai_preview = gr.HTML(label="AI Preview")
|
230 |
ai_output = gr.File(label="Download AI", visible=True)
|
231 |
|
232 |
examples = [
|