Create src/streamlit_app.py
Browse files- src/streamlit_app.py +40 -0
src/streamlit_app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from git import Repo
|
| 4 |
+
import sys
|
| 5 |
+
|
| 6 |
+
# ---- 1. pick a writable base dir (we'll stop using /app)
|
| 7 |
+
BASE_DIR = Path("/tmp/huniu_runtime")
|
| 8 |
+
STREAMLIT_DIR = BASE_DIR / ".streamlit"
|
| 9 |
+
REPO_TARGET = BASE_DIR / "huniu"
|
| 10 |
+
|
| 11 |
+
# ensure the base dir exists
|
| 12 |
+
BASE_DIR.mkdir(parents=True, exist_ok=True)
|
| 13 |
+
STREAMLIT_DIR.mkdir(parents=True, exist_ok=True)
|
| 14 |
+
|
| 15 |
+
# ---- 2. tell Streamlit to treat /tmp/... as "home"
|
| 16 |
+
os.environ.setdefault("HOME", str(BASE_DIR))
|
| 17 |
+
os.environ.setdefault("XDG_CONFIG_HOME", str(BASE_DIR))
|
| 18 |
+
os.environ.setdefault("STREAMLIT_CONFIG_DIR", str(STREAMLIT_DIR))
|
| 19 |
+
os.environ.setdefault("STREAMLIT_HOME", str(BASE_DIR))
|
| 20 |
+
os.environ.setdefault("STREAMLIT_BROWSER_GATHERUSAGESTATS", "false")
|
| 21 |
+
|
| 22 |
+
# ---- 3. clone private repo into /tmp/huniu_runtime/huniu if not already there
|
| 23 |
+
if not REPO_TARGET.exists():
|
| 24 |
+
git_url = os.environ.get("GIT_URL")
|
| 25 |
+
if not git_url:
|
| 26 |
+
raise RuntimeError("GIT_URL env var is not set")
|
| 27 |
+
Repo.clone_from(git_url, REPO_TARGET)
|
| 28 |
+
|
| 29 |
+
# make that repo importable
|
| 30 |
+
sys.path.append(str(REPO_TARGET))
|
| 31 |
+
|
| 32 |
+
# ---- 4. now safe to import streamlit and run the app
|
| 33 |
+
import streamlit as st
|
| 34 |
+
import huniu
|
| 35 |
+
#st.write("repo loaded from", str(REPO_TARGET))
|
| 36 |
+
#st.image("huniutoo.png")
|
| 37 |
+
#st.image("gwecon.png")
|
| 38 |
+
huniu.huniu()
|
| 39 |
+
|
| 40 |
+
# ...rest of your UI...
|