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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -19
app.py CHANGED
@@ -28,6 +28,16 @@ def _load_config_from_source(content: str) -> 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)
@@ -40,53 +50,80 @@ def _materialize_private_config_from_env() -> None:
40
  raw_b64 = (os.getenv("OMNI_PRIVATE_CONFIG_B64") or "").strip()
41
  raw_py = (os.getenv("OMNI_PRIVATE_CONFIG_PY") or "").strip()
42
  content = ""
43
-
44
  if raw_b64:
45
  try:
46
  content = base64.b64decode(raw_b64.encode("utf-8")).decode("utf-8")
47
- except Exception:
 
48
  return
49
  elif raw_py:
50
  content = raw_py
51
-
52
  if content:
53
  try:
54
  data = _load_config_from_source(content.rstrip() + "\n")
55
  _write_packed_private_config(pyc_target, data)
56
- except Exception:
57
- pass
58
 
59
- # --- RUNTIME PREPARATION ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  _materialize_private_config_from_env()
 
61
 
62
- # --- IFRAME INTERFACE (Optimized for Free Tier) ---
63
- # Direct link to the source space to avoid "Refused to connect"
64
- SOURCE_SPACE_URL = "https://selfit-camera-omni-image-editor.hf.space"
65
 
66
- def build_iframe_interface():
67
  with gr.Blocks(fill_height=True) as demo:
68
  gr.HTML(f"""
69
  <iframe
70
- src="{SOURCE_SPACE_URL}"
71
  frameborder="0"
72
  width="100%"
73
  height="100%"
74
- style="min-height: 850px; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);"
75
  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
76
  allowfullscreen>
77
  </iframe>
78
  """)
79
  return demo
80
 
81
- # --- MAIN EXECUTION ---
82
  if __name__ == "__main__":
83
- print("[startup] Initializing Omni-Image-Editor Bridge...")
84
 
85
- # Launch with settings optimized for Colab / API Access
86
- demo = build_iframe_interface()
 
 
 
 
 
 
 
 
 
 
87
  demo.launch(
88
- share=True,
89
  server_name="0.0.0.0",
90
- server_port=int(os.getenv("PORT", "7860")),
91
- inline=False
92
  )
 
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)
 
50
  raw_b64 = (os.getenv("OMNI_PRIVATE_CONFIG_B64") or "").strip()
51
  raw_py = (os.getenv("OMNI_PRIVATE_CONFIG_PY") or "").strip()
52
  content = ""
 
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
 
61
  if content:
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
84
+ except ImportError:
85
+ return None
86
+
87
+ # --- INITIALIZATION ---
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
  )