fix for pydantic and spaces
Browse files
app.py
CHANGED
@@ -12,9 +12,42 @@ from utils.uploadAndExample import add_upload
|
|
12 |
from PIL import Image
|
13 |
import streamlit as st
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
st.set_page_config(page_title = 'Climate Policy Intelligence',
|
16 |
initial_sidebar_state='expanded', layout="wide")
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
with st.sidebar:
|
19 |
# upload and example doc
|
20 |
choice = st.sidebar.radio(label = 'Select the Document',
|
|
|
12 |
from PIL import Image
|
13 |
import streamlit as st
|
14 |
|
15 |
+
import streamlit as st
|
16 |
+
import os
|
17 |
+
import pkg_resources
|
18 |
+
|
19 |
+
# Using this wacky hack to get around the massively ridicolous managed env loading order
|
20 |
+
def is_installed(package_name, version):
|
21 |
+
try:
|
22 |
+
pkg = pkg_resources.get_distribution(package_name)
|
23 |
+
return pkg.version == version
|
24 |
+
except pkg_resources.DistributionNotFound:
|
25 |
+
return False
|
26 |
+
|
27 |
+
# shifted from below - this must be the first streamlit call; otherwise: problems
|
28 |
st.set_page_config(page_title = 'Climate Policy Intelligence',
|
29 |
initial_sidebar_state='expanded', layout="wide")
|
30 |
|
31 |
+
@st.cache_resource # cache the function so it's not called every time app.py is triggered
|
32 |
+
def install_packages():
|
33 |
+
install_commands = []
|
34 |
+
|
35 |
+
if not is_installed("spaces", "0.12.0"):
|
36 |
+
install_commands.append("pip install spaces==0.17.0")
|
37 |
+
|
38 |
+
if not is_installed("pydantic", "1.8.2"):
|
39 |
+
install_commands.append("pip install pydantic==1.8.2")
|
40 |
+
|
41 |
+
if not is_installed("typer", "0.4.0"):
|
42 |
+
install_commands.append("pip install typer==0.4.0")
|
43 |
+
|
44 |
+
if install_commands:
|
45 |
+
os.system(" && ".join(install_commands))
|
46 |
+
|
47 |
+
# install packages if necessary
|
48 |
+
install_packages()
|
49 |
+
|
50 |
+
|
51 |
with st.sidebar:
|
52 |
# upload and example doc
|
53 |
choice = st.sidebar.radio(label = 'Select the Document',
|