Saravutw commited on
Commit
284289a
·
verified ·
1 Parent(s): d9c7ee8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -53
app.py CHANGED
@@ -8,7 +8,7 @@ from pathlib import Path
8
  from typing import Any, Dict
9
  import gradio as gr
10
 
11
- # --- CONFIGURATION PROTOCOLS ---
12
  _CONFIG_MARKER = b"OMNICFG1"
13
 
14
  def _collect_config_values(namespace: Dict[str, Any]) -> Dict[str, Any]:
@@ -28,16 +28,6 @@ def _load_config_from_source(content: str) -> Dict[str, Any]:
28
  exec(content, scope, scope)
29
  return _collect_config_values(scope)
30
 
31
- def _load_config_from_pyc(path: Path) -> Dict[str, Any]:
32
- loader = importlib.machinery.SourcelessFileLoader("omni_private_config_compat", str(path))
33
- spec = importlib.util.spec_from_loader("omni_private_config_compat", loader)
34
- module = importlib.util.module_from_spec(spec) if spec else None
35
- if not spec or not module or not spec.loader:
36
- raise RuntimeError(f"failed to load config bytecode module spec from {path}")
37
- spec.loader.exec_module(module)
38
- namespace = {key: getattr(module, key) for key in dir(module)}
39
- return _collect_config_values(namespace)
40
-
41
  def _write_packed_private_config(path: Path, data: Dict[str, Any]) -> None:
42
  payload = json.dumps(data, ensure_ascii=False, separators=(",", ":")).encode("utf-8")
43
  packed = _CONFIG_MARKER + zlib.compress(payload, level=9)
@@ -53,8 +43,7 @@ def _materialize_private_config_from_env() -> None:
53
  if raw_b64:
54
  try:
55
  content = base64.b64decode(raw_b64.encode("utf-8")).decode("utf-8")
56
- except Exception as exc:
57
- print(f"[startup] warning: decode failed: {exc}")
58
  return
59
  elif raw_py:
60
  content = raw_py
@@ -62,22 +51,11 @@ def _materialize_private_config_from_env() -> None:
62
  try:
63
  data = _load_config_from_source(content.rstrip() + "\n")
64
  _write_packed_private_config(pyc_target, data)
65
- except Exception as exc:
66
- print(f"[startup] warning: build config failed: {exc}")
67
 
68
  def _load_runtime_module():
69
  repo_dir = Path(__file__).resolve().parent
70
- pyc_path = repo_dir / "src" / "app_lib.pyc"
71
- if pyc_path.exists():
72
- got = pyc_path.read_bytes()[:4]
73
- expected = importlib.util.MAGIC_NUMBER
74
- if got == expected:
75
- loader = importlib.machinery.SourcelessFileLoader("app_lib_runtime", str(pyc_path))
76
- spec = importlib.util.spec_from_loader("app_lib_runtime", loader)
77
- if spec is not None:
78
- module = importlib.util.module_from_spec(spec)
79
- loader.exec_module(module)
80
- return module
81
  try:
82
  from src import app_lib as module
83
  return module
@@ -88,42 +66,42 @@ def _load_runtime_module():
88
  _materialize_private_config_from_env()
89
  _RUNTIME = _load_runtime_module()
90
 
91
- # --- INTERFACE BRIDGE (VIDEO UI) ---
92
- # Using the correct Direct Embed Link for Video Generation Space
93
- SOURCE_VIDEO_SPACE_URL = "https://selfit-camera-omni-video-editor.hf.space"
94
 
95
- def build_video_interface():
96
- with gr.Blocks(fill_height=True) as demo:
97
  gr.HTML(f"""
98
- <iframe
99
- src="{SOURCE_VIDEO_SPACE_URL}"
100
- frameborder="0"
101
- width="100%"
102
- height="100%"
103
- style="min-height: 900px; border-radius: 8px;"
104
- allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
105
- allowfullscreen>
106
- </iframe>
 
 
107
  """)
