Spaces:
Runtime error
Runtime error
Add nb develop and utils
Browse files
utils.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import json
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
|
6 |
+
def load_image(image_path, image_resize=None):
|
7 |
+
image = Image.open(image_path)
|
8 |
+
if isinstance(image_resize, tuple):
|
9 |
+
image.resize(image_resize)
|
10 |
+
return image
|
11 |
+
|
12 |
+
|
13 |
+
def load_text(text_path):
|
14 |
+
text = ''
|
15 |
+
with open(text_path) as f:
|
16 |
+
text = f.read()
|
17 |
+
|
18 |
+
return text
|
19 |
+
|
20 |
+
|
21 |
+
def load_json(json_path):
|
22 |
+
jdata = ''
|
23 |
+
with open(json_path) as f:
|
24 |
+
jdata = json.load(f)
|
25 |
+
|
26 |
+
return jdata
|
27 |
+
|
28 |
+
|
29 |
+
def local_css(css_path):
|
30 |
+
with open(css_path) as f:
|
31 |
+
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
|
32 |
+
|
33 |
+
|
34 |
+
def remote_css(css_url):
|
35 |
+
st.markdown(f'<link href="{css_url}" rel="stylesheet">', unsafe_allow_html=True)
|