Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -329,9 +329,9 @@ def create_gradio_app():
|
|
| 329 |
|
| 330 |
use_predefined = gr.Checkbox(
|
| 331 |
label="Use Predefined Shape",
|
| 332 |
-
value=True
|
| 333 |
-
info="Check to use predefined shapes, uncheck to upload your own image"
|
| 334 |
)
|
|
|
|
| 335 |
|
| 336 |
with gr.Group(visible=True) as predefined_group:
|
| 337 |
shape_type = gr.Radio(
|
|
@@ -343,9 +343,9 @@ def create_gradio_app():
|
|
| 343 |
with gr.Group(visible=False) as upload_group:
|
| 344 |
input_image = gr.Image(
|
| 345 |
label="Upload Image",
|
| 346 |
-
type="pil"
|
| 347 |
-
info="Upload PNG, JPG, or other image formats"
|
| 348 |
)
|
|
|
|
| 349 |
|
| 350 |
gr.HTML("<h3>βοΈ Configuration</h3>")
|
| 351 |
|
|
@@ -354,18 +354,18 @@ def create_gradio_app():
|
|
| 354 |
maximum=1000,
|
| 355 |
value=400,
|
| 356 |
step=50,
|
| 357 |
-
label="Number of Nails"
|
| 358 |
-
info="More nails = more detail but slower processing"
|
| 359 |
)
|
|
|
|
| 360 |
|
| 361 |
max_lines = gr.Slider(
|
| 362 |
minimum=1000,
|
| 363 |
maximum=5000,
|
| 364 |
value=3000,
|
| 365 |
step=250,
|
| 366 |
-
label="Maximum Lines"
|
| 367 |
-
info="More lines = denser result"
|
| 368 |
)
|
|
|
|
| 369 |
|
| 370 |
gr.HTML("<h3>π¨ Appearance</h3>")
|
| 371 |
|
|
@@ -389,18 +389,18 @@ def create_gradio_app():
|
|
| 389 |
maximum=200,
|
| 390 |
value=128,
|
| 391 |
step=10,
|
| 392 |
-
label="Threshold"
|
| 393 |
-
info="Lower = more detail, Higher = simpler shapes"
|
| 394 |
)
|
|
|
|
| 395 |
|
| 396 |
blur_kernel = gr.Slider(
|
| 397 |
minimum=1,
|
| 398 |
maximum=15,
|
| 399 |
value=5,
|
| 400 |
step=2,
|
| 401 |
-
label="Blur Amount"
|
| 402 |
-
info="Smooths the image before processing"
|
| 403 |
)
|
|
|
|
| 404 |
|
| 405 |
generate_btn = gr.Button(
|
| 406 |
"π Generate String Art",
|
|
@@ -433,24 +433,19 @@ def create_gradio_app():
|
|
| 433 |
gr.HTML("<h3>π₯ Downloads</h3>")
|
| 434 |
|
| 435 |
with gr.Row():
|
| 436 |
-
instructions_download = gr.File(
|
| 437 |
-
label="Threading Instructions (.txt)",
|
| 438 |
-
visible=False
|
| 439 |
-
)
|
| 440 |
-
|
| 441 |
instructions_text = gr.Textbox(
|
| 442 |
label="Threading Instructions",
|
| 443 |
lines=10,
|
| 444 |
max_lines=20,
|
| 445 |
-
placeholder="Instructions will appear here after generation..."
|
| 446 |
-
info="Copy these step-by-step instructions for physical crafting"
|
| 447 |
)
|
|
|
|
| 448 |
|
| 449 |
# Toggle visibility based on predefined checkbox
|
| 450 |
def toggle_input_method(use_pred):
|
| 451 |
return {
|
| 452 |
-
predefined_group: gr.
|
| 453 |
-
upload_group: gr.
|
| 454 |
}
|
| 455 |
|
| 456 |
use_predefined.change(
|
|
@@ -460,28 +455,21 @@ def create_gradio_app():
|
|
| 460 |
)
|
| 461 |
|
| 462 |
# Generate button click handler
|
| 463 |
-
def
|
| 464 |
result_img, processed_img, info, instructions = generate_string_art_interface(
|
| 465 |
image, shape, use_pred, nails, lines, thresh, blur, color, opacity
|
| 466 |
)
|
| 467 |
|
| 468 |
-
|
| 469 |
-
if instructions:
|
| 470 |
-
instructions_file = io.StringIO(instructions)
|
| 471 |
-
instructions_bytes = io.BytesIO(instructions.encode('utf-8'))
|
| 472 |
-
return result_img, processed_img, info, instructions, instructions_bytes
|
| 473 |
-
|
| 474 |
-
return result_img, processed_img, info, instructions, None
|
| 475 |
|
| 476 |
generate_btn.click(
|
| 477 |
-
|
| 478 |
inputs=[
|
| 479 |
input_image, shape_type, use_predefined, num_nails, max_lines,
|
| 480 |
threshold, blur_kernel, thread_color, line_opacity
|
| 481 |
],
|
| 482 |
outputs=[
|
| 483 |
-
result_output, processed_output, info_output,
|
| 484 |
-
instructions_text, instructions_download
|
| 485 |
]
|
| 486 |
)
|
| 487 |
|
|
@@ -499,10 +487,9 @@ def create_gradio_app():
|
|
| 499 |
threshold, blur_kernel, thread_color, line_opacity
|
| 500 |
],
|
| 501 |
outputs=[
|
| 502 |
-
result_output, processed_output, info_output,
|
| 503 |
-
instructions_text, instructions_download
|
| 504 |
],
|
| 505 |
-
fn=
|
| 506 |
cache_examples=False
|
| 507 |
)
|
| 508 |
|
|
|
|
| 329 |
|
| 330 |
use_predefined = gr.Checkbox(
|
| 331 |
label="Use Predefined Shape",
|
| 332 |
+
value=True
|
|
|
|
| 333 |
)
|
| 334 |
+
gr.HTML("<small>Check to use predefined shapes, uncheck to upload your own image</small>")
|
| 335 |
|
| 336 |
with gr.Group(visible=True) as predefined_group:
|
| 337 |
shape_type = gr.Radio(
|
|
|
|
| 343 |
with gr.Group(visible=False) as upload_group:
|
| 344 |
input_image = gr.Image(
|
| 345 |
label="Upload Image",
|
| 346 |
+
type="pil"
|
|
|
|
| 347 |
)
|
| 348 |
+
gr.HTML("<small>Upload PNG, JPG, or other image formats</small>")
|
| 349 |
|
| 350 |
gr.HTML("<h3>βοΈ Configuration</h3>")
|
| 351 |
|
|
|
|
| 354 |
maximum=1000,
|
| 355 |
value=400,
|
| 356 |
step=50,
|
| 357 |
+
label="Number of Nails"
|
|
|
|
| 358 |
)
|
| 359 |
+
gr.HTML("<small>More nails = more detail but slower processing</small>")
|
| 360 |
|
| 361 |
max_lines = gr.Slider(
|
| 362 |
minimum=1000,
|
| 363 |
maximum=5000,
|
| 364 |
value=3000,
|
| 365 |
step=250,
|
| 366 |
+
label="Maximum Lines"
|
|
|
|
| 367 |
)
|
| 368 |
+
gr.HTML("<small>More lines = denser result</small>")
|
| 369 |
|
| 370 |
gr.HTML("<h3>π¨ Appearance</h3>")
|
| 371 |
|
|
|
|
| 389 |
maximum=200,
|
| 390 |
value=128,
|
| 391 |
step=10,
|
| 392 |
+
label="Threshold"
|
|
|
|
| 393 |
)
|
| 394 |
+
gr.HTML("<small>Lower = more detail, Higher = simpler shapes</small>")
|
| 395 |
|
| 396 |
blur_kernel = gr.Slider(
|
| 397 |
minimum=1,
|
| 398 |
maximum=15,
|
| 399 |
value=5,
|
| 400 |
step=2,
|
| 401 |
+
label="Blur Amount"
|
|
|
|
| 402 |
)
|
| 403 |
+
gr.HTML("<small>Smooths the image before processing</small>")
|
| 404 |
|
| 405 |
generate_btn = gr.Button(
|
| 406 |
"π Generate String Art",
|
|
|
|
| 433 |
gr.HTML("<h3>π₯ Downloads</h3>")
|
| 434 |
|
| 435 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 436 |
instructions_text = gr.Textbox(
|
| 437 |
label="Threading Instructions",
|
| 438 |
lines=10,
|
| 439 |
max_lines=20,
|
| 440 |
+
placeholder="Instructions will appear here after generation..."
|
|
|
|
| 441 |
)
|
| 442 |
+
gr.HTML("<small>Copy these step-by-step instructions for physical crafting</small>")
|
| 443 |
|
| 444 |
# Toggle visibility based on predefined checkbox
|
| 445 |
def toggle_input_method(use_pred):
|
| 446 |
return {
|
| 447 |
+
predefined_group: gr.update(visible=use_pred),
|
| 448 |
+
upload_group: gr.update(visible=not use_pred)
|
| 449 |
}
|
| 450 |
|
| 451 |
use_predefined.change(
|
|
|
|
| 455 |
)
|
| 456 |
|
| 457 |
# Generate button click handler
|
| 458 |
+
def generate_handler(image, shape, use_pred, nails, lines, thresh, blur, color, opacity):
|
| 459 |
result_img, processed_img, info, instructions = generate_string_art_interface(
|
| 460 |
image, shape, use_pred, nails, lines, thresh, blur, color, opacity
|
| 461 |
)
|
| 462 |
|
| 463 |
+
return result_img, processed_img, info, instructions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 464 |
|
| 465 |
generate_btn.click(
|
| 466 |
+
generate_handler,
|
| 467 |
inputs=[
|
| 468 |
input_image, shape_type, use_predefined, num_nails, max_lines,
|
| 469 |
threshold, blur_kernel, thread_color, line_opacity
|
| 470 |
],
|
| 471 |
outputs=[
|
| 472 |
+
result_output, processed_output, info_output, instructions_text
|
|
|
|
| 473 |
]
|
| 474 |
)
|
| 475 |
|
|
|
|
| 487 |
threshold, blur_kernel, thread_color, line_opacity
|
| 488 |
],
|
| 489 |
outputs=[
|
| 490 |
+
result_output, processed_output, info_output, instructions_text
|
|
|
|
| 491 |
],
|
| 492 |
+
fn=generate_handler,
|
| 493 |
cache_examples=False
|
| 494 |
)
|
| 495 |
|