Spaces:
Running
on
Zero
Running
on
Zero
Allow raw input of QR code text to enable VCARD, calendar etc.
Browse files
app.py
CHANGED
|
@@ -160,11 +160,14 @@ valid_models = [
|
|
| 160 |
model_management.load_models_gpu(valid_models)
|
| 161 |
|
| 162 |
@spaces.GPU(duration=20)
|
| 163 |
-
def generate_qr_code(prompt: str,
|
| 164 |
-
if
|
| 165 |
-
|
| 166 |
-
if "
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
with torch.inference_mode():
|
| 170 |
|
|
@@ -192,7 +195,7 @@ def generate_qr_code(prompt: str, url: str):
|
|
| 192 |
|
| 193 |
comfy_qr_by_module_size_15 = comfy_qr_by_module_size.generate_qr(
|
| 194 |
protocol="Https",
|
| 195 |
-
text=
|
| 196 |
module_size=12,
|
| 197 |
max_image_size=512,
|
| 198 |
fill_hexcolor="#000000",
|
|
@@ -320,21 +323,31 @@ if __name__ == "__main__":
|
|
| 320 |
### Tips:
|
| 321 |
- Use detailed prompts for better results
|
| 322 |
- Include style keywords like 'photorealistic', 'detailed', '8k'
|
|
|
|
| 323 |
- Try the examples below for inspiration
|
| 324 |
""")
|
| 325 |
|
| 326 |
with gr.Row():
|
| 327 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
# Add inputs
|
| 329 |
prompt_input = gr.Textbox(
|
| 330 |
label="Prompt",
|
| 331 |
placeholder="Describe the image you want to generate (check examples below for inspiration)",
|
| 332 |
value="Enter your prompt here... For example: 'a beautiful sunset over mountains, photorealistic, detailed landscape'"
|
| 333 |
)
|
| 334 |
-
|
| 335 |
-
label="
|
| 336 |
-
placeholder="Enter
|
| 337 |
-
value="Enter your URL here... For example: https://github.com"
|
|
|
|
| 338 |
)
|
| 339 |
# The generate button
|
| 340 |
generate_btn = gr.Button("Generate")
|
|
@@ -346,7 +359,7 @@ if __name__ == "__main__":
|
|
| 346 |
# When clicking the button, it will trigger the main function
|
| 347 |
generate_btn.click(
|
| 348 |
fn=generate_qr_code,
|
| 349 |
-
inputs=[prompt_input,
|
| 350 |
outputs=[output_image]
|
| 351 |
)
|
| 352 |
|
|
@@ -354,33 +367,59 @@ if __name__ == "__main__":
|
|
| 354 |
examples = [
|
| 355 |
[
|
| 356 |
"some clothes spread on ropes, realistic, great details, out in the open air sunny day realistic, great details,absence of people, Detailed and Intricate, CGI, Photoshoot,rim light, 8k, 16k, ultra detail",
|
| 357 |
-
"https://www.google.com"
|
|
|
|
| 358 |
],
|
| 359 |
[
|
| 360 |
"some cards on poker tale, realistic, great details, realistic, great details,absence of people, Detailed and Intricate, CGI, Photoshoot,rim light, 8k, 16k, ultra detail",
|
| 361 |
-
"https://store.steampowered.com"
|
|
|
|
| 362 |
],
|
| 363 |
[
|
| 364 |
"a beautiful sunset over mountains, photorealistic, detailed landscape, golden hour, dramatic lighting, 8k, ultra detailed",
|
| 365 |
-
"https://github.com"
|
|
|
|
| 366 |
],
|
| 367 |
[
|
| 368 |
"underwater scene with coral reef and tropical fish, photorealistic, detailed, crystal clear water, sunlight rays, 8k, ultra detailed",
|
| 369 |
-
"https://twitter.com"
|
|
|
|
| 370 |
],
|
| 371 |
[
|
| 372 |
"futuristic cityscape with flying cars and neon lights, cyberpunk style, detailed architecture, night scene, 8k, ultra detailed",
|
| 373 |
-
"https://linkedin.com"
|
|
|
|
| 374 |
],
|
| 375 |
[
|
| 376 |
"vintage camera on wooden table, photorealistic, detailed textures, soft lighting, bokeh background, 8k, ultra detailed",
|
| 377 |
-
"https://instagram.com"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
]
|
| 379 |
]
|
| 380 |
|
| 381 |
gr.Examples(
|
| 382 |
examples=examples,
|
| 383 |
-
inputs=[prompt_input,
|
| 384 |
outputs=[output_image],
|
| 385 |
fn=generate_qr_code,
|
| 386 |
cache_examples=True
|
|
|
|
| 160 |
model_management.load_models_gpu(valid_models)
|
| 161 |
|
| 162 |
@spaces.GPU(duration=20)
|
| 163 |
+
def generate_qr_code(prompt: str, text_input: str, input_type: str = "URL"):
|
| 164 |
+
# Only manipulate the text if it's a URL input type
|
| 165 |
+
qr_text = text_input
|
| 166 |
+
if input_type == "URL":
|
| 167 |
+
if "https://" in qr_text:
|
| 168 |
+
qr_text = qr_text.replace("https://", "")
|
| 169 |
+
if "http://" in qr_text:
|
| 170 |
+
qr_text = qr_text.replace("http://", "")
|
| 171 |
|
| 172 |
with torch.inference_mode():
|
| 173 |
|
|
|
|
| 195 |
|
| 196 |
comfy_qr_by_module_size_15 = comfy_qr_by_module_size.generate_qr(
|
| 197 |
protocol="Https",
|
| 198 |
+
text=qr_text,
|
| 199 |
module_size=12,
|
| 200 |
max_image_size=512,
|
| 201 |
fill_hexcolor="#000000",
|
|
|
|
| 323 |
### Tips:
|
| 324 |
- Use detailed prompts for better results
|
| 325 |
- Include style keywords like 'photorealistic', 'detailed', '8k'
|
| 326 |
+
- Choose **URL** mode for web links or **Plain Text** mode for VCARD, WiFi credentials, calendar events, etc.
|
| 327 |
- Try the examples below for inspiration
|
| 328 |
""")
|
| 329 |
|
| 330 |
with gr.Row():
|
| 331 |
with gr.Column():
|
| 332 |
+
# Add input type selector
|
| 333 |
+
input_type = gr.Radio(
|
| 334 |
+
choices=["URL", "Plain Text"],
|
| 335 |
+
value="URL",
|
| 336 |
+
label="Input Type",
|
| 337 |
+
info="URL: For web links (auto-removes https://). Plain Text: For VCARD, WiFi, calendar, location, etc. (no manipulation)"
|
| 338 |
+
)
|
| 339 |
+
|
| 340 |
# Add inputs
|
| 341 |
prompt_input = gr.Textbox(
|
| 342 |
label="Prompt",
|
| 343 |
placeholder="Describe the image you want to generate (check examples below for inspiration)",
|
| 344 |
value="Enter your prompt here... For example: 'a beautiful sunset over mountains, photorealistic, detailed landscape'"
|
| 345 |
)
|
| 346 |
+
text_input = gr.Textbox(
|
| 347 |
+
label="QR Code Content",
|
| 348 |
+
placeholder="Enter URL or plain text",
|
| 349 |
+
value="Enter your URL or text here... For example: https://github.com",
|
| 350 |
+
lines=3
|
| 351 |
)
|
| 352 |
# The generate button
|
| 353 |
generate_btn = gr.Button("Generate")
|
|
|
|
| 359 |
# When clicking the button, it will trigger the main function
|
| 360 |
generate_btn.click(
|
| 361 |
fn=generate_qr_code,
|
| 362 |
+
inputs=[prompt_input, text_input, input_type],
|
| 363 |
outputs=[output_image]
|
| 364 |
)
|
| 365 |
|
|
|
|
| 367 |
examples = [
|
| 368 |
[
|
| 369 |
"some clothes spread on ropes, realistic, great details, out in the open air sunny day realistic, great details,absence of people, Detailed and Intricate, CGI, Photoshoot,rim light, 8k, 16k, ultra detail",
|
| 370 |
+
"https://www.google.com",
|
| 371 |
+
"URL"
|
| 372 |
],
|
| 373 |
[
|
| 374 |
"some cards on poker tale, realistic, great details, realistic, great details,absence of people, Detailed and Intricate, CGI, Photoshoot,rim light, 8k, 16k, ultra detail",
|
| 375 |
+
"https://store.steampowered.com",
|
| 376 |
+
"URL"
|
| 377 |
],
|
| 378 |
[
|
| 379 |
"a beautiful sunset over mountains, photorealistic, detailed landscape, golden hour, dramatic lighting, 8k, ultra detailed",
|
| 380 |
+
"https://github.com",
|
| 381 |
+
"URL"
|
| 382 |
],
|
| 383 |
[
|
| 384 |
"underwater scene with coral reef and tropical fish, photorealistic, detailed, crystal clear water, sunlight rays, 8k, ultra detailed",
|
| 385 |
+
"https://twitter.com",
|
| 386 |
+
"URL"
|
| 387 |
],
|
| 388 |
[
|
| 389 |
"futuristic cityscape with flying cars and neon lights, cyberpunk style, detailed architecture, night scene, 8k, ultra detailed",
|
| 390 |
+
"https://linkedin.com",
|
| 391 |
+
"URL"
|
| 392 |
],
|
| 393 |
[
|
| 394 |
"vintage camera on wooden table, photorealistic, detailed textures, soft lighting, bokeh background, 8k, ultra detailed",
|
| 395 |
+
"https://instagram.com",
|
| 396 |
+
"URL"
|
| 397 |
+
],
|
| 398 |
+
[
|
| 399 |
+
"business card design, professional, modern, clean layout, corporate style, detailed, 8k, ultra detailed",
|
| 400 |
+
"BEGIN:VCARD\nVERSION:3.0\nFN:John Doe\nORG:Acme Corporation\nTITLE:Software Engineer\nTEL:+1-555-123-4567\nEMAIL:[email protected]\nEND:VCARD",
|
| 401 |
+
"Plain Text"
|
| 402 |
+
],
|
| 403 |
+
[
|
| 404 |
+
"wifi network symbol, modern tech, digital art, glowing blue, detailed, 8k, ultra detailed",
|
| 405 |
+
"WIFI:T:WPA;S:MyNetwork;P:MyPassword123;;",
|
| 406 |
+
"Plain Text"
|
| 407 |
+
],
|
| 408 |
+
[
|
| 409 |
+
"calendar appointment reminder, organized planner, professional office, detailed, 8k, ultra detailed",
|
| 410 |
+
"BEGIN:VEVENT\nSUMMARY:Team Meeting\nDTSTART:20251115T140000Z\nDTEND:20251115T150000Z\nLOCATION:Conference Room A\nEND:VEVENT",
|
| 411 |
+
"Plain Text"
|
| 412 |
+
],
|
| 413 |
+
[
|
| 414 |
+
"location pin on map, travel destination, scenic view, detailed cartography, 8k, ultra detailed",
|
| 415 |
+
"geo:37.7749,-122.4194",
|
| 416 |
+
"Plain Text"
|
| 417 |
]
|
| 418 |
]
|
| 419 |
|
| 420 |
gr.Examples(
|
| 421 |
examples=examples,
|
| 422 |
+
inputs=[prompt_input, text_input, input_type],
|
| 423 |
outputs=[output_image],
|
| 424 |
fn=generate_qr_code,
|
| 425 |
cache_examples=True
|