-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_server.py
47 lines (38 loc) · 1.28 KB
/
streamlit_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Streamlit App using Modal Serverless Platform
"""
import shlex
import subprocess
from pathlib import Path
import modal
image = modal.Image.debian_slim().pip_install("streamlit", "numpy", "pandas")
app = modal.App(
name="streamlit-modal-serverless-app", image=image
)
# Mount app.py script (NOTE: Streamlit runs apps as Python scripts)
streamlit_script_local_path = Path(__file__).parent / "app.py"
print('*****************')
print(f'Local path: {streamlit_script_local_path}')
print('*****************')
streamlit_script_remote_path = Path("/root/app.py")
print('*****************')
print(f'remote path: {streamlit_script_local_path}')
print('*****************')
if not streamlit_script_local_path.exists():
raise RuntimeError(
"app.py not found! Check your directory structure."
)
streamlit_script_mount = modal.Mount.from_local_file(
streamlit_script_local_path,
streamlit_script_remote_path,
)
# Instantiate the Streamlit server
@app.function(
allow_concurrent_inputs=100,
mounts=[streamlit_script_mount],
)
@modal.web_server(8000)
def run():
target = shlex.quote(str(streamlit_script_remote_path))
cmd = f"streamlit run {target} --server.port 8000 --server.enableCORS=false --server.enableXsrfProtection=false"
subprocess.Popen(cmd, shell=True)