m3g4p0p commited on
Commit
23b7e6c
·
1 Parent(s): ff91eea

add error control

Browse files
Files changed (1) hide show
  1. myapp/app.py +6 -2
myapp/app.py CHANGED
@@ -10,6 +10,7 @@ from gradio.components import Component
10
  from huggingface_hub import InferenceClient
11
  from PIL import Image
12
  from qrcode_artistic import write_artistic
 
13
 
14
  from myapp.colorutils import array_to_hex
15
  from myapp.palette import extract_color_clusters, sort_color_clusters
@@ -45,14 +46,15 @@ with gr.Blocks() as demo:
45
  str(static_path / "example.webp"), visible=False, type="filepath"
46
  )
47
  scale = gr.Slider(3, 15, 9, step=1, label="Scale")
 
48
 
49
  with gr.Row():
50
  color_dark = gr.ColorPicker("#000000", label="Dark")
51
  color_light = gr.ColorPicker("#FFFFFF", label="Light")
52
 
53
  with gr.Row():
54
- gr.ClearButton([color_dark, color_light], value="Reset")
55
  extract_colors = gr.Button("Extract")
 
56
 
57
  def generate_background(data: dict[Component, Any]):
58
  if not data.get(prompt):
@@ -77,7 +79,7 @@ with gr.Blocks() as demo:
77
  return f"#{r:02X}{g:02X}{b:02X}"
78
 
79
  image = Image.open(data[background])
80
- qr_code = segno.make(data[text], error="h")
81
 
82
  with BytesIO() as buffer:
83
  write_artistic(
@@ -121,6 +123,7 @@ with gr.Blocks() as demo:
121
  text.submit,
122
  background.change,
123
  scale.change,
 
124
  color_light.change,
125
  color_dark.change,
126
  ],
@@ -129,6 +132,7 @@ with gr.Blocks() as demo:
129
  text,
130
  background,
131
  scale,
 
132
  color_light,
133
  color_dark,
134
  },
 
10
  from huggingface_hub import InferenceClient
11
  from PIL import Image
12
  from qrcode_artistic import write_artistic
13
+ from segno.consts import ERROR_MAPPING
14
 
15
  from myapp.colorutils import array_to_hex
16
  from myapp.palette import extract_color_clusters, sort_color_clusters
 
46
  str(static_path / "example.webp"), visible=False, type="filepath"
47
  )
48
  scale = gr.Slider(3, 15, 9, step=1, label="Scale")
49
+ error = gr.Radio(list(ERROR_MAPPING), value="H", label="Error")
50
 
51
  with gr.Row():
52
  color_dark = gr.ColorPicker("#000000", label="Dark")
53
  color_light = gr.ColorPicker("#FFFFFF", label="Light")
54
 
55
  with gr.Row():
 
56
  extract_colors = gr.Button("Extract")
57
+ gr.ClearButton([color_dark, color_light], value="Reset")
58
 
59
  def generate_background(data: dict[Component, Any]):
60
  if not data.get(prompt):
 
79
  return f"#{r:02X}{g:02X}{b:02X}"
80
 
81
  image = Image.open(data[background])
82
+ qr_code = segno.make(data[text], error=data[error])
83
 
84
  with BytesIO() as buffer:
85
  write_artistic(
 
123
  text.submit,
124
  background.change,
125
  scale.change,
126
+ error.change,
127
  color_light.change,
128
  color_dark.change,
129
  ],
 
132
  text,
133
  background,
134
  scale,
135
+ error,
136
  color_light,
137
  color_dark,
138
  },