Spaces:
Runtime error
Runtime error
Update app.py
Browse files123456730 unmodified lines383940414243444546474849505152531 unmodified line555657585960616263646566676869707172737475767778798081828384858687888990919293import ioimport gradio as grfrom PIL import Imageimport vtracerimport tempfiledef convert_image(image, color_mode, hierarchical, mode, filter_speckle,30 unmodified linesreturn gr.HTML(f'<svg viewBox="0 0 {image.width} {image.height}">{svg_str}</svg>'), temp_file.name# HTML code for the ad bannerad_code = """<div style="text-align: center;"><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></div>"""# HTML code for the ad bannerad_code2 = """<div style="text-align: center;"><a href="https://beta.publishers.adsterra.com/referral/UNXJYTziBP" target="_blank" style="display: inline-block;"><img decoding="async" alt="banner" src="https://landings-cdn.adsterratech.com/referralBanners/gif/468x120_adsterra_reff.gif"></a>1 unmodified line<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=""></a></div>"""# Gradio interfaceiface = gr.Blocks()with iface:gr.HTML(ad_code2)gr.Interface(fn=convert_image,inputs=[gr.Image(type="pil", label="Upload Image"),gr.Radio(choices=["Color", "Binary"], value="Color", label="Color Mode"),gr.Radio(choices=["Stacked", "Cutout"], value="Stacked", label="Hierarchical"),gr.Radio(choices=["Spline", "Polygon", "None"], value="Spline", label="Mode"),gr.Slider(minimum=1, maximum=10, value=4, step=1, label="Filter Speckle"),gr.Slider(minimum=1, maximum=8, value=6, step=1, label="Color Precision"),gr.Slider(minimum=1, maximum=32, value=16, step=1, label="Layer Difference"),gr.Slider(minimum=10, maximum=90, value=60, step=1, label="Corner Threshold"),gr.Slider(minimum=3.5, maximum=10, value=4.0, step=0.5, label="Length Threshold"),gr.Slider(minimum=1, maximum=20, value=10, step=1, label="Max Iterations"),gr.Slider(minimum=10, maximum=90, value=45, step=1, label="Splice Threshold"),gr.Slider(minimum=1, maximum=10, value=8, step=1, label="Path Precision")],outputs=[gr.HTML(label="SVG Output"),gr.File(label="Download SVG")],title="Convert Image to SVG vectors",description="Upload an image and customize the conversion parameters as needed.",)gr.HTML(ad_code)iface.launch()123456730 unmodified lines38394041424344454647481 unmodified line5051525354555657585960616263646566676869707172737475767778798081828384858687888990919293import ioimport gradio as grfrom PIL import Imageimport vtracer # Make sure you have vtracer installedimport tempfiledef convert_image(image, color_mode, hierarchical, mode, filter_speckle,30 unmodified linesreturn gr.HTML(f'<svg viewBox="0 0 {image.width} {image.height}">{svg_str}</svg>'), temp_file.name# HTML code for the ad banners (combined)ad_code = """<div style="text-align: center;"><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><a href="https://beta.publishers.adsterra.com/referral/UNXJYTziBP" target="_blank" style="display: inline-block;"><img decoding="async" alt="banner" src="https://landings-cdn.adsterratech.com/referralBanners/gif/468x120_adsterra_reff.gif"></a>1 unmodified line<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=""></a></div>"""# Gradio interfacewith gr.Blocks() as iface:# Combine ads into one HTML blockgr.HTML(ad_code)# Your main interface componentswith gr.Row(): # Arrange the interface elements in a rowwith gr.Column():image_input = gr.Image(type="pil", label="Upload Image")color_mode = gr.Radio(choices=["Color", "Binary"], value="Color", label="Color Mode")hierarchical = gr.Radio(choices=["Stacked", "Cutout"], value="Stacked", label="Hierarchical")mode = gr.Radio(choices=["Spline", "Polygon", "None"], value="Spline", label="Mode")filter_speckle = gr.Slider(minimum=1, maximum=10, value=4, step=1, label="Filter Speckle")color_precision = gr.Slider(minimum=1, maximum=8, value=6, step=1, label="Color Precision")layer_difference = gr.Slider(minimum=1, maximum=32, value=16, step=1, label="Layer Difference")corner_threshold = gr.Slider(minimum=10, maximum=90, value=60, step=1, label="Corner Threshold")length_threshold = gr.Slider(minimum=3.5, maximum=10, value=4.0, step=0.5, label="Length Threshold")max_iterations = gr.Slider(minimum=1, maximum=20, value=10, step=1, label="Max Iterations")splice_threshold = gr.Slider(minimum=10, maximum=90, value=45, step=1, label="Splice Threshold")path_precision = gr.Slider(minimum=1, maximum=10, value=8, step=1, label="Path Precision")with gr.Column():svg_output = gr.HTML(label="SVG Output")svg_download = gr.File(label="Download SVG")# Link the inputs and outputs to the functionconvert_button = gr.Button("Convert Image")convert_button.click(fn=convert_image,inputs=[image_input, color_mode, hierarchical, mode, filter_speckle,color_precision, layer_difference, corner_threshold,length_threshold, max_iterations, splice_threshold, path_precision],outputs=[svg_output, svg_download])iface.launch()
app.py+38-38