zenefil commited on
Commit
bf3444d
·
verified ·
1 Parent(s): 21236a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -7
app.py CHANGED
@@ -1,30 +1,55 @@
 
1
  import os
2
  from huggingface_hub import snapshot_download
3
- import subprocess
4
  import sys
5
 
6
- # 1) Download private Space
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  LOCAL_DIR = snapshot_download(
8
- repo_id="zenefil/veo", # ganti!
9
  repo_type="space",
10
  use_auth_token=os.getenv("HF_TOKEN"),
11
  )
12
 
13
- # 2) Path ke skrip Streamlit di private Space
14
  streamlit_script = os.path.join(LOCAL_DIR, "src", "streamlit_app.py")
15
-
16
  if not os.path.exists(streamlit_script):
17
  print(f"File tidak ditemukan: {streamlit_script}")
18
  sys.exit(1)
19
 
20
- # 3) Jalankan streamlit (replace current process agar log rapi)
21
  os.execvp(
22
  "streamlit",
23
  [
24
  "streamlit",
25
  "run",
26
  streamlit_script,
27
- "--server.port", os.getenv("PORT", "7860"),
28
  "--server.address", "0.0.0.0",
 
29
  ],
30
  )
 
1
+ # app.py (Space publik)
2
  import os
3
  from huggingface_hub import snapshot_download
 
4
  import sys
5
 
6
+ # ---- 1) Set ENV sebelum Streamlit jalan (W A J I B) ----
7
+ # HOME yang writable (agar tidak tulis ke '/.streamlit')
8
+ os.environ.setdefault("HOME", "/home/user")
9
+ # Matikan XSRF/CORS + naikan limit upload
10
+ os.environ.setdefault("STREAMLIT_SERVER_ENABLE_XSRF_PROTECTION", "false")
11
+ os.environ.setdefault("STREAMLIT_SERVER_ENABLE_CORS", "false")
12
+ os.environ.setdefault("STREAMLIT_BROWSER_GATHER_USAGE_STATS", "false")
13
+ os.environ.setdefault("STREAMLIT_SERVER_MAX_UPLOAD_SIZE", "1024")
14
+
15
+ # (opsional) siapkan config.toml sebagai backup
16
+ try:
17
+ cfg_dir = os.path.join(os.environ["HOME"], ".streamlit")
18
+ os.makedirs(cfg_dir, exist_ok=True)
19
+ cfg_path = os.path.join(cfg_dir, "config.toml")
20
+ if not os.path.exists(cfg_path):
21
+ with open(cfg_path, "w", encoding="utf-8") as f:
22
+ f.write(
23
+ "[server]\n"
24
+ "enableXsrfProtection = false\n"
25
+ "enableCORS = false\n"
26
+ "maxUploadSize = 1024\n"
27
+ "\n[browser]\n"
28
+ "gatherUsageStats = false\n"
29
+ )
30
+ except Exception:
31
+ pass
32
+
33
+ # ---- 2) Download Space privat ----
34
  LOCAL_DIR = snapshot_download(
35
+ repo_id="zenefil/veo", # <== pastikan benar
36
  repo_type="space",
37
  use_auth_token=os.getenv("HF_TOKEN"),
38
  )
39
 
40
+ # ---- 3) Jalankan streamlit script dari Space privat ----
41
  streamlit_script = os.path.join(LOCAL_DIR, "src", "streamlit_app.py")
 
42
  if not os.path.exists(streamlit_script):
43
  print(f"File tidak ditemukan: {streamlit_script}")
44
  sys.exit(1)
45
 
 
46
  os.execvp(
47
  "streamlit",
48
  [
49
  "streamlit",
50
  "run",
51
  streamlit_script,
 
52
  "--server.address", "0.0.0.0",
53
+ "--server.port", os.getenv("PORT", "7860"),
54
  ],
55
  )