Spaces:
Runtime error
Runtime error
lionelgarnier
commited on
Commit
·
cc9aa28
1
Parent(s):
73911dd
refactor session management and update event handlers for improved clarity and functionality
Browse files
app.py
CHANGED
@@ -430,17 +430,17 @@ def create_interface():
|
|
430 |
model_status = "ℹ️ Models will be loaded on demand"
|
431 |
|
432 |
with gr.Blocks(css=css) as demo:
|
433 |
-
# Set up session management
|
434 |
-
demo.load(start_session)
|
435 |
-
demo.unload(end_session)
|
436 |
|
437 |
gr.Info(model_status)
|
438 |
|
439 |
-
# State for storing 3D model data
|
440 |
output_state = gr.State(None)
|
441 |
|
442 |
with gr.Column(elem_id="col-container"):
|
443 |
-
gr.Markdown("# Text to Product\nUsing Mistral-7B
|
444 |
|
445 |
prompt = gr.Text(
|
446 |
show_label=False,
|
@@ -497,8 +497,8 @@ def create_interface():
|
|
497 |
|
498 |
with gr.Tab("Flux"):
|
499 |
# Flux settings
|
500 |
-
|
501 |
-
|
502 |
|
503 |
with gr.Row():
|
504 |
width = gr.Slider(label="Width", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=DEFAULT_WIDTH)
|
@@ -513,8 +513,8 @@ def create_interface():
|
|
513 |
)
|
514 |
|
515 |
with gr.Tab("3D Generation Settings"):
|
516 |
-
|
517 |
-
|
518 |
gr.Markdown("Stage 1: Sparse Structure Generation")
|
519 |
with gr.Row():
|
520 |
ss_guidance_strength = gr.Slider(0.0, 10.0, label="Guidance Strength", value=7.5, step=0.1)
|
@@ -539,38 +539,37 @@ def create_interface():
|
|
539 |
|
540 |
# Examples section - simplified version that only updates the prompt fields
|
541 |
gr.Examples(
|
542 |
-
examples=examples,
|
543 |
fn=process_example_pipeline,
|
544 |
-
inputs=[prompt],
|
545 |
-
outputs=[refined_prompt, message_box],
|
546 |
cache_examples=True,
|
547 |
)
|
548 |
|
549 |
-
# Event handlers
|
550 |
gr.on(
|
551 |
triggers=[prompt_button.click, prompt.submit],
|
552 |
fn=refine_prompt,
|
553 |
-
inputs=[prompt, system_prompt],
|
554 |
outputs=[refined_prompt, message_box]
|
555 |
)
|
556 |
|
557 |
gr.on(
|
558 |
triggers=[visual_button.click],
|
559 |
fn=infer,
|
560 |
-
inputs=[refined_prompt,
|
561 |
outputs=[generated_image, message_box]
|
562 |
)
|
563 |
|
564 |
-
# Updated to use output_state
|
565 |
gr.on(
|
566 |
triggers=[gen3d_button.click],
|
567 |
fn=image_to_3d,
|
568 |
-
inputs=[generated_image,
|
569 |
outputs=[output_state, video_output],
|
570 |
-
).
|
571 |
# Update button states after successful 3D generation
|
572 |
-
lambda: (gr.Button.update(interactive=True), gr.Button.update(interactive=True)),
|
573 |
-
outputs=[extract_glb_btn, extract_gs_btn]
|
574 |
)
|
575 |
|
576 |
# Add handlers for GLB and Gaussian extraction
|
@@ -579,10 +578,10 @@ def create_interface():
|
|
579 |
fn=extract_glb,
|
580 |
inputs=[output_state, mesh_simplify, texture_size],
|
581 |
outputs=[model_output, download_glb]
|
582 |
-
).
|
583 |
-
lambda path: gr.DownloadButton.update(interactive=True, value=path),
|
584 |
inputs=[model_output],
|
585 |
-
outputs=[download_glb]
|
586 |
)
|
587 |
|
588 |
gr.on(
|
@@ -590,10 +589,10 @@ def create_interface():
|
|
590 |
fn=extract_gaussian,
|
591 |
inputs=[output_state],
|
592 |
outputs=[model_output, download_gs]
|
593 |
-
).
|
594 |
-
lambda path: gr.DownloadButton.update(interactive=True, value=path),
|
595 |
inputs=[model_output],
|
596 |
-
outputs=[download_gs]
|
597 |
)
|
598 |
|
599 |
return demo
|
|
|
430 |
model_status = "ℹ️ Models will be loaded on demand"
|
431 |
|
432 |
with gr.Blocks(css=css) as demo:
|
433 |
+
# Set up session management - COMMENT THESE OUT FOR TESTING
|
434 |
+
# demo.load(start_session)
|
435 |
+
# demo.unload(end_session)
|
436 |
|
437 |
gr.Info(model_status)
|
438 |
|
439 |
+
# State for storing 3D model data
|
440 |
output_state = gr.State(None)
|
441 |
|
442 |
with gr.Column(elem_id="col-container"):
|
443 |
+
gr.Markdown("# Text to Product\nUsing Mistral-7B + FLUX.1-dev + Trellis")
|
444 |
|
445 |
prompt = gr.Text(
|
446 |
show_label=False,
|
|
|
497 |
|
498 |
with gr.Tab("Flux"):
|
499 |
# Flux settings
|
500 |
+
flux_seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=DEFAULT_SEED)
|
501 |
+
flux_randomize_seed = gr.Checkbox(label="Randomize seed", value=DEFAULT_RANDOMIZE_SEED)
|
502 |
|
503 |
with gr.Row():
|
504 |
width = gr.Slider(label="Width", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=DEFAULT_WIDTH)
|
|
|
513 |
)
|
514 |
|
515 |
with gr.Tab("3D Generation Settings"):
|
516 |
+
trellis_seed = gr.Slider(0, MAX_SEED, label="Seed", value=0, step=1)
|
517 |
+
trellis_randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
|
518 |
gr.Markdown("Stage 1: Sparse Structure Generation")
|
519 |
with gr.Row():
|
520 |
ss_guidance_strength = gr.Slider(0.0, 10.0, label="Guidance Strength", value=7.5, step=0.1)
|
|
|
539 |
|
540 |
# Examples section - simplified version that only updates the prompt fields
|
541 |
gr.Examples(
|
542 |
+
examples=examples,
|
543 |
fn=process_example_pipeline,
|
544 |
+
inputs=[prompt],
|
545 |
+
outputs=[refined_prompt, message_box],
|
546 |
cache_examples=True,
|
547 |
)
|
548 |
|
549 |
+
# Event handlers - Fixed to use the renamed components
|
550 |
gr.on(
|
551 |
triggers=[prompt_button.click, prompt.submit],
|
552 |
fn=refine_prompt,
|
553 |
+
inputs=[prompt, system_prompt],
|
554 |
outputs=[refined_prompt, message_box]
|
555 |
)
|
556 |
|
557 |
gr.on(
|
558 |
triggers=[visual_button.click],
|
559 |
fn=infer,
|
560 |
+
inputs=[refined_prompt, flux_seed, flux_randomize_seed, width, height, num_inference_steps],
|
561 |
outputs=[generated_image, message_box]
|
562 |
)
|
563 |
|
|
|
564 |
gr.on(
|
565 |
triggers=[gen3d_button.click],
|
566 |
fn=image_to_3d,
|
567 |
+
inputs=[generated_image, trellis_seed, ss_guidance_strength, ss_sampling_steps, slat_guidance_strength, slat_sampling_steps],
|
568 |
outputs=[output_state, video_output],
|
569 |
+
).then(
|
570 |
# Update button states after successful 3D generation
|
571 |
+
lambda: (gr.Button.update(interactive=True), gr.Button.update(interactive=True), "3D model generated successfully"),
|
572 |
+
outputs=[extract_glb_btn, extract_gs_btn, message_box]
|
573 |
)
|
574 |
|
575 |
# Add handlers for GLB and Gaussian extraction
|
|
|
578 |
fn=extract_glb,
|
579 |
inputs=[output_state, mesh_simplify, texture_size],
|
580 |
outputs=[model_output, download_glb]
|
581 |
+
).then(
|
582 |
+
lambda path: (gr.DownloadButton.update(interactive=True, value=path), "GLB extraction completed"),
|
583 |
inputs=[model_output],
|
584 |
+
outputs=[download_glb, message_box]
|
585 |
)
|
586 |
|
587 |
gr.on(
|
|
|
589 |
fn=extract_gaussian,
|
590 |
inputs=[output_state],
|
591 |
outputs=[model_output, download_gs]
|
592 |
+
).then(
|
593 |
+
lambda path: (gr.DownloadButton.update(interactive=True, value=path), "Gaussian extraction completed"),
|
594 |
inputs=[model_output],
|
595 |
+
outputs=[download_gs, message_box]
|
596 |
)
|
597 |
|
598 |
return demo
|