108
  return demo
109
 
110
  if __name__ == "__main__":
111
- print("[startup] Preparing Video Generation Runtime...")
112
 
113
- # Initialize background hooks if available
114
  if _RUNTIME:
115
- kickoff_runtime = getattr(_RUNTIME, "kickoff_runtime_prepare_background", None)
116
- kickoff_model = getattr(_RUNTIME, "kickoff_model_prepare_background", None)
117
-
118
- if callable(kickoff_runtime):
119
- print(kickoff_runtime())
120
- if callable(kickoff_model):
121
- print(kickoff_model())
122
 
123
- # Build and Launch the Video UI
124
- demo = build_video_interface()
125
  demo.launch(
126
  share=True,
127
- server_name="0.0.0.0",
128
- server_port=int(os.getenv("PORT", "7860"))
 
129
  )
 
8
  from typing import Any, Dict
9
  import gradio as gr
10
 
11
+ # --- CONFIGURATION PROTOCOLS (OMNICFG1) ---
12
  _CONFIG_MARKER = b"OMNICFG1"
13
 
14
  def _collect_config_values(namespace: Dict[str, Any]) -> Dict[str, Any]:
 
28
  exec(content, scope, scope)
29
  return _collect_config_values(scope)
30
 
 
 
 
 
 
 
 
 
 
 
31
  def _write_packed_private_config(path: Path, data: Dict[str, Any]) -> None:
32
  payload = json.dumps(data, ensure_ascii=False, separators=(",", ":")).encode("utf-8")
33
  packed = _CONFIG_MARKER + zlib.compress(payload, level=9)
 
43
  if raw_b64:
44
  try:
45
  content = base64.b64decode(raw_b64.encode("utf-8")).decode("utf-8")
46
+ except Exception:
 
47
  return
48
  elif raw_py:
49
  content = raw_py
 
51
  try:
52
  data = _load_config_from_source(content.rstrip() + "\n")
53
  _write_packed_private_config(pyc_target, data)
54
+ except Exception:
55
+ pass
56
 
57
  def _load_runtime_module():
58
  repo_dir = Path(__file__).resolve().parent
 
 
 
 
 
 
 
 
 
 
 
59
  try:
60
  from src import app_lib as module
61
  return module
 
66
  _materialize_private_config_from_env()
67
  _RUNTIME = _load_runtime_module()
68
 
69
+ # --- VIDEO INTERFACE BRIDGE ---
70
+ # Direct link to the Video Factory space for Iframe embedding
71
+ SOURCE_VIDEO_URL = "https://frameai4687-omni-video-factory.hf.space"
72
 
73
+ def build_video_factory_ui():
74
+ with gr.Blocks(fill_height=True, title="Omni-Video-Factory Bridge") as demo:
75
  gr.HTML(f"""
76
+ <div style="width: 100%; height: 100vh;">
77
+ <iframe
78
+ src="{SOURCE_VIDEO_URL}"
79
+ frameborder="0"
80
+ width="100%"
81
+ height="100%"
82
+ style="min-height: 1000px; border-radius: 4px;"
83
+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
84
+ allowfullscreen>
85
+ </iframe>
86
+ </div>
87
  """)
88
  return demo
89
 
90
  if __name__ == "__main__":
91
+ print("[startup] Launching Omni-Video-Factory Runtime...")
92
 
93
+ # Background hooks execution
94
  if _RUNTIME:
95
+ for hook in ["kickoff_runtime_prepare_background", "kickoff_model_prepare_background"]:
96
+ func = getattr(_RUNTIME, hook, None)
97
+ if callable(func):
98
+ print(f"[startup] {hook}: {func()}")
 
 
 
99
 
100
+ # Launching the interface optimized for Colab / External API
101
+ demo = build_video_factory_ui()
102
  demo.launch(
103
  share=True,
104
+ server_name="0.0.0.0",
105
+ server_port=int(os.getenv("PORT", "7860")),
106
+ inline=False
107
  )