aaurelions commited on
Commit
3b263fa
·
verified ·
1 Parent(s): 0fddbf9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -13
app.py CHANGED
@@ -46,7 +46,6 @@ def image_to_svg(image, colormode, hierarchical, filter_speckle, color_precision
46
  # --- Gradio User Interface ---
47
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
48
 
49
- # --- Top Row: Upload and Project Info ---
50
  with gr.Row():
51
  with gr.Column(scale=1):
52
  image_input = gr.Image(type="filepath", label="Upload Your Image", sources=["upload", "clipboard"])
@@ -63,9 +62,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
63
  """
64
  )
65
 
66
- # --- Bottom Row: Controls and Output ---
67
  with gr.Row(variant="panel"):
68
- # ----- Control Panel Column -----
69
  with gr.Column(scale=1):
70
  gr.Markdown("### Control Panel")
71
  with gr.Group():
@@ -73,7 +70,11 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
73
  colormode = gr.Radio(["Color", "B/W"], value="Color", label="Color Mode")
74
  hierarchical = gr.Radio(["Stacked", "Cutout"], value="Stacked", label="Hierarchical Mode")
75
  filter_speckle = gr.Slider(0, 128, value=4, step=1, label="Filter Speckle (Cleaner)")
76
- color_precision = gr.Slider(0, 8, value=6, step=1, label="Color Precision (More accurate)")
 
 
 
 
77
  layer_difference = gr.Slider(0, 128, value=16, step=1, label="Gradient Step (Less layers)")
78
 
79
  with gr.Group():
@@ -84,7 +85,6 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
84
  splice_threshold = gr.Slider(0, 180, value=45, step=1, label="Splice Threshold (Less accurate)")
85
  path_precision = gr.Slider(1, 8, value=3, step=1, label="Path Precision")
86
 
87
- # ----- Output Column -----
88
  with gr.Column(scale=2):
89
  gr.Markdown("### Result")
90
  with gr.Tabs():
@@ -94,8 +94,6 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
94
  svg_text_output = gr.Code(label="Generated SVG Code", language="html", interactive=False)
95
 
96
  svg_file_output = gr.File(label="Download SVG")
97
-
98
- # --- Event Handling for Live Update ---
99
 
100
  all_inputs = [
101
  image_input, colormode, hierarchical, filter_speckle, color_precision,
@@ -104,16 +102,10 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
104
 
105
  all_outputs = [svg_file_output, svg_text_output, svg_image_output]
106
 
107
- # **THE FIX:** Use '.release' for sliders to avoid excessive updates.
108
- # Use '.change' for controls that only fire once per action.
109
-
110
- # Sliders will trigger the function only when the user lets go of the mouse.
111
  for slider in [filter_speckle, color_precision, layer_difference, corner_threshold, length_threshold, splice_threshold, path_precision]:
112
  slider.release(fn=image_to_svg, inputs=all_inputs, outputs=all_outputs)
113
 
114
- # Image upload and radio buttons will trigger immediately on change.
115
  for component in [image_input, colormode, hierarchical, mode]:
116
  component.change(fn=image_to_svg, inputs=all_inputs, outputs=all_outputs)
117
 
118
- # To launch the application
119
  demo.launch()
 
46
  # --- Gradio User Interface ---
47
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
48
 
 
49
  with gr.Row():
50
  with gr.Column(scale=1):
51
  image_input = gr.Image(type="filepath", label="Upload Your Image", sources=["upload", "clipboard"])
 
62
  """
63
  )
64
 
 
65
  with gr.Row(variant="panel"):
 
66
  with gr.Column(scale=1):
67
  gr.Markdown("### Control Panel")
68
  with gr.Group():
 
70
  colormode = gr.Radio(["Color", "B/W"], value="Color", label="Color Mode")
71
  hierarchical = gr.Radio(["Stacked", "Cutout"], value="Stacked", label="Hierarchical Mode")
72
  filter_speckle = gr.Slider(0, 128, value=4, step=1, label="Filter Speckle (Cleaner)")
73
+
74
+ # **THE FIX:** The vtracer backend panics if color_precision is 8 or greater.
75
+ # The valid range is 0-7. This slider now enforces that constraint.
76
+ color_precision = gr.Slider(0, 7, value=6, step=1, label="Color Precision (More accurate)")
77
+
78
  layer_difference = gr.Slider(0, 128, value=16, step=1, label="Gradient Step (Less layers)")
79
 
80
  with gr.Group():
 
85
  splice_threshold = gr.Slider(0, 180, value=45, step=1, label="Splice Threshold (Less accurate)")
86
  path_precision = gr.Slider(1, 8, value=3, step=1, label="Path Precision")
87
 
 
88
  with gr.Column(scale=2):
89
  gr.Markdown("### Result")
90
  with gr.Tabs():
 
94
  svg_text_output = gr.Code(label="Generated SVG Code", language="html", interactive=False)
95
 
96
  svg_file_output = gr.File(label="Download SVG")
 
 
97
 
98
  all_inputs = [
99
  image_input, colormode, hierarchical, filter_speckle, color_precision,
 
102
 
103
  all_outputs = [svg_file_output, svg_text_output, svg_image_output]
104
 
 
 
 
 
105
  for slider in [filter_speckle, color_precision, layer_difference, corner_threshold, length_threshold, splice_threshold, path_precision]:
106
  slider.release(fn=image_to_svg, inputs=all_inputs, outputs=all_outputs)
107
 
 
108
  for component in [image_input, colormode, hierarchical, mode]:
109
  component.change(fn=image_to_svg, inputs=all_inputs, outputs=all_outputs)
110
 
 
111
  demo.launch()