AnimeOverlord commited on
Commit
6c9dd43
·
1 Parent(s): 507a1f0

still initial commit

Browse files
Files changed (1) hide show
  1. app.py +24 -10
app.py CHANGED
@@ -1,18 +1,32 @@
 
1
  import gradio as gr
2
  import cv2
3
  import numpy as np
4
  import modal
5
 
6
- # ── Modal Connection ────────────────────────────────────────────────────────
7
- try:
8
- # Hook directly into your remote Modal class
9
- VoxelModelCls = modal.Cls.from_name("flux-klein-voxel-backend", "VoxelModel")
10
- voxel_backend = VoxelModelCls().process_frame
11
- status_text = "🟢 Connected"
12
- except Exception as e:
13
- print(f"Failed to connect to Modal: {e}")
 
14
  voxel_backend = None
15
- status_text = "🔴 Offline"
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
 
18
  # ── Core Backend Execution ──────────────────────────────────────────────────
@@ -43,7 +57,7 @@ def run_modal_backend(frame: np.ndarray) -> np.ndarray:
43
 
44
  # ── Activation & Pre-Warming Logic ──────────────────────────────────────────
45
  def start_and_warmup_container():
46
- """Forces the Modal container to start up before enabling the webcam stream stream."""
47
  print("🚀 [START CLICKED] Waking up Modal container to prevent cold-start lag...")
48
 
49
  if voxel_backend is not None:
 
1
+ import os
2
  import gradio as gr
3
  import cv2
4
  import numpy as np
5
  import modal
6
 
7
+ # ── Authentication & Modal Connection ───────────────────────────────────────
8
+ # Modal automatically authenticates using MODAL_TOKEN_ID and MODAL_TOKEN_SECRET
9
+ # from the environment. We check them here to ensure your HF Secrets are loaded.
10
+
11
+ token_id = os.environ.get("MODAL_TOKEN_ID")
12
+ token_secret = os.environ.get("MODAL_TOKEN_SECRET")
13
+
14
+ if not token_id or not token_secret:
15
+ print("⚠️ [AUTH ERROR] Modal tokens missing! Check your Hugging Face Secrets.")
16
  voxel_backend = None
17
+ status_text = "🔴 Offline (Missing Tokens)"
18
+ else:
19
+ try:
20
+ print("🔑 Tokens found. Connecting to Modal...")
21
+ # Hook directly into your remote Modal class
22
+ VoxelModelCls = modal.Cls.from_name("flux-klein-voxel-backend", "VoxelModel")
23
+ voxel_backend = VoxelModelCls().process_frame
24
+ status_text = "🟢 Connected"
25
+ print("✅ Successfully connected to Modal backend.")
26
+ except Exception as e:
27
+ print(f"❌ Failed to connect to Modal: {e}")
28
+ voxel_backend = None
29
+ status_text = "🔴 Offline (Connection Error)"
30
 
31
 
32
  # ── Core Backend Execution ──────────────────────────────────────────────────
 
57
 
58
  # ── Activation & Pre-Warming Logic ──────────────────────────────────────────
59
  def start_and_warmup_container():
60
+ """Forces the Modal container to start up before enabling the webcam stream."""
61
  print("🚀 [START CLICKED] Waking up Modal container to prevent cold-start lag...")
62
 
63
  if voxel_backend is not None: