bjorn-hommel
commited on
Commit
•
dcfe827
1
Parent(s):
263b2c2
added input hash; excluding init input from db write
Browse files- app.py +15 -4
- requirements.txt +1 -0
- utils.py +8 -1
app.py
CHANGED
@@ -106,14 +106,21 @@ def show_demo(placeholder):
|
|
106 |
if 'input_data' in st.session_state:
|
107 |
|
108 |
if 'yaml_dict' in locals():
|
|
|
|
|
|
|
109 |
payload = {
|
110 |
'user_id': st.session_state.user_id,
|
111 |
'timestap': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
112 |
-
'
|
|
|
113 |
}
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
117 |
|
118 |
tab1, tab2, tab3 = st.tabs(["Item Correlations", "Scale Correlations", "Scale Reliabilities"])
|
119 |
|
@@ -233,6 +240,10 @@ def main():
|
|
233 |
with open('sample_input.yaml', 'r') as file:
|
234 |
try:
|
235 |
st.session_state['input_yaml'] = file.read()
|
|
|
|
|
|
|
|
|
236 |
except Exception as error:
|
237 |
print(error)
|
238 |
|
|
|
106 |
if 'input_data' in st.session_state:
|
107 |
|
108 |
if 'yaml_dict' in locals():
|
109 |
+
|
110 |
+
input_data_serialized = utils.serialize_data(yaml_dict)
|
111 |
+
input_data_hashed = utils.hash(input_data_serialized)
|
112 |
payload = {
|
113 |
'user_id': st.session_state.user_id,
|
114 |
'timestap': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
115 |
+
'input_hash': input_data_hashed,
|
116 |
+
'input_data': input_data_serialized
|
117 |
}
|
118 |
+
|
119 |
+
if st.session_state['init_input_hash'] != input_data_hashed:
|
120 |
+
# not logging default example
|
121 |
+
if os.environ.get('remote_model_path'):
|
122 |
+
# not logging locally
|
123 |
+
db.write_to_db(st.session_state.db, payload)
|
124 |
|
125 |
tab1, tab2, tab3 = st.tabs(["Item Correlations", "Scale Correlations", "Scale Reliabilities"])
|
126 |
|
|
|
240 |
with open('sample_input.yaml', 'r') as file:
|
241 |
try:
|
242 |
st.session_state['input_yaml'] = file.read()
|
243 |
+
init_input_dict = yaml.safe_load(st.session_state['input_yaml'])
|
244 |
+
init_input_serialized = utils.serialize_data(init_input_dict)
|
245 |
+
init_input_hashed = utils.hash(init_input_serialized)
|
246 |
+
st.session_state['init_input_hash'] = init_input_hashed
|
247 |
except Exception as error:
|
248 |
print(error)
|
249 |
|
requirements.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
torch
|
|
|
2 |
pandas==2.2.0
|
3 |
numpy==1.26.3
|
4 |
sentence_transformers==2.7.0
|
|
|
1 |
torch
|
2 |
+
hashlib
|
3 |
pandas==2.2.0
|
4 |
numpy==1.26.3
|
5 |
sentence_transformers==2.7.0
|
utils.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import cleantext
|
2 |
import ftfy
|
3 |
import json
|
|
|
4 |
from io import StringIO
|
5 |
from datetime import datetime
|
6 |
|
@@ -31,4 +32,10 @@ def serialize_data(data):
|
|
31 |
if isinstance(o, datetime):
|
32 |
return o.__str__()
|
33 |
|
34 |
-
return json.dumps(data, default=converter)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import cleantext
|
2 |
import ftfy
|
3 |
import json
|
4 |
+
import hashlib
|
5 |
from io import StringIO
|
6 |
from datetime import datetime
|
7 |
|
|
|
32 |
if isinstance(o, datetime):
|
33 |
return o.__str__()
|
34 |
|
35 |
+
return json.dumps(data, default=converter)
|
36 |
+
|
37 |
+
def hash(input):
|
38 |
+
sha1 = hashlib.sha1()
|
39 |
+
encoded = json.dumps([input], sort_keys=True).encode()
|
40 |
+
sha1.update(encoded)
|
41 |
+
return sha1.hexdigest()
|