AnimeOverlord commited on
Commit
ae4da09
·
1 Parent(s): eecf206

still initial commit

Browse files
Files changed (1) hide show
  1. app.py +41 -43
app.py CHANGED
@@ -74,27 +74,25 @@ def process_demo_stream(frame: np.ndarray) -> np.ndarray:
74
  return np.hstack([raw_labeled, processed])
75
 
76
 
77
- # ── THE FIX: from official FastRTC docs ────────────────────────────────────
78
- # Use elem_classes on gr.Group + gr.Column, not elem_id CSS targeting
79
- # Use height= directly on WebRTC() — the component accepts it natively
80
  css = """
81
- .webrtc-group {
82
- max-width: 100% !important;
83
- max-height: 480px !important;
84
- overflow: hidden !important;
85
- }
86
- .webrtc-col {
87
- display: flex !important;
88
- justify-content: center !important;
89
- align-items: flex-start !important;
90
- }
91
  """
92
 
93
  # ── UI ───────────────────────────────────────────────────────────────────────
94
  with gr.Blocks(title="Minecraft Spatial Voxel Filter", css=css) as demo:
95
 
96
- gr.Markdown("<h1 style='text-align: center;'>⛏️ MINECRAFT SPATIAL VOXEL FILTER ⛏️</h1>")
97
- gr.Markdown("<p style='text-align: center;'>Transform your environment into a real-time blocky landscape.</p>")
 
 
 
 
 
 
 
 
98
 
99
  mode_dropdown = gr.Dropdown(
100
  choices=["Minecraft Filter", "Streaming Demo"],
@@ -103,10 +101,11 @@ with gr.Blocks(title="Minecraft Spatial Voxel Filter", css=css) as demo:
103
  interactive=True,
104
  )
105
 
106
- with gr.Row():
 
107
 
108
- # ── Left: Controls ─────────────────────────────────────────────────
109
- with gr.Column(scale=1, min_width=280):
110
  gr.Markdown("### 🎛️ Environmental Filters")
111
  prompt_input = gr.Textbox(
112
  value="vanilla minecraft voxel landscape, 3d blocky style, retro game cube aesthetic",
@@ -120,31 +119,30 @@ with gr.Blocks(title="Minecraft Spatial Voxel Filter", css=css) as demo:
120
  status_color = "🟢" if voxel_backend is not None else "🔴"
121
  status_text = "Connected" if voxel_backend is not None else "Offline"
122
  gr.Markdown(f"**Modal Backend:** {status_color} `{status_text}`")
123
- gr.Markdown("_Controls only apply in Minecraft Filter mode._")
124
-
125
- # ── Right: Viewports ───────────────────────────────────────────────
126
- # OFFICIAL PATTERN: elem_classes on Column + Group, height= on WebRTC
127
- with gr.Column(scale=2, elem_classes=["webrtc-col"]):
128
-
129
- with gr.Group(visible=True, elem_classes=["webrtc-group"]) as minecraft_layout:
130
- gr.Markdown("### 📺 Spatial Render Pipeline")
131
- webrtc_single = WebRTC(
132
- label="Live Voxel Viewport",
133
- modality="video",
134
- mode="send-receive",
135
- rtc_configuration=get_cloudflare_turn_credentials,
136
- height=440, # native height param, docs-official fix
137
- )
138
-
139
- with gr.Group(visible=False, elem_classes=["webrtc-group"]) as demo_layout:
140
- gr.Markdown("### 📺 Dual-Feed · _Left: Raw · Right: Minecraft_")
141
- webrtc_demo = WebRTC(
142
- label="Live Side-by-Side Feed",
143
- modality="video",
144
- mode="send-receive",
145
- rtc_configuration=get_cloudflare_turn_credentials,
146
- height=440, # ← same
147
- )
148
 
149
  # ── Mode Switch ──────────────────────────────────────────────────────────
150
  def switch_layout(selected_mode):
 
74
  return np.hstack([raw_labeled, processed])
75
 
76
 
77
+ # ── CSS: exact pattern from official FastRTC docs ──────────────────────────
 
 
78
  css = """
79
+ #webrtc-single { max-width: 600px !important; max-height: 600px !important; }
80
+ #webrtc-demo { max-width: 900px !important; max-height: 600px !important; }
 
 
 
 
 
 
 
 
81
  """
82
 
83
  # ── UI ───────────────────────────────────────────────────────────────────────
84
  with gr.Blocks(title="Minecraft Spatial Voxel Filter", css=css) as demo:
85
 
86
+ gr.HTML("""
87
+ <div style='display: flex; align-items: center; justify-content: center; gap: 16px; padding: 12px 0'>
88
+ <div>
89
+ <h1 style='margin: 0'>⛏️ MINECRAFT SPATIAL VOXEL FILTER ⛏️</h1>
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
  mode_dropdown = gr.Dropdown(
98
  choices=["Minecraft Filter", "Streaming Demo"],
 
101
  interactive=True,
102
  )
103
 
104
+ # ── Mode 1: Minecraft Filter ───────────────────────────────────────────
105
+ with gr.Row(visible=True) as minecraft_layout:
106
 
107
+ # Left: controls
108
+ with gr.Column():
109
  gr.Markdown("### 🎛️ Environmental Filters")
110
  prompt_input = gr.Textbox(
111
  value="vanilla minecraft voxel landscape, 3d blocky style, retro game cube aesthetic",
 
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
+ # Right: video — elem_id + CSS, exactly like the docs example
124
+ with gr.Column():
125
+ gr.Markdown("### 📺 Spatial Render Pipeline")
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.Row(visible=False) as demo_layout:
136
+
137
+ with gr.Column():
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):