Spaces:
Running on Zero
Running on Zero
Update demo_release.py
#1
by EasonXiao-888 - opened
- demo_release.py +72 -15
demo_release.py
CHANGED
|
@@ -365,8 +365,6 @@ def box_selector_html() -> str:
|
|
| 365 |
"""
|
| 366 |
|
| 367 |
|
| 368 |
-
|
| 369 |
-
|
| 370 |
CAMERA_EXAMPLE_SAMPLES = [
|
| 371 |
{
|
| 372 |
"image": "images/example_1.jpg",
|
|
@@ -495,6 +493,52 @@ def pil_to_data_url(image: Image.Image) -> str:
|
|
| 495 |
img_str = base64.b64encode(buf.getvalue()).decode()
|
| 496 |
return f"data:image/png;base64,{img_str}"
|
| 497 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
def _build_conversation_instruction(y_rot: float, x_rot: float, d_delta: int, rng: random.Random) -> str:
|
| 499 |
instr = natural_template_rot_only.format(x_rot=x_rot, y_rot=y_rot)
|
| 500 |
if d_delta < 0:
|
|
@@ -2723,7 +2767,7 @@ def create_demo(
|
|
| 2723 |
if pil_image is None:
|
| 2724 |
return (
|
| 2725 |
None,
|
| 2726 |
-
None,
|
| 2727 |
gr.update(value=default_camera_value(), imageUrl=None),
|
| 2728 |
0.0,
|
| 2729 |
0.0,
|
|
@@ -2734,7 +2778,7 @@ def create_demo(
|
|
| 2734 |
data_url = selector_source_data_url(pil_image)
|
| 2735 |
return (
|
| 2736 |
pil_image,
|
| 2737 |
-
pil_image,
|
| 2738 |
gr.update(value=default_camera_value(), imageUrl=data_url),
|
| 2739 |
0.0,
|
| 2740 |
0.0,
|
|
@@ -2752,7 +2796,7 @@ def create_demo(
|
|
| 2752 |
def reset_camera_upload():
|
| 2753 |
return (
|
| 2754 |
None,
|
| 2755 |
-
None,
|
| 2756 |
gr.update(value=default_camera_value(), imageUrl=None),
|
| 2757 |
0.0,
|
| 2758 |
0.0,
|
|
@@ -2769,7 +2813,7 @@ def create_demo(
|
|
| 2769 |
if idx < 0 or idx >= len(examples_full):
|
| 2770 |
return (
|
| 2771 |
None,
|
| 2772 |
-
None,
|
| 2773 |
gr.update(value=default_camera_value(), imageUrl=None),
|
| 2774 |
0.0,
|
| 2775 |
0.0,
|
|
@@ -2782,7 +2826,7 @@ def create_demo(
|
|
| 2782 |
if pil_image is None:
|
| 2783 |
return (
|
| 2784 |
None,
|
| 2785 |
-
None,
|
| 2786 |
gr.update(value=default_camera_value(), imageUrl=None),
|
| 2787 |
0.0,
|
| 2788 |
0.0,
|
|
@@ -2797,7 +2841,7 @@ def create_demo(
|
|
| 2797 |
data_url = selector_source_data_url(pil_image)
|
| 2798 |
return (
|
| 2799 |
pil_image,
|
| 2800 |
-
pil_image,
|
| 2801 |
gr.update(value={"yaw": yaw, "pitch": pitch, "zoom_delta": zoom_delta}, imageUrl=data_url),
|
| 2802 |
yaw,
|
| 2803 |
pitch,
|
|
@@ -3001,11 +3045,9 @@ def create_demo(
|
|
| 3001 |
elem_id="se_upload_image_camera_file",
|
| 3002 |
)
|
| 3003 |
camera_clear_btn = gr.Button("Clear Input", size="sm")
|
| 3004 |
-
|
| 3005 |
-
|
| 3006 |
-
|
| 3007 |
-
interactive=False,
|
| 3008 |
-
height=320,
|
| 3009 |
elem_id="se_upload_image_camera_preview",
|
| 3010 |
)
|
| 3011 |
camera_prompt_box = gr.Textbox(
|
|
@@ -3042,7 +3084,23 @@ def create_demo(
|
|
| 3042 |
)
|
| 3043 |
|
| 3044 |
if examples_full:
|
| 3045 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3046 |
with gr.Row():
|
| 3047 |
for idx, example_item in enumerate(examples_full):
|
| 3048 |
example_name = Path(str(example_item[0])).name
|
|
@@ -3051,7 +3109,6 @@ def create_demo(
|
|
| 3051 |
fn=lambda i=idx: load_camera_example_by_index(i),
|
| 3052 |
inputs=None,
|
| 3053 |
outputs=[camera_original_image_state, camera_input_preview, camera_3d, yaw_slider, pitch_slider, zoom_slider, display_line, camera_prompt_box],
|
| 3054 |
-
queue=False,
|
| 3055 |
)
|
| 3056 |
|
| 3057 |
camera_prompt_box.render()
|
|
|
|
| 365 |
"""
|
| 366 |
|
| 367 |
|
|
|
|
|
|
|
| 368 |
CAMERA_EXAMPLE_SAMPLES = [
|
| 369 |
{
|
| 370 |
"image": "images/example_1.jpg",
|
|
|
|
| 493 |
img_str = base64.b64encode(buf.getvalue()).decode()
|
| 494 |
return f"data:image/png;base64,{img_str}"
|
| 495 |
|
| 496 |
+
def build_camera_preview_html(image: Optional[Image.Image]) -> str:
|
| 497 |
+
if image is None:
|
| 498 |
+
return """
|
| 499 |
+
<div style="
|
| 500 |
+
width: 100%;
|
| 501 |
+
height: 320px;
|
| 502 |
+
display: flex;
|
| 503 |
+
align-items: center;
|
| 504 |
+
justify-content: center;
|
| 505 |
+
border: 1px solid #d8e1ee;
|
| 506 |
+
border-radius: 12px;
|
| 507 |
+
background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
|
| 508 |
+
color: #64748b;
|
| 509 |
+
font-size: 14px;
|
| 510 |
+
">
|
| 511 |
+
Input image preview will appear here.
|
| 512 |
+
</div>
|
| 513 |
+
"""
|
| 514 |
+
data_url = pil_to_data_url(image)
|
| 515 |
+
return f"""
|
| 516 |
+
<div style="
|
| 517 |
+
width: 100%;
|
| 518 |
+
height: 320px;
|
| 519 |
+
display: flex;
|
| 520 |
+
align-items: center;
|
| 521 |
+
justify-content: center;
|
| 522 |
+
border: 1px solid #d8e1ee;
|
| 523 |
+
border-radius: 12px;
|
| 524 |
+
background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
|
| 525 |
+
overflow: hidden;
|
| 526 |
+
">
|
| 527 |
+
<img
|
| 528 |
+
src="{data_url}"
|
| 529 |
+
alt="Input preview"
|
| 530 |
+
style="
|
| 531 |
+
max-width: 100%;
|
| 532 |
+
max-height: 100%;
|
| 533 |
+
width: auto;
|
| 534 |
+
height: auto;
|
| 535 |
+
object-fit: contain;
|
| 536 |
+
display: block;
|
| 537 |
+
"
|
| 538 |
+
/>
|
| 539 |
+
</div>
|
| 540 |
+
"""
|
| 541 |
+
|
| 542 |
def _build_conversation_instruction(y_rot: float, x_rot: float, d_delta: int, rng: random.Random) -> str:
|
| 543 |
instr = natural_template_rot_only.format(x_rot=x_rot, y_rot=y_rot)
|
| 544 |
if d_delta < 0:
|
|
|
|
| 2767 |
if pil_image is None:
|
| 2768 |
return (
|
| 2769 |
None,
|
| 2770 |
+
build_camera_preview_html(None),
|
| 2771 |
gr.update(value=default_camera_value(), imageUrl=None),
|
| 2772 |
0.0,
|
| 2773 |
0.0,
|
|
|
|
| 2778 |
data_url = selector_source_data_url(pil_image)
|
| 2779 |
return (
|
| 2780 |
pil_image,
|
| 2781 |
+
build_camera_preview_html(pil_image),
|
| 2782 |
gr.update(value=default_camera_value(), imageUrl=data_url),
|
| 2783 |
0.0,
|
| 2784 |
0.0,
|
|
|
|
| 2796 |
def reset_camera_upload():
|
| 2797 |
return (
|
| 2798 |
None,
|
| 2799 |
+
build_camera_preview_html(None),
|
| 2800 |
gr.update(value=default_camera_value(), imageUrl=None),
|
| 2801 |
0.0,
|
| 2802 |
0.0,
|
|
|
|
| 2813 |
if idx < 0 or idx >= len(examples_full):
|
| 2814 |
return (
|
| 2815 |
None,
|
| 2816 |
+
build_camera_preview_html(None),
|
| 2817 |
gr.update(value=default_camera_value(), imageUrl=None),
|
| 2818 |
0.0,
|
| 2819 |
0.0,
|
|
|
|
| 2826 |
if pil_image is None:
|
| 2827 |
return (
|
| 2828 |
None,
|
| 2829 |
+
build_camera_preview_html(None),
|
| 2830 |
gr.update(value=default_camera_value(), imageUrl=None),
|
| 2831 |
0.0,
|
| 2832 |
0.0,
|
|
|
|
| 2841 |
data_url = selector_source_data_url(pil_image)
|
| 2842 |
return (
|
| 2843 |
pil_image,
|
| 2844 |
+
build_camera_preview_html(pil_image),
|
| 2845 |
gr.update(value={"yaw": yaw, "pitch": pitch, "zoom_delta": zoom_delta}, imageUrl=data_url),
|
| 2846 |
yaw,
|
| 2847 |
pitch,
|
|
|
|
| 3045 |
elem_id="se_upload_image_camera_file",
|
| 3046 |
)
|
| 3047 |
camera_clear_btn = gr.Button("Clear Input", size="sm")
|
| 3048 |
+
gr.Markdown("### Input Image")
|
| 3049 |
+
camera_input_preview = gr.HTML(
|
| 3050 |
+
value=build_camera_preview_html(None),
|
|
|
|
|
|
|
| 3051 |
elem_id="se_upload_image_camera_preview",
|
| 3052 |
)
|
| 3053 |
camera_prompt_box = gr.Textbox(
|
|
|
|
| 3084 |
)
|
| 3085 |
|
| 3086 |
if examples_full:
|
| 3087 |
+
gr.HTML(
|
| 3088 |
+
"""
|
| 3089 |
+
<div style="
|
| 3090 |
+
display:flex;
|
| 3091 |
+
align-items:center;
|
| 3092 |
+
gap:10px;
|
| 3093 |
+
margin: 6px 0 10px 0;
|
| 3094 |
+
font-size: 1.25rem;
|
| 3095 |
+
font-weight: 700;
|
| 3096 |
+
line-height: 1.2;
|
| 3097 |
+
color: var(--body-text-color);
|
| 3098 |
+
">
|
| 3099 |
+
<span style="font-size: 1.05em; line-height: 1;">🖼️</span>
|
| 3100 |
+
<span>Camera Control Examples</span>
|
| 3101 |
+
</div>
|
| 3102 |
+
"""
|
| 3103 |
+
)
|
| 3104 |
with gr.Row():
|
| 3105 |
for idx, example_item in enumerate(examples_full):
|
| 3106 |
example_name = Path(str(example_item[0])).name
|
|
|
|
| 3109 |
fn=lambda i=idx: load_camera_example_by_index(i),
|
| 3110 |
inputs=None,
|
| 3111 |
outputs=[camera_original_image_state, camera_input_preview, camera_3d, yaw_slider, pitch_slider, zoom_slider, display_line, camera_prompt_box],
|
|
|
|
| 3112 |
)
|
| 3113 |
|
| 3114 |
camera_prompt_box.render()
|