Spaces:
Sleeping
Sleeping
dasdebanna
commited on
Commit
·
13bd1ea
1
Parent(s):
ff76d0f
Use streamlit_app launcher -> src/app.py; remove root app.py
Browse files- app.py +0 -35
- src/streamlit_app.py +0 -40
app.py
DELETED
|
@@ -1,35 +0,0 @@
|
|
| 1 |
-
# app.py (place this at repo root and push)
|
| 2 |
-
"""
|
| 3 |
-
Top-level launcher for Hugging Face Spaces (Streamlit).
|
| 4 |
-
Ensures Streamlit config/metrics are written into repo .streamlit (writable),
|
| 5 |
-
then runs src/app.py as __main__.
|
| 6 |
-
"""
|
| 7 |
-
import os
|
| 8 |
-
from pathlib import Path
|
| 9 |
-
import runpy
|
| 10 |
-
|
| 11 |
-
ROOT = Path(__file__).parent.resolve()
|
| 12 |
-
STREAMLIT_DIR = ROOT.joinpath(".streamlit")
|
| 13 |
-
|
| 14 |
-
# 1) Prefer a repo-local config dir so Streamlit doesn't try to write to '/'
|
| 15 |
-
os.environ.setdefault("XDG_CONFIG_HOME", str(STREAMLIT_DIR))
|
| 16 |
-
# Some libs read HOME, ensure it's not '/'
|
| 17 |
-
os.environ.setdefault("HOME", str(ROOT))
|
| 18 |
-
|
| 19 |
-
# 2) Ensure .streamlit/config.toml exists with recommended settings
|
| 20 |
-
STREAMLIT_DIR.mkdir(parents=True, exist_ok=True)
|
| 21 |
-
cfg = STREAMLIT_DIR.joinpath("config.toml")
|
| 22 |
-
if not cfg.exists():
|
| 23 |
-
cfg.write_text(
|
| 24 |
-
"[server]\n"
|
| 25 |
-
"headless = true\n"
|
| 26 |
-
"port = 8501\n"
|
| 27 |
-
"enableCORS = false\n"
|
| 28 |
-
"enableWebsocketCompression = false\n\n"
|
| 29 |
-
"[browser]\n"
|
| 30 |
-
"gatherUsageStats = false\n",
|
| 31 |
-
encoding="utf-8",
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
# 3) Finally run your real app script
|
| 35 |
-
runpy.run_path(str(ROOT.joinpath("src", "app.py")), run_name="__main__")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/streamlit_app.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 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 |
-
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|