-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcustom_script.py
More file actions
51 lines (43 loc) · 1.41 KB
/
custom_script.py
File metadata and controls
51 lines (43 loc) · 1.41 KB
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
48
49
50
51
import sys
import os
from pathlib import Path
import contextlib
import logging
def main():
try:
import streamlit.web.cli as stcli
except ImportError:
# Suppress error message or log it silently
sys.exit(1)
# Get the directory of the installed package
package_dir = Path(__file__).parent.absolute()
app_path = package_dir / "app.py"
if not app_path.exists():
# Suppress error message or log it silently
sys.exit(1)
# Read port and address from environment variables
port = os.environ.get("STREAMLIT_SERVER_PORT", "8501")
address = os.environ.get("STREAMLIT_SERVER_ADDRESS", "localhost")
# Suppress Streamlit logging
os.environ["STREAMLIT_SUPPRESS_LOGGING"] = "1"
sys.argv = [
"streamlit",
"run",
str(app_path),
"--server.port", port,
"--server.address", address,
"--browser.gatherUsageStats=false",
"--server.runOnSave=false",
"--server.fileWatcherType=none",
"--logger.level=error" # Set logging level to error
]
# Redirect stdout and stderr to null
with open(os.devnull, 'w') as devnull:
with contextlib.redirect_stdout(devnull), contextlib.redirect_stderr(devnull):
try:
stcli.main()
except Exception:
# Suppress exception traceback
sys.exit(1)
if __name__ == '__main__':
main()