-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve_streamlit.py
40 lines (33 loc) · 1020 Bytes
/
serve_streamlit.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
import shlex
import subprocess
from pathlib import Path
import modal
streamlit_script_local_path = Path(__file__).parent / "app.py"
streamlit_script_remote_path = "/root/app.py"
image = (
modal.Image.debian_slim(python_version="3.11")
.pip_install(
"streamlit==1.12.0",
"pandas==2.2.3",
"plotly==5.24.1",
"altair==4.2.2",
"tabulate==0.9.0",
)
.add_local_file(
streamlit_script_local_path,
streamlit_script_remote_path,
)
)
app = modal.App(name="venmo-splitter", image=image)
if not streamlit_script_local_path.exists():
raise RuntimeError(
"app.py not found! Place the script with your streamlit app in the same directory."
)
@app.function(
allow_concurrent_inputs=100,
)
@modal.web_server(8000)
def run():
target = shlex.quote(streamlit_script_remote_path)
cmd = f"streamlit run {target} --server.port 8000 --server.enableCORS=false --server.enableXsrfProtection=false"
subprocess.Popen(cmd, shell=True)