mishtert commited on
Commit
8fb3b4a
1 Parent(s): 76645e5

Upload utils.py

Browse files
Files changed (1) hide show
  1. utils.py +40 -0
utils.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ import json
3
+ import streamlit as st
4
+
5
+
6
+ def load_image_from_local(image_path, image_resize=None):
7
+ image = Image.open(image_path)
8
+
9
+ if isinstance(image_resize, tuple):
10
+ image = image.resize(image_resize)
11
+ return image
12
+
13
+
14
+ # # reading the nct_ta dictionary
15
+ # with open('asset/data/input_sentence.json') as f:
16
+ # data = f.read()
17
+ # sample_sentences = json.loads(data) # load dict
18
+ # print(sample_sentences)
19
+
20
+ def unique_list(seq):
21
+ seen = set()
22
+ seen_add = seen.add
23
+ return [x for x in seq if not (x in seen or seen_add(x))]
24
+
25
+
26
+ def pure_comma_separation(list_str, return_list=True):
27
+ r = unique_list([item.strip() for item in list_str.lower().split(",") if item.strip()])
28
+ if return_list:
29
+ return r
30
+ return ", ".join(r)
31
+
32
+
33
+
34
+ def local_css(css_path):
35
+ with open(css_path) as f:
36
+ st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
37
+
38
+
39
+ def remote_css(css_url):
40
+ st.markdown(f'<link href="{css_url}" rel="stylesheet">', unsafe_allow_html=True)