radames commited on
Commit
95f13e5
1 Parent(s): a49bd51

small suggestions

Browse files
Files changed (2) hide show
  1. .gitignore +3 -0
  2. app.py +40 -25
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ __pycache__/
2
+ gradio_cached_examples/
3
+ venv/
app.py CHANGED
@@ -42,6 +42,7 @@ SAMPLER_MAP = {
42
  "DEIS": lambda config: DEISMultistepScheduler.from_config(config),
43
  }
44
 
 
45
  def create_code(content: str):
46
  qr = qrcode.QRCode(
47
  version=1,
@@ -63,10 +64,12 @@ def create_code(content: str):
63
  bg = Image.new('L', (w, h), 255)
64
 
65
  # align on 16px grid
66
- coords = ((w - img.size[0]) // 2 // 16 * 16, (h - img.size[1]) // 2 // 16 * 16)
 
67
  bg.paste(img, coords)
68
  return bg
69
 
 
70
  def inference(
71
  qr_code_content: str,
72
  prompt: str,
@@ -74,7 +77,7 @@ def inference(
74
  guidance_scale: float = 10.0,
75
  controlnet_conditioning_scale: float = 2.0,
76
  seed: int = -1,
77
- sampler = "DPM++ Karras SDE",
78
  ):
79
  if prompt is None or prompt == "":
80
  raise gr.Error("Prompt is required")
@@ -99,12 +102,14 @@ def inference(
99
  width=qrcode_image.width, # type: ignore
100
  height=qrcode_image.height, # type: ignore
101
  guidance_scale=float(guidance_scale),
102
- controlnet_conditioning_scale=float(controlnet_conditioning_scale), # type: ignore
 
103
  generator=generator,
104
  num_inference_steps=40,
105
  )
106
  return out.images[0] # type: ignore
107
 
 
108
  css = """
109
  #result_image {
110
  display: flex;
@@ -122,27 +127,22 @@ with gr.Blocks(css=css) as blocks:
122
  gr.Markdown(
123
  """
124
  # QR Code Monster v1.0
 
125
 
126
- model used: https://huggingface.co/monster-labs/control_v1p_sd15_qrcode_monster
127
-
128
- Welcome to the QR Code Monster!
129
-
130
- **TLDR:**
131
 
132
- Input your text, choose a prompt, and generate a QR code!
133
- The Controlnet Conditioning Scale parameter controls the readability/creativity of the QR code. Lower values will generate more creative QR codes, higher values will generate more readable QR codes.
134
-
135
-
136
- More instructions at the bottom of the page.
137
 
 
 
138
  """
139
  )
140
 
141
  with gr.Row():
142
  with gr.Column():
143
  qr_code_content = gr.Textbox(
144
- label="QR Code Content",
145
- info="QR Code Content or URL",
146
  value="",
147
  )
148
 
@@ -153,6 +153,7 @@ More instructions at the bottom of the page.
153
  negative_prompt = gr.Textbox(
154
  label="Negative Prompt",
155
  value="ugly, disfigured, low quality, blurry, nsfw",
 
156
  )
157
 
158
  with gr.Accordion(
@@ -165,6 +166,11 @@ More instructions at the bottom of the page.
165
  step=0.01,
166
  value=1.5,
167
  label="Controlnet Conditioning Scale",
 
 
 
 
 
168
  )
169
  guidance_scale = gr.Slider(
170
  minimum=0.0,
@@ -172,8 +178,10 @@ More instructions at the bottom of the page.
172
  step=0.25,
173
  value=7,
174
  label="Guidance Scale",
 
175
  )
176
- sampler = gr.Dropdown(choices=list(SAMPLER_MAP.keys()), value="Euler a", label="Sampler")
 
177
  seed = gr.Number(
178
  minimum=-1,
179
  maximum=9999999999,
@@ -181,11 +189,13 @@ More instructions at the bottom of the page.
181
  value=2313123,
182
  label="Seed",
183
  randomize=True,
 
184
  )
185
  with gr.Row():
186
  run_btn = gr.Button("Run")
187
  with gr.Column():
188
- result_image = gr.Image(label="Result Image", elem_id="result_image")
 
189
  run_btn.click(
190
  inference,
191
  inputs=[
@@ -203,7 +213,7 @@ More instructions at the bottom of the page.
203
  gr.Examples(
204
  examples=[
205
  [
206
- "test",
207
  "Baroque rococo architecture, architectural photography, post apocalyptic New York, hyperrealism, [roots], hyperrealistic, octane render, cinematic, hyper detailed, 8K",
208
  "",
209
  7,
@@ -212,7 +222,7 @@ More instructions at the bottom of the page.
212
  "Euler a",
213
  ],
214
  [
215
- "test",
216
  "a centered render of an ancient tree covered in bio - organic micro organisms growing in a mystical setting, cinematic, beautifully lit, by tomasz alen kopera and peter mohrbacher and craig mullins, 3d, trending on artstation, octane render, 8k",
217
  "",
218
  7,
@@ -221,7 +231,7 @@ More instructions at the bottom of the page.
221
  "Euler a",
222
  ],
223
  [
224
- "test",
225
  "3 cups of coffee with coffee beans around",
226
  "",
227
  7,
@@ -230,7 +240,7 @@ More instructions at the bottom of the page.
230
  "Euler a",
231
  ],
232
  [
233
- "sd is cool",
234
  "A top view picture of a sandy beach with a sand castle, beautiful lighting, 8k, highly detailed",
235
  "sky",
236
  7,
@@ -239,7 +249,7 @@ More instructions at the bottom of the page.
239
  "Euler a",
240
  ],
241
  [
242
- "test",
243
  "A top view picture of a sandy beach, organic shapes, beautiful lighting, bumps and shadows, 8k, highly detailed",
244
  "sky, water, squares",
245
  7,
@@ -263,6 +273,12 @@ More instructions at the bottom of the page.
263
  )
264
  gr.Markdown(
265
  """
 
 
 
 
 
 
266
  ## Parameters
267
 
268
  - **Input Text:** The text you want to encode into the QR code
@@ -271,7 +287,6 @@ More instructions at the bottom of the page.
271
 
272
  The generated QR codes might not always be easily readable. It might take a few tries with different parameters to find the right balance. This often depends on the prompt, which can be more or less suitable for QR code generation.
273
 
274
- We're already working on v2, which is much more powerful, you can try [an early version here](https://qrcodemonster.art)!
275
 
276
  ## How to Use
277
 
@@ -283,5 +298,5 @@ We're already working on v2, which is much more powerful, you can try [an early
283
  """
284
  )
285
 
286
- blocks.queue(concurrency_count=1, max_size=20)
287
- blocks.launch(share=bool(os.environ.get("SHARE", False)))
 
42
  "DEIS": lambda config: DEISMultistepScheduler.from_config(config),
43
  }
44
 
45
+
46
  def create_code(content: str):
47
  qr = qrcode.QRCode(
48
  version=1,
 
64
  bg = Image.new('L', (w, h), 255)
65
 
66
  # align on 16px grid
67
+ coords = ((w - img.size[0]) // 2 // 16 * 16,
68
+ (h - img.size[1]) // 2 // 16 * 16)
69
  bg.paste(img, coords)
70
  return bg
71
 
72
+
73
  def inference(
74
  qr_code_content: str,
75
  prompt: str,
 
77
  guidance_scale: float = 10.0,
78
  controlnet_conditioning_scale: float = 2.0,
79
  seed: int = -1,
80
+ sampler="DPM++ Karras SDE",
81
  ):
82
  if prompt is None or prompt == "":
83
  raise gr.Error("Prompt is required")
 
102
  width=qrcode_image.width, # type: ignore
103
  height=qrcode_image.height, # type: ignore
104
  guidance_scale=float(guidance_scale),
105
+ controlnet_conditioning_scale=float(
106
+ controlnet_conditioning_scale), # type: ignore
107
  generator=generator,
108
  num_inference_steps=40,
109
  )
110
  return out.images[0] # type: ignore
111
 
112
+
113
  css = """
114
  #result_image {
115
  display: flex;
 
127
  gr.Markdown(
128
  """
129
  # QR Code Monster v1.0
130
+ ## QR Code AI Art Generator
131
 
132
+ Model used: https://huggingface.co/monster-labs/control_v1p_sd15_qrcode_monster
 
 
 
 
133
 
134
+ Try our more powerful v2 here: https://qrcodemonster.art!
 
 
 
 
135
 
136
+ <a href="https://huggingface.co/spaces/monster-labs/Controlnet-QRCode-Monster-V1?duplicate=true" style="display: inline-block;margin-top: .5em;margin-right: .25em;" target="_blank">
137
+ <img style="margin-bottom: 0em;display: inline;margin-top: -.25em;" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a> for no queue on your own hardware.</p>
138
  """
139
  )
140
 
141
  with gr.Row():
142
  with gr.Column():
143
  qr_code_content = gr.Textbox(
144
+ label="QR Code Content or URL",
145
+ info="The text you want to encode into the QR code",
146
  value="",
147
  )
148
 
 
153
  negative_prompt = gr.Textbox(
154
  label="Negative Prompt",
155
  value="ugly, disfigured, low quality, blurry, nsfw",
156
+ info="Prompt that guides the generation away from",
157
  )
158
 
159
  with gr.Accordion(
 
166
  step=0.01,
167
  value=1.5,
168
  label="Controlnet Conditioning Scale",
169
+ info="""Controls the readability/creativity of the QR code.
170
+
171
+ High values: The generated QR code will be more readable.
172
+ Low values: The generated QR code will be more creative.
173
+ """
174
  )
175
  guidance_scale = gr.Slider(
176
  minimum=0.0,
 
178
  step=0.25,
179
  value=7,
180
  label="Guidance Scale",
181
+ info="Controls the amount of guidance the text prompt guides the image generation"
182
  )
183
+ sampler = gr.Dropdown(choices=list(
184
+ SAMPLER_MAP.keys()), value="Euler a", label="Sampler")
185
  seed = gr.Number(
186
  minimum=-1,
187
  maximum=9999999999,
 
189
  value=2313123,
190
  label="Seed",
191
  randomize=True,
192
+ info="Seed for the random number generator. Set to -1 for a random seed"
193
  )
194
  with gr.Row():
195
  run_btn = gr.Button("Run")
196
  with gr.Column():
197
+ result_image = gr.Image(
198
+ label="Result Image", elem_id="result_image")
199
  run_btn.click(
200
  inference,
201
  inputs=[
 
213
  gr.Examples(
214
  examples=[
215
  [
216
+ "https://qrcodemonster.art",
217
  "Baroque rococo architecture, architectural photography, post apocalyptic New York, hyperrealism, [roots], hyperrealistic, octane render, cinematic, hyper detailed, 8K",
218
  "",
219
  7,
 
222
  "Euler a",
223
  ],
224
  [
225
+ "https://qrcodemonster.art",
226
  "a centered render of an ancient tree covered in bio - organic micro organisms growing in a mystical setting, cinematic, beautifully lit, by tomasz alen kopera and peter mohrbacher and craig mullins, 3d, trending on artstation, octane render, 8k",
227
  "",
228
  7,
 
231
  "Euler a",
232
  ],
233
  [
234
+ "https://qrcodemonster.art",
235
  "3 cups of coffee with coffee beans around",
236
  "",
237
  7,
 
240
  "Euler a",
241
  ],
242
  [
243
+ "https://huggingface.co",
244
  "A top view picture of a sandy beach with a sand castle, beautiful lighting, 8k, highly detailed",
245
  "sky",
246
  7,
 
249
  "Euler a",
250
  ],
251
  [
252
+ "https://qrcodemonster.art",
253
  "A top view picture of a sandy beach, organic shapes, beautiful lighting, bumps and shadows, 8k, highly detailed",
254
  "sky, water, squares",
255
  7,
 
273
  )
274
  gr.Markdown(
275
  """
276
+ ## Notes
277
+
278
+ * The generated QR codes may not always be easily readable and may require adjusting the parameters.
279
+ * The prompt affects the quality of the generated QR code.
280
+ * The scan may work better if the phone is held further away from the screen.
281
+
282
  ## Parameters
283
 
284
  - **Input Text:** The text you want to encode into the QR code
 
287
 
288
  The generated QR codes might not always be easily readable. It might take a few tries with different parameters to find the right balance. This often depends on the prompt, which can be more or less suitable for QR code generation.
289
 
 
290
 
291
  ## How to Use
292
 
 
298
  """
299
  )
300
 
301
+ blocks.queue(concurrency_count=1, max_size=20, api_open=False)
302
+ blocks.launch(share=bool(os.environ.get("SHARE", False)), show_api=False)