connork commited on
Commit
b6c6615
·
1 Parent(s): de9c0fe

Bootstrap Streamlit when launched via python

Browse files
Files changed (1) hide show
  1. app.py +30 -7
app.py CHANGED
@@ -1,13 +1,6 @@
1
  import io
2
  import os
3
  import tempfile
4
- import joblib
5
- import numpy as np
6
- import pandas as pd
7
- import streamlit as st
8
- import librosa
9
- import librosa.display
10
- import matplotlib.pyplot as plt
11
  from pathlib import Path
12
 
13
  BASE_DIR = Path(__file__).resolve().parent
@@ -19,6 +12,36 @@ for cache_dir in (NUMBA_CACHE_DIR, MPL_CACHE_DIR):
19
  os.environ.setdefault("NUMBA_CACHE_DIR", str(NUMBA_CACHE_DIR))
20
  os.environ.setdefault("MPLCONFIGDIR", str(MPL_CACHE_DIR))
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  from features import extract_features
23
  from devices import describe_label
24
 
 
1
  import io
2
  import os
3
  import tempfile
 
 
 
 
 
 
 
4
  from pathlib import Path
5
 
6
  BASE_DIR = Path(__file__).resolve().parent
 
12
  os.environ.setdefault("NUMBA_CACHE_DIR", str(NUMBA_CACHE_DIR))
13
  os.environ.setdefault("MPLCONFIGDIR", str(MPL_CACHE_DIR))
14
 
15
+ import joblib
16
+ import numpy as np
17
+ import pandas as pd
18
+ import streamlit as st
19
+
20
+ if not st.runtime.exists():
21
+ # Hugging Face Spaces sometimes executes `python app.py`; bootstrap Streamlit manually.
22
+ from streamlit.web import cli as stcli
23
+
24
+ import sys
25
+
26
+ port = os.environ.get("PORT", "7860")
27
+ address = os.environ.get("HOST", "0.0.0.0")
28
+ sys.argv = [
29
+ "streamlit",
30
+ "run",
31
+ __file__,
32
+ "--server.port",
33
+ port,
34
+ "--server.address",
35
+ address,
36
+ "--server.headless",
37
+ "true",
38
+ ]
39
+ sys.exit(stcli.main())
40
+
41
+ import librosa
42
+ import librosa.display
43
+ import matplotlib.pyplot as plt
44
+
45
  from features import extract_features
46
  from devices import describe_label
47