Spaces:
Sleeping
Sleeping
rowankwang
commited on
Commit
•
b799b9a
1
Parent(s):
3e8cd27
redis
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
|
|
2 |
import json
|
3 |
from streamlit_shortcuts import add_keyboard_shortcuts
|
4 |
import random
|
|
|
5 |
|
6 |
st.set_page_config(layout="wide")
|
7 |
|
@@ -20,25 +21,66 @@ st.set_page_config(layout="wide")
|
|
20 |
|
21 |
file_path = 'grid_eval_gpt4o.json'
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
# Load your data
|
24 |
@st.cache_data()
|
25 |
def load_data():
|
26 |
with open(file_path, 'r') as file:
|
27 |
data = json.load(file)
|
28 |
-
# random.shuffle(data)
|
29 |
-
# data = data[]
|
30 |
return data
|
31 |
|
32 |
def save_data(data):
|
33 |
print(file_path.split(".json")[0])
|
34 |
with open(f"{file_path.split('.json')[0]}_graded.json", 'w') as file:
|
35 |
json.dump(data, file, indent=4)
|
36 |
-
|
37 |
def download_json(data):
|
38 |
return json.dumps(data, indent=4)
|
39 |
|
40 |
-
|
|
|
|
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
for query in data:
|
43 |
for result in query['results']:
|
44 |
if 'agree' not in result:
|
@@ -80,7 +122,7 @@ def display_query():
|
|
80 |
# Navigation bar
|
81 |
global current_query
|
82 |
|
83 |
-
st.session_state.graded_queries = sum(query.get('status', None)
|
84 |
print(f"Current Query Index: {st.session_state.current_query_index} | Graded Queries: {st.session_state.graded_queries} | Total Queries: {len(st.session_state.data)} | Current Query Status {current_query.get('status', None)}")
|
85 |
col1, col2 = st.columns([4, 2], gap="small")
|
86 |
with col1:
|
@@ -90,7 +132,7 @@ def display_query():
|
|
90 |
st.rerun()
|
91 |
st.progress((st.session_state.current_query_index + 1) / len(st.session_state.data))
|
92 |
with col2:
|
93 |
-
col1, col2, col3, col4 = st.columns([
|
94 |
with col1:
|
95 |
if st.button('Next'):
|
96 |
if st.session_state.current_query_index < len(st.session_state.data) - 1:
|
@@ -99,10 +141,12 @@ def display_query():
|
|
99 |
with col2:
|
100 |
if st.button('Skip'):
|
101 |
current_query['status'] = 'skipped'
|
|
|
102 |
next_query()
|
103 |
with col3:
|
104 |
if st.button('Junk'):
|
105 |
current_query['status'] = 'nonsense'
|
|
|
106 |
next_query()
|
107 |
with col4:
|
108 |
# Example button for downloading data
|
@@ -112,6 +156,11 @@ def display_query():
|
|
112 |
file_name="graded_data.json",
|
113 |
mime="application/json"
|
114 |
)
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
index = st.text_input(f"At index {st.session_state.current_query_index + 1}. Graded: {st.session_state.graded_queries}/{len(st.session_state.data)}", placeholder="Go to index:")
|
117 |
if index:
|
@@ -126,15 +175,17 @@ def display_query():
|
|
126 |
st.error("Please enter a valid integer.")
|
127 |
|
128 |
if st.session_state.graded_queries >= len(data):
|
129 |
-
save_data(st.session_state.data)
|
130 |
-
st.success(f"{len(data)} Queries graded
|
131 |
|
132 |
st.markdown(result_box_style, unsafe_allow_html=True)
|
133 |
|
134 |
st.header(f"Query: {current_query['query']}")
|
135 |
-
status_color = 'green' if current_query.get('status', None)
|
136 |
-
st.markdown(f"{current_query['grid_pos_str']} | Query Grade: <b style='color: {status_color};'>{'
|
137 |
-
st.
|
|
|
|
|
138 |
st.subheader("Results:")
|
139 |
for index, result in enumerate(current_query['results']):
|
140 |
st.markdown(f"<div class='rounded-box'>", unsafe_allow_html=True)
|
@@ -163,6 +214,7 @@ col1, col2 = st.columns([5, 1], gap="small")
|
|
163 |
with col2:
|
164 |
if st.button('Mark Done and Go to Next'):
|
165 |
current_query['status'] = 'graded'
|
|
|
166 |
next_query()
|
167 |
|
168 |
add_keyboard_shortcuts({
|
@@ -174,3 +226,9 @@ add_keyboard_shortcuts({
|
|
174 |
add_keyboard_shortcuts({
|
175 |
'n': 'Next',
|
176 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import json
|
3 |
from streamlit_shortcuts import add_keyboard_shortcuts
|
4 |
import random
|
5 |
+
import requests
|
6 |
|
7 |
st.set_page_config(layout="wide")
|
8 |
|
|
|
21 |
|
22 |
file_path = 'grid_eval_gpt4o.json'
|
23 |
|
24 |
+
@st.cache_data()
|
25 |
+
def fetch_data(fetch_url, num_samples=10):
|
26 |
+
payload = {
|
27 |
+
'num_samples': num_samples
|
28 |
+
}
|
29 |
+
headers = {
|
30 |
+
'Content-Type': 'application/json'
|
31 |
+
}
|
32 |
+
response = requests.post(fetch_url, json=payload, headers=headers)
|
33 |
+
if response.status_code == 200:
|
34 |
+
data = response.json()
|
35 |
+
return data
|
36 |
+
else:
|
37 |
+
st.error(f"Failed to fetch data: {response.status_code}")
|
38 |
+
return None
|
39 |
+
|
40 |
+
def update_data(query, new_grade_result):
|
41 |
+
payload = {
|
42 |
+
'query': query,
|
43 |
+
'newGradeResult': new_grade_result
|
44 |
+
}
|
45 |
+
headers = {
|
46 |
+
'Content-Type': 'application/json'
|
47 |
+
}
|
48 |
+
response = requests.put(URL + "update", json=payload, headers=headers)
|
49 |
+
if response.status_code != 200:
|
50 |
+
st.error(f"Failed to update data: {response.status_code}")
|
51 |
+
|
52 |
+
def get_new_grade_result_from_data(data):
|
53 |
+
new_grade_result = {
|
54 |
+
'status': data['status'],
|
55 |
+
'results': [{'url' : result['url'], 'agree': result['agree']} for result in data['results']]
|
56 |
+
}
|
57 |
+
return new_grade_result
|
58 |
+
|
59 |
+
##https://synthetic-data-framework.vercel.app/samples
|
60 |
# Load your data
|
61 |
@st.cache_data()
|
62 |
def load_data():
|
63 |
with open(file_path, 'r') as file:
|
64 |
data = json.load(file)
|
|
|
|
|
65 |
return data
|
66 |
|
67 |
def save_data(data):
|
68 |
print(file_path.split(".json")[0])
|
69 |
with open(f"{file_path.split('.json')[0]}_graded.json", 'w') as file:
|
70 |
json.dump(data, file, indent=4)
|
|
|
71 |
def download_json(data):
|
72 |
return json.dumps(data, indent=4)
|
73 |
|
74 |
+
NUM_SAMPLES = 5
|
75 |
+
URL = "https://synthetic-data-framework.vercel.app/"
|
76 |
+
data = fetch_data(URL + "samples", num_samples=NUM_SAMPLES)
|
77 |
|
78 |
+
def refresh_data():
|
79 |
+
fetch_data.clear(URL, NUM_SAMPLES)
|
80 |
+
st.session_state.data = fetch_data(URL + "samples", num_samples=NUM_SAMPLES)
|
81 |
+
st.session_state.current_query_index = 0
|
82 |
+
st.session_state.graded_queries = 0
|
83 |
+
|
84 |
for query in data:
|
85 |
for result in query['results']:
|
86 |
if 'agree' not in result:
|
|
|
122 |
# Navigation bar
|
123 |
global current_query
|
124 |
|
125 |
+
st.session_state.graded_queries = sum(query.get('status', None) == 'graded' for query in st.session_state.data)
|
126 |
print(f"Current Query Index: {st.session_state.current_query_index} | Graded Queries: {st.session_state.graded_queries} | Total Queries: {len(st.session_state.data)} | Current Query Status {current_query.get('status', None)}")
|
127 |
col1, col2 = st.columns([4, 2], gap="small")
|
128 |
with col1:
|
|
|
132 |
st.rerun()
|
133 |
st.progress((st.session_state.current_query_index + 1) / len(st.session_state.data))
|
134 |
with col2:
|
135 |
+
col1, col2, col3, col4, col5 = st.columns([2, 2, 2, 3, 3], gap = "small")
|
136 |
with col1:
|
137 |
if st.button('Next'):
|
138 |
if st.session_state.current_query_index < len(st.session_state.data) - 1:
|
|
|
141 |
with col2:
|
142 |
if st.button('Skip'):
|
143 |
current_query['status'] = 'skipped'
|
144 |
+
update_data(current_query['query'], get_new_grade_result_from_data(current_query))
|
145 |
next_query()
|
146 |
with col3:
|
147 |
if st.button('Junk'):
|
148 |
current_query['status'] = 'nonsense'
|
149 |
+
update_data(current_query['query'], get_new_grade_result_from_data(current_query))
|
150 |
next_query()
|
151 |
with col4:
|
152 |
# Example button for downloading data
|
|
|
156 |
file_name="graded_data.json",
|
157 |
mime="application/json"
|
158 |
)
|
159 |
+
|
160 |
+
with col5:
|
161 |
+
if st.button('Renew'):
|
162 |
+
refresh_data()
|
163 |
+
st.rerun()
|
164 |
|
165 |
index = st.text_input(f"At index {st.session_state.current_query_index + 1}. Graded: {st.session_state.graded_queries}/{len(st.session_state.data)}", placeholder="Go to index:")
|
166 |
if index:
|
|
|
175 |
st.error("Please enter a valid integer.")
|
176 |
|
177 |
if st.session_state.graded_queries >= len(data):
|
178 |
+
# save_data(st.session_state.data)
|
179 |
+
st.success(f"{len(data)} Queries graded!")
|
180 |
|
181 |
st.markdown(result_box_style, unsafe_allow_html=True)
|
182 |
|
183 |
st.header(f"Query: {current_query['query']}")
|
184 |
+
status_color = 'green' if current_query.get('status', None) == "graded" else 'red'
|
185 |
+
st.markdown(f"{current_query['metadata']['grid_pos_str']} | Query Grade: <b style='color: {status_color};'>{current_query.get('status', None)}</b>", unsafe_allow_html = True)
|
186 |
+
with st.expander("Model's Query Gen Reasoning Trace"):
|
187 |
+
st.markdown(f"{current_query['metadata']['reasoning_trace'][0]}")
|
188 |
+
|
189 |
st.subheader("Results:")
|
190 |
for index, result in enumerate(current_query['results']):
|
191 |
st.markdown(f"<div class='rounded-box'>", unsafe_allow_html=True)
|
|
|
214 |
with col2:
|
215 |
if st.button('Mark Done and Go to Next'):
|
216 |
current_query['status'] = 'graded'
|
217 |
+
update_data(current_query['query'], get_new_grade_result_from_data(current_query))
|
218 |
next_query()
|
219 |
|
220 |
add_keyboard_shortcuts({
|
|
|
226 |
add_keyboard_shortcuts({
|
227 |
'n': 'Next',
|
228 |
})
|
229 |
+
add_keyboard_shortcuts({
|
230 |
+
'd': 'Download',
|
231 |
+
})
|
232 |
+
add_keyboard_shortcuts({
|
233 |
+
'r': 'Renew',
|
234 |
+
})
|