weepakistan commited on
Commit
d541579
·
verified ·
1 Parent(s): bc17813

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -52
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import io
2
  import gradio as gr
3
  from PIL import Image
4
- import vtracer # Make sure you have vtracer installed
5
  import tempfile
6
 
7
  def convert_image(image, color_mode, hierarchical, mode, filter_speckle,
@@ -38,56 +38,28 @@ def convert_image(image, color_mode, hierarchical, mode, filter_speckle,
38
 
39
  return gr.HTML(f'<svg viewBox="0 0 {image.width} {image.height}">{svg_str}</svg>'), temp_file.name
40
 
41
- # HTML code for the ad banners (combined)
42
- ad_code = """
43
- <div style="text-align: center;">
44
- <iframe src="https://www.fiverr.com/gig_widgets?id=U2FsdGVkX1+9vQaosK0mq7xGXzIb/5hdFYIQsmHlpeMwFm5gingveDZKXBz2oJwV7ZwvToxseOx/KzKtr77ryB3qTb83/+GvCyI8OKpZcSgM0sDHzEPlZnqNeu8Db4y/IXlAceA1UcYT5Z3cW5vBLrgJ/WOpyMWSiyfwwMmGngjltQBexcivW7ukRd+/0yos7GCbfGjGdnLPHm2LB/CB9w2mA1i8cVv9LU+UUdj/O5KLRXtnychl9wAMkPTpmwMiyuAfUZy0nbK/Xa5O2UecmCvn7wicTr0TCTpLmIxaEh3YftXOVr9e36OGVYTmy5nlsgujkqJPI7wL0dXfon0ru4kvoycC7UD6m/whMoxrWZOf386qV2eEeXzk3vKO/emXUUfSavtofzSBtjLcyAOVhnHJg27PvVPgvFTQdy0o3F1M0DaHYTVW3Ln45MPYvMSH&affiliate_id=36184&strip_google_tagmanager=true" loading="lazy" data-with-title="false" class="fiverr_nga_frame" frameborder="0" height="350" width="100%" referrerpolicy="no-referrer-when-downgrade" data-mode="random_gigs" onload=" var frame = this; var script = document.createElement('script'); script.addEventListener('load', function() { window.FW_SDK.register(frame); }); script.setAttribute('src', 'https://www.fiverr.com/gig_widgets/sdk'); document.body.appendChild(script); " ></iframe>
45
 
46
- <a href="https://beta.publishers.adsterra.com/referral/UNXJYTziBP" target="_blank" style="display: inline-block;">
47
- <img decoding="async" alt="banner" src="https://landings-cdn.adsterratech.com/referralBanners/gif/468x120_adsterra_reff.gif">
48
- </a>
49
- <a href="https://go.fiverr.com/visit/?bta=36184&brand=fiverrcpa&landingPage=https%253A%252F%252Fwww.fiverr.com%252Fcategories%252Fprogramming-tech%252Fai-coding%252Fai-applications%253Fsource%253Dcategory_tree" target="_blank" style="display: inline-block;">
50
- <img fetchpriority="high" decoding="async" width="468" height="120" src="https://ziverr.xyz/wp-content/uploads/2024/06/PASSIVE-1.gif" class="attachment-large size-large wp-image-1266" alt="">
51
- </a>
52
- </div>
53
- """
54
 
55
- # Gradio interface
56
- with gr.Blocks() as iface:
57
- # Combine ads into one HTML block
58
- gr.HTML(ad_code)
59
-
60
- # Your main interface components
61
- with gr.Row(): # Arrange the interface elements in a row
62
- with gr.Column():
63
- image_input = gr.Image(type="pil", label="Upload Image")
64
- color_mode = gr.Radio(choices=["Color", "Binary"], value="Color", label="Color Mode")
65
- hierarchical = gr.Radio(choices=["Stacked", "Cutout"], value="Stacked", label="Hierarchical")
66
- mode = gr.Radio(choices=["Spline", "Polygon", "None"], value="Spline", label="Mode")
67
- filter_speckle = gr.Slider(minimum=1, maximum=10, value=4, step=1, label="Filter Speckle")
68
- color_precision = gr.Slider(minimum=1, maximum=8, value=6, step=1, label="Color Precision")
69
- layer_difference = gr.Slider(minimum=1, maximum=32, value=16, step=1, label="Layer Difference")
70
- corner_threshold = gr.Slider(minimum=10, maximum=90, value=60, step=1, label="Corner Threshold")
71
- length_threshold = gr.Slider(minimum=3.5, maximum=10, value=4.0, step=0.5, label="Length Threshold")
72
- max_iterations = gr.Slider(minimum=1, maximum=20, value=10, step=1, label="Max Iterations")
73
- splice_threshold = gr.Slider(minimum=10, maximum=90, value=45, step=1, label="Splice Threshold")
74
- path_precision = gr.Slider(minimum=1, maximum=10, value=8, step=1, label="Path Precision")
75
-
76
- with gr.Column():
77
- svg_output = gr.HTML(label="SVG Output")
78
- svg_download = gr.File(label="Download SVG")
79
-
80
- # Link the inputs and outputs to the function
81
- convert_button = gr.Button("Convert Image")
82
- convert_button.click(
83
- fn=convert_image,
84
- inputs=[
85
- image_input, color_mode, hierarchical, mode, filter_speckle,
86
- color_precision, layer_difference, corner_threshold,
87
- length_threshold, max_iterations, splice_threshold, path_precision
88
- ],
89
- outputs=[svg_output, svg_download]
90
- )
91
-
92
-
93
- iface.launch()
 
1
  import io
2
  import gradio as gr
3
  from PIL import Image
4
+ import vtracer
5
  import tempfile
6
 
7
  def convert_image(image, color_mode, hierarchical, mode, filter_speckle,
 
38
 
39
  return gr.HTML(f'<svg viewBox="0 0 {image.width} {image.height}">{svg_str}</svg>'), temp_file.name
40
 
 
 
 
 
41
 
 
 
 
 
 
 
 
 
42
 
43
+ app = gr.Interface(
44
+ fn=convert_image, inputs=[
45
+ gr.Image(type="pil", label="Upload Image"),
46
+ gr.Radio(choices=["Color", "Binary"], value="Color", label="Color Mode"),
47
+ gr.Radio(choices=["Stacked", "Cutout"], value="Stacked", label="Hierarchical"),
48
+ gr.Radio(choices=["Spline", "Polygon", "None"], value="Spline", label="Mode"),
49
+ gr.Slider(minimum=1, maximum=10, value=4, step=1, label="Filter Speckle"),
50
+ gr.Slider(minimum=1, maximum=8, value=6, step=1, label="Color Precision"),
51
+ gr.Slider(minimum=1, maximum=32, value=16, step=1, label="Layer Difference"),
52
+ gr.Slider(minimum=10, maximum=90, value=60, step=1, label="Corner Threshold"),
53
+ gr.Slider(minimum=3.5, maximum=10, value=4.0, step=0.5, label="Length Threshold"),
54
+ gr.Slider(minimum=1, maximum=20, value=10, step=1, label="Max Iterations"),
55
+ gr.Slider(minimum=10, maximum=90, value=45, step=1, label="Splice Threshold"),
56
+ gr.Slider(minimum=1, maximum=10, value=8, step=1, label="Path Precision")
57
+ ], outputs=[
58
+ gr.HTML(label="SVG Output"),
59
+ gr.File(label="Download SVG")
60
+ ],
61
+ title="Convert Image to SVG vectors",
62
+ description="Upload an image and customize the conversion parameters as needed.",
63
+ )
64
+ )
65
+ app.launch()