Spaces:
Sleeping
Sleeping
Commit
·
e4dcaa1
1
Parent(s):
686a2cd
updated app.py
Browse files
app.py
CHANGED
|
@@ -76,9 +76,12 @@ def init_files():
|
|
| 76 |
sync_pull()
|
| 77 |
for f in [LABEL_FILE, VERIFY_FILE, SKIP_FILE]:
|
| 78 |
if not os.path.exists(f):
|
| 79 |
-
if f == LABEL_FILE:
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
| 82 |
pd.DataFrame(columns=cols).to_csv(f, index=False)
|
| 83 |
|
| 84 |
if not os.path.exists(URL_FILE):
|
|
@@ -151,7 +154,8 @@ def get_saved_values(gid, mode):
|
|
| 151 |
if mode == "label":
|
| 152 |
saved_data[row['url']] = {"score": row['score'], "label": row['label']}
|
| 153 |
else:
|
| 154 |
-
|
|
|
|
| 155 |
except: pass
|
| 156 |
return saved_data
|
| 157 |
|
|
@@ -194,12 +198,9 @@ def render_workspace(mode, history, specific_index=None, move_back=False):
|
|
| 194 |
candidates = []
|
| 195 |
for i, gid in enumerate(all_groups):
|
| 196 |
if gid in s_done: continue
|
| 197 |
-
|
| 198 |
is_ready = False
|
| 199 |
-
if mode == "label" and gid not in l_done:
|
| 200 |
-
|
| 201 |
-
elif mode == "verify" and gid in l_done and gid not in v_done:
|
| 202 |
-
is_ready = True
|
| 203 |
|
| 204 |
if is_ready:
|
| 205 |
candidates.append((i, gid))
|
|
@@ -254,9 +255,13 @@ def render_workspace(mode, history, specific_index=None, move_back=False):
|
|
| 254 |
updates[c_chk] = gr.update(visible=False)
|
| 255 |
updates[c_lbl] = gr.update(visible=False)
|
| 256 |
else:
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
updates[c_drp] = gr.update(visible=True, value=v_lbl)
|
| 261 |
updates[c_chk] = gr.update(visible=True, value=v_chk)
|
| 262 |
else:
|
|
@@ -275,8 +280,10 @@ def save_data(mode, history, urls, *args):
|
|
| 275 |
for i, u in enumerate(urls):
|
| 276 |
base = i * 4
|
| 277 |
sc, lbl, chk = args[base], args[base+1], args[base+2]
|
| 278 |
-
if mode == "label":
|
| 279 |
-
|
|
|
|
|
|
|
| 280 |
|
| 281 |
fname = LABEL_FILE if mode == "label" else VERIFY_FILE
|
| 282 |
with FileLock(LOCK_FILE):
|
|
|
|
| 76 |
sync_pull()
|
| 77 |
for f in [LABEL_FILE, VERIFY_FILE, SKIP_FILE]:
|
| 78 |
if not os.path.exists(f):
|
| 79 |
+
if f == LABEL_FILE:
|
| 80 |
+
cols = ["timestamp", "user", "group_id", "url", "score", "label"]
|
| 81 |
+
elif f == VERIFY_FILE:
|
| 82 |
+
cols = ["timestamp", "user", "group_id", "url", "is_correct", "corrected_label", "corrected_score"]
|
| 83 |
+
else:
|
| 84 |
+
cols = ["timestamp", "user", "group_id"]
|
| 85 |
pd.DataFrame(columns=cols).to_csv(f, index=False)
|
| 86 |
|
| 87 |
if not os.path.exists(URL_FILE):
|
|
|
|
| 154 |
if mode == "label":
|
| 155 |
saved_data[row['url']] = {"score": row['score'], "label": row['label']}
|
| 156 |
else:
|
| 157 |
+
sc = row['corrected_score'] if 'corrected_score' in row else 5
|
| 158 |
+
saved_data[row['url']] = {"is_correct": row['is_correct'], "label": row['corrected_label'], "score": sc}
|
| 159 |
except: pass
|
| 160 |
return saved_data
|
| 161 |
|
|
|
|
| 198 |
candidates = []
|
| 199 |
for i, gid in enumerate(all_groups):
|
| 200 |
if gid in s_done: continue
|
|
|
|
| 201 |
is_ready = False
|
| 202 |
+
if mode == "label" and gid not in l_done: is_ready = True
|
| 203 |
+
elif mode == "verify" and gid in l_done and gid not in v_done: is_ready = True
|
|
|
|
|
|
|
| 204 |
|
| 205 |
if is_ready:
|
| 206 |
candidates.append((i, gid))
|
|
|
|
| 255 |
updates[c_chk] = gr.update(visible=False)
|
| 256 |
updates[c_lbl] = gr.update(visible=False)
|
| 257 |
else:
|
| 258 |
+
prev_lbl = r1_vals.get(u, {}).get('label', "Unknown")
|
| 259 |
+
prev_sc = r1_vals.get(u, {}).get('score', 0)
|
| 260 |
+
|
| 261 |
+
display_score = v_sc if u in saved_vals else prev_sc
|
| 262 |
+
|
| 263 |
+
updates[c_sld] = gr.update(visible=True, value=display_score)
|
| 264 |
+
updates[c_lbl] = gr.update(visible=True, value=f"**Labeled:** {prev_lbl} | **Score:** {prev_sc}")
|
| 265 |
updates[c_drp] = gr.update(visible=True, value=v_lbl)
|
| 266 |
updates[c_chk] = gr.update(visible=True, value=v_chk)
|
| 267 |
else:
|
|
|
|
| 280 |
for i, u in enumerate(urls):
|
| 281 |
base = i * 4
|
| 282 |
sc, lbl, chk = args[base], args[base+1], args[base+2]
|
| 283 |
+
if mode == "label":
|
| 284 |
+
rows.append([ts, "user", gid, u, sc, lbl])
|
| 285 |
+
else:
|
| 286 |
+
rows.append([ts, "user", gid, u, chk, lbl, sc])
|
| 287 |
|
| 288 |
fname = LABEL_FILE if mode == "label" else VERIFY_FILE
|
| 289 |
with FileLock(LOCK_FILE):
|