dasdebanna commited on
Commit
2e38127
·
1 Parent(s): 13bd1ea

Add shim src/streamlit_app.py so HF Spaces entrypoint src/streamlit_app.py works

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +32 -0
src/streamlit_app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # src/streamlit_app.py
2
+ """
3
+ Small shim for Hugging Face Spaces compatibility.
4
+
5
+ Some Spaces start Streamlit with `streamlit run src/streamlit_app.py`.
6
+ If that happens, this shim forwards execution to the real launcher
7
+ at the repository root (streamlit_app.py), which in turn runs src/app.py.
8
+ """
9
+ from pathlib import Path
10
+ import runpy
11
+ import sys
12
+ import os
13
+
14
+ ROOT = Path(__file__).parent.parent.resolve()
15
+
16
+ # Diagnostic print so we can see in HF container logs
17
+ print("shim: running src/streamlit_app.py -> delegating to ../streamlit_app.py")
18
+ sys.stdout.flush()
19
+
20
+ # If root streamlit_app.py exists, run it; otherwise directly run src/app.py as fallback
21
+ root_launcher = ROOT.joinpath("streamlit_app.py")
22
+ if root_launcher.exists():
23
+ runpy.run_path(str(root_launcher), run_name="__main__")
24
+ else:
25
+ # fallback: directly run the app (useful for local sanity checks)
26
+ app_script = ROOT.joinpath("src", "app.py")
27
+ if not app_script.exists():
28
+ raise FileNotFoundError(f"Neither {root_launcher} nor {app_script} exist")
29
+ # set a little diagnostic in the logs
30
+ print("shim: root launcher missing — running src/app.py directly")
31
+ sys.stdout.flush()
32
+ runpy.run_path(str(app_script), run_name="__main__")