nopperl/lineart-vectorizer
9
1from os.path import basename, splitext2import spaces3import gradio as gr4from huggingface_hub import hf_hub_download5 6from onnx_inference import vectorize_image7 8 9MODEL_PATH = hf_hub_download("nopperl/marked-lineart-vectorizer", "model.onnx")10 11@spaces.GPU12def predict(input_image_path, threshold, stroke_width):13 output_filepath = splitext(basename(input_image_path))[0] + ".svg"14 for recons_img in vectorize_image(input_image_path, model=MODEL_PATH, output=output_filepath, threshold_ratio=threshold, stroke_width=stroke_width):15 yield recons_img16 yield output_filepath17 18 19interface = gr.Interface(20 predict,21 inputs=[gr.Image(sources="upload", type="filepath"), gr.Slider(minimum=0.1, maximum=0.9, value=0.1, label="threshold"), gr.Slider(minimum=0.1, maximum=4.0, value=0.512, label="stroke_width")],22 outputs=gr.Image(),23 description="Demo for a model that converts raster line-art images into vector images iteratively. The model is trained on black-and-white line-art images, hence it won't work with other images. Inference time will be quite slow due to a lack of GPU resources. More information at https://github.com/nopperl/marked-lineart-vectorization.",24 examples = [25 ["examples/01.png", 0.1, 0.512],26 ["examples/02.png", 0.1, 0.512]27 ],28 analytics_enabled=False,29 cache_examples=False30 )31interface.launch()32 