Commit ·
24a6a61
1
Parent(s): ae4da09
still initial commit
Browse files
app.py
CHANGED
|
@@ -74,77 +74,73 @@ def process_demo_stream(frame: np.ndarray) -> np.ndarray:
|
|
| 74 |
return np.hstack([raw_labeled, processed])
|
| 75 |
|
| 76 |
|
| 77 |
-
# ── CSS:
|
|
|
|
| 78 |
css = """
|
| 79 |
-
|
| 80 |
-
|
|
|
|
| 81 |
"""
|
| 82 |
|
|
|
|
|
|
|
|
|
|
| 83 |
# ── UI ───────────────────────────────────────────────────────────────────────
|
| 84 |
with gr.Blocks(title="Minecraft Spatial Voxel Filter", css=css) as demo:
|
| 85 |
|
| 86 |
gr.HTML("""
|
| 87 |
-
<div style='
|
| 88 |
-
<
|
| 89 |
-
|
| 90 |
-
<p style='margin: 4px 0 0 0; text-align: center'>
|
| 91 |
-
Transform your environment into a real-time blocky landscape
|
| 92 |
-
</p>
|
| 93 |
-
</div>
|
| 94 |
</div>
|
| 95 |
""")
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
)
|
| 119 |
-
status_color = "🟢" if voxel_backend is not None else "🔴"
|
| 120 |
-
status_text = "Connected" if voxel_backend is not None else "Offline"
|
| 121 |
-
gr.Markdown(f"**Modal Backend:** {status_color} `{status_text}`")
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
| 126 |
webrtc_single = WebRTC(
|
| 127 |
label="Live Voxel Viewport",
|
| 128 |
modality="video",
|
| 129 |
mode="send-receive",
|
| 130 |
-
elem_id="webrtc-single", # ← docs pattern
|
| 131 |
rtc_configuration=get_cloudflare_turn_credentials,
|
| 132 |
)
|
| 133 |
|
| 134 |
-
# ── Mode 2: Streaming Demo ────────────
|
| 135 |
-
with gr.
|
| 136 |
-
|
| 137 |
-
with gr.
|
| 138 |
-
gr.Markdown("### 📺 Dual-Feed · _Left: Raw · Right: Minecraft_")
|
| 139 |
webrtc_demo = WebRTC(
|
| 140 |
label="Live Side-by-Side Feed",
|
| 141 |
modality="video",
|
| 142 |
mode="send-receive",
|
| 143 |
-
elem_id="webrtc-demo", # ← docs pattern
|
| 144 |
rtc_configuration=get_cloudflare_turn_credentials,
|
| 145 |
)
|
| 146 |
|
| 147 |
-
# ── Mode Switch ──────────────────────────────────────────────────────────
|
| 148 |
def switch_layout(selected_mode):
|
| 149 |
return (
|
| 150 |
gr.update(visible=selected_mode == "Minecraft Filter"),
|
|
@@ -157,7 +153,7 @@ with gr.Blocks(title="Minecraft Spatial Voxel Filter", css=css) as demo:
|
|
| 157 |
outputs=[minecraft_layout, demo_layout],
|
| 158 |
)
|
| 159 |
|
| 160 |
-
# ── Stream Bindings ──────────────────────────────────────────────────────
|
| 161 |
webrtc_single.stream(
|
| 162 |
fn=process_video_stream,
|
| 163 |
inputs=[webrtc_single, prompt_input, denoise_strength],
|
|
|
|
| 74 |
return np.hstack([raw_labeled, processed])
|
| 75 |
|
| 76 |
|
| 77 |
+
# ── CSS: official Gradio WebRTC pattern (from gradio.app/guides) ───────────
|
| 78 |
+
# Target gr.Group and gr.Column via elem_classes — NOT the WebRTC component
|
| 79 |
css = """
|
| 80 |
+
.webrtc-group { max-width: 600px !important; max-height: 600px !important; }
|
| 81 |
+
.webrtc-col { display: flex !important; justify-content: center !important; align-items: center !important; }
|
| 82 |
+
.demo-group { max-width: 1000px !important; max-height: 600px !important; }
|
| 83 |
"""
|
| 84 |
|
| 85 |
+
status_color = "🟢" if voxel_backend is not None else "🔴"
|
| 86 |
+
status_text = "Connected" if voxel_backend is not None else "Offline"
|
| 87 |
+
|
| 88 |
# ── UI ───────────────────────────────────────────────────────────────────────
|
| 89 |
with gr.Blocks(title="Minecraft Spatial Voxel Filter", css=css) as demo:
|
| 90 |
|
| 91 |
gr.HTML("""
|
| 92 |
+
<div style='text-align:center; padding: 16px 0'>
|
| 93 |
+
<h1 style='margin:0'>⛏️ MINECRAFT SPATIAL VOXEL FILTER ⛏️</h1>
|
| 94 |
+
<p style='margin:6px 0 0 0'>Transform your environment into a real-time blocky landscape</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
</div>
|
| 96 |
""")
|
| 97 |
|
| 98 |
+
# ── Shared controls (always visible) ─────────────────────────────────────
|
| 99 |
+
with gr.Row():
|
| 100 |
+
mode_dropdown = gr.Dropdown(
|
| 101 |
+
choices=["Minecraft Filter", "Streaming Demo"],
|
| 102 |
+
value="Minecraft Filter",
|
| 103 |
+
label="🎯 Pipeline Mode",
|
| 104 |
+
interactive=True,
|
| 105 |
+
scale=1,
|
| 106 |
+
)
|
| 107 |
+
prompt_input = gr.Textbox(
|
| 108 |
+
value="vanilla minecraft voxel landscape, 3d blocky style, retro game cube aesthetic",
|
| 109 |
+
label="Biome Blueprint",
|
| 110 |
+
lines=1,
|
| 111 |
+
scale=3,
|
| 112 |
+
)
|
| 113 |
+
denoise_strength = gr.Slider(
|
| 114 |
+
minimum=0.1, maximum=1.0, step=0.05, value=0.55,
|
| 115 |
+
label="Denoising Strength",
|
| 116 |
+
scale=1,
|
| 117 |
+
)
|
| 118 |
+
gr.Markdown(f"**Backend:** {status_color} `{status_text}`", scale=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
# ── Mode 1: Minecraft Filter ──────────────────────────────────────────────
|
| 121 |
+
# OFFICIAL PATTERN: gr.Column(elem_classes) → gr.Group(elem_classes) → WebRTC
|
| 122 |
+
with gr.Column(elem_classes=["webrtc-col"], visible=True) as minecraft_layout:
|
| 123 |
+
gr.Markdown("### 📺 Spatial Render Pipeline")
|
| 124 |
+
with gr.Group(elem_classes=["webrtc-group"]):
|
| 125 |
webrtc_single = WebRTC(
|
| 126 |
label="Live Voxel Viewport",
|
| 127 |
modality="video",
|
| 128 |
mode="send-receive",
|
|
|
|
| 129 |
rtc_configuration=get_cloudflare_turn_credentials,
|
| 130 |
)
|
| 131 |
|
| 132 |
+
# ── Mode 2: Streaming Demo ────────────────────────────────────────────────
|
| 133 |
+
with gr.Column(elem_classes=["webrtc-col"], visible=False) as demo_layout:
|
| 134 |
+
gr.Markdown("### 📺 Dual-Feed · _Left: Raw · Right: Minecraft_")
|
| 135 |
+
with gr.Group(elem_classes=["demo-group"]):
|
|
|
|
| 136 |
webrtc_demo = WebRTC(
|
| 137 |
label="Live Side-by-Side Feed",
|
| 138 |
modality="video",
|
| 139 |
mode="send-receive",
|
|
|
|
| 140 |
rtc_configuration=get_cloudflare_turn_credentials,
|
| 141 |
)
|
| 142 |
|
| 143 |
+
# ── Mode Switch ───────────────────────────────────────────────────────────
|
| 144 |
def switch_layout(selected_mode):
|
| 145 |
return (
|
| 146 |
gr.update(visible=selected_mode == "Minecraft Filter"),
|
|
|
|
| 153 |
outputs=[minecraft_layout, demo_layout],
|
| 154 |
)
|
| 155 |
|
| 156 |
+
# ── Stream Bindings ───────────────────────────────────────────────────────
|
| 157 |
webrtc_single.stream(
|
| 158 |
fn=process_video_stream,
|
| 159 |
inputs=[webrtc_single, prompt_input, denoise_strength],
|