Commit ·
99ea5fd
1
Parent(s): b6b07c0
still initial commit
Browse files
app.py
CHANGED
|
@@ -3,19 +3,7 @@ import cv2
|
|
| 3 |
import numpy as np
|
| 4 |
import gradio as gr
|
| 5 |
import modal
|
| 6 |
-
|
| 7 |
-
# 🔥 MONKEY-PATCH HOTFIX: Bypasses the older Gradio version bug for gr.Sidebar
|
| 8 |
-
import inspect
|
| 9 |
-
_original_sidebar_init = gr.Sidebar.__init__
|
| 10 |
-
def _patched_sidebar_init(self, *args, **kwargs):
|
| 11 |
-
# Remove 'position' parameter if the underlying Gradio version doesn't support it
|
| 12 |
-
sig = inspect.signature(_original_sidebar_init)
|
| 13 |
-
if "position" not in sig.parameters:
|
| 14 |
-
kwargs.pop("position", None)
|
| 15 |
-
_original_sidebar_init(self, *args, **kwargs)
|
| 16 |
-
gr.Sidebar.__init__ = _patched_sidebar_init
|
| 17 |
-
|
| 18 |
-
from fastrtc import Stream, get_cloudflare_turn_credentials
|
| 19 |
|
| 20 |
# ── Modal Backend ───────────────────────────────────────────────────────────
|
| 21 |
try:
|
|
@@ -79,11 +67,11 @@ def _run_voxel_backend(frame: np.ndarray) -> np.ndarray:
|
|
| 79 |
return out
|
| 80 |
|
| 81 |
|
| 82 |
-
# ──
|
| 83 |
-
def process_video_stream(frame: np.ndarray, mode: str
|
| 84 |
"""
|
| 85 |
Unified real-time handler mapping directly to FastRTC's stream pipeline.
|
| 86 |
-
Accepts incoming frame
|
| 87 |
"""
|
| 88 |
if frame is None:
|
| 89 |
return None
|
|
@@ -114,33 +102,43 @@ def process_video_stream(frame: np.ndarray, mode: str, _status=None) -> np.ndarr
|
|
| 114 |
return processed
|
| 115 |
|
| 116 |
|
| 117 |
-
# ──
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
if __name__ == "__main__":
|
| 146 |
-
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
import gradio as gr
|
| 5 |
import modal
|
| 6 |
+
from fastrtc import WebRTC, get_cloudflare_turn_credentials
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# ── Modal Backend ───────────────────────────────────────────────────────────
|
| 9 |
try:
|
|
|
|
| 67 |
return out
|
| 68 |
|
| 69 |
|
| 70 |
+
# ── Core Stream Handler ─────────────────────────────────────────────────────
|
| 71 |
+
def process_video_stream(frame: np.ndarray, mode: str) -> np.ndarray:
|
| 72 |
"""
|
| 73 |
Unified real-time handler mapping directly to FastRTC's stream pipeline.
|
| 74 |
+
Accepts incoming frame from the WebRTC component and the mode dropdown selection.
|
| 75 |
"""
|
| 76 |
if frame is None:
|
| 77 |
return None
|
|
|
|
| 102 |
return processed
|
| 103 |
|
| 104 |
|
| 105 |
+
# ── Custom Gradio Interface Layout ──────────────────────────────────────────
|
| 106 |
+
with gr.Blocks(title="⛏️ Minecraft Spatial Voxel Filter") as demo:
|
| 107 |
+
gr.Markdown("# ⛏️ Minecraft Spatial Voxel Filter")
|
| 108 |
+
|
| 109 |
+
with gr.Row():
|
| 110 |
+
# Configuration Settings & Status (Left Side Box)
|
| 111 |
+
with gr.Column(scale=1):
|
| 112 |
+
status_md = gr.Markdown(
|
| 113 |
+
f"### ⚡ Backend Connection Status\n"
|
| 114 |
+
f"Status: {status_color} **{status_text}**\n\n"
|
| 115 |
+
f"Switching between pipeline modes instantly updates your active viewport feed."
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
mode_dropdown = gr.Dropdown(
|
| 119 |
+
choices=["Minecraft Filter", "Streaming Demo"],
|
| 120 |
+
value="Minecraft Filter",
|
| 121 |
+
label="🎯 Pipeline Mode",
|
| 122 |
+
interactive=True,
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
# Contained Video Box Viewport (Right Side Box)
|
| 126 |
+
with gr.Column(scale=2):
|
| 127 |
+
webrtc_stream = WebRTC(
|
| 128 |
+
label="Live Filter Stream",
|
| 129 |
+
modality="video",
|
| 130 |
+
mode="send-receive",
|
| 131 |
+
rtc_configuration=get_safe_rtc_configuration(),
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
# Explicitly attach the handler to the custom WebRTC component
|
| 135 |
+
webrtc_stream.stream(
|
| 136 |
+
fn=process_video_stream,
|
| 137 |
+
inputs=[webrtc_stream, mode_dropdown],
|
| 138 |
+
outputs=[webrtc_stream],
|
| 139 |
+
time_limit=150,
|
| 140 |
+
concurrency_limit=4,
|
| 141 |
+
)
|
| 142 |
|
| 143 |
if __name__ == "__main__":
|
| 144 |
+
demo.launch()
|