Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +39 -38
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,41 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
"""
|
| 7 |
-
# Welcome to Streamlit!
|
| 8 |
-
|
| 9 |
-
Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
|
| 10 |
-
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
|
| 11 |
-
forums](https://discuss.streamlit.io).
|
| 12 |
-
|
| 13 |
-
In the meantime, below is an example of what you can do with just a few lines of code:
|
| 14 |
-
"""
|
| 15 |
-
|
| 16 |
-
num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
|
| 17 |
-
num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
|
| 18 |
-
|
| 19 |
-
indices = np.linspace(0, 1, num_points)
|
| 20 |
-
theta = 2 * np.pi * num_turns * indices
|
| 21 |
-
radius = indices
|
| 22 |
-
|
| 23 |
-
x = radius * np.cos(theta)
|
| 24 |
-
y = radius * np.sin(theta)
|
| 25 |
-
|
| 26 |
-
df = pd.DataFrame({
|
| 27 |
-
"x": x,
|
| 28 |
-
"y": y,
|
| 29 |
-
"idx": indices,
|
| 30 |
-
"rand": np.random.randn(num_points),
|
| 31 |
-
})
|
| 32 |
-
|
| 33 |
-
st.altair_chart(alt.Chart(df, height=700, width=700)
|
| 34 |
-
.mark_point(filled=True)
|
| 35 |
-
.encode(
|
| 36 |
-
x=alt.X("x", axis=None),
|
| 37 |
-
y=alt.Y("y", axis=None),
|
| 38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
| 39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 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/gl_runtime")
|
| 8 |
+
STREAMLIT_DIR = BASE_DIR / ".streamlit"
|
| 9 |
+
REPO_TARGET = BASE_DIR / "gl"
|
| 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/gl_runtime/gl 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 gl
|
| 35 |
+
#st.write("repo loaded from", str(REPO_TARGET))
|
| 36 |
+
#st.image("huniutoo.png")
|
| 37 |
+
#st.image("gwecon.png")
|
| 38 |
+
gl.gl()
|
| 39 |
+
|
| 40 |
+
# ...rest of your UI...
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|