IshmamF commited on
Commit
7b20843
·
1 Parent(s): 21cbd01

Delete serve_streamlit.py

Browse files
Files changed (1) hide show
  1. serve_streamlit.py +0 -53
serve_streamlit.py DELETED
@@ -1,53 +0,0 @@
1
- import pathlib
2
- import modal
3
-
4
- # Define container dependencies
5
- image = (
6
- modal.Image.debian_slim()
7
- .apt_install("git")
8
- .pip_install("streamlit", "numpy", "pandas", "tensorflow", "transformers", "spotipy", "sentence_transformers")
9
- )
10
-
11
- stub = modal.Stub(name="streamlit_app.py", image=image)
12
-
13
- # Define the run_streamlit function
14
- @stub.function(
15
- mounts=[
16
- modal.Mount.from_local_directory(
17
- local_path=pathlib.Path(__file__).parent,
18
- remote_path=pathlib.Path("/app"),
19
- exclude=["*.pyc", "__pycache__"]
20
- )
21
- ],
22
- timeout=15 * 60 # Set the session timeout as needed
23
- )
24
- def run_streamlit(publish_url: bool = False):
25
- import streamlit.web.bootstrap
26
-
27
- streamlit_script_remote_path = pathlib.Path("streamlit_app.py")
28
-
29
- # Run the server. This function will not return until the server is shut down.
30
- with modal.forward(8501) as tunnel:
31
- # Reload Streamlit config with information about Modal tunnel address.
32
- if publish_url:
33
- stub.q.put(tunnel.url)
34
- streamlit.web.bootstrap.run(
35
- main_script_path=str(streamlit_script_remote_path),
36
- command_line=None,
37
- args=["--timeout", str(15 * 60)], # Adjust as needed
38
- flag_options={},
39
- )
40
-
41
- # Additional function for creating a web endpoint
42
- @stub.function()
43
- @modal.web_endpoint(method="GET")
44
- def share():
45
- from fastapi.responses import RedirectResponse
46
-
47
- run_streamlit.spawn(publish_url=True)
48
- url = stub.q.get()
49
- return RedirectResponse(url, status_code=303)
50
-
51
- # Deploy the app
52
- if __name__ == "__main__":
53
- stub.deploy()