Spaces:
Sleeping
Sleeping
Commit
·
c9e566c
1
Parent(s):
3c1b983
update app.py
Browse files
app.py
CHANGED
|
@@ -75,8 +75,7 @@ def get_ordered_groups():
|
|
| 75 |
try: gid = u.split("-m")[0].split("/")[-1]
|
| 76 |
except: gid = "unknown"
|
| 77 |
if gid not in seen:
|
| 78 |
-
groups.append(gid)
|
| 79 |
-
seen.add(gid)
|
| 80 |
return groups
|
| 81 |
|
| 82 |
def get_flagged_groups():
|
|
@@ -84,6 +83,7 @@ def get_flagged_groups():
|
|
| 84 |
try:
|
| 85 |
df = pd.read_csv(LABEL_FILE)
|
| 86 |
if df.empty: return []
|
|
|
|
| 87 |
df = df.drop_duplicates(subset=['url'], keep='last')
|
| 88 |
errors = df[(df['score'] == 10) & (df['label'] != 'living_room')]
|
| 89 |
return errors['group_id'].unique().tolist()
|
|
@@ -114,14 +114,16 @@ def get_stats_text():
|
|
| 114 |
df_l = pd.read_csv(LABEL_FILE).drop_duplicates(subset=['url'], keep='last')
|
| 115 |
l = len(df_l['group_id'].unique())
|
| 116 |
except: l = 0
|
| 117 |
-
err_msg = f" | ⚠️ **Fix
|
| 118 |
-
return f"**
|
| 119 |
|
| 120 |
def render_workspace(mode, history, specific_index=None, move_back=False):
|
| 121 |
all_ordered = get_ordered_groups()
|
| 122 |
flagged_pool = get_flagged_groups()
|
| 123 |
|
|
|
|
| 124 |
target_gid = None
|
|
|
|
| 125 |
if specific_index is not None:
|
| 126 |
if 0 <= specific_index < len(all_ordered): target_gid = all_ordered[specific_index]
|
| 127 |
elif move_back and len(history) > 1:
|
|
@@ -136,12 +138,13 @@ def render_workspace(mode, history, specific_index=None, move_back=False):
|
|
| 136 |
except: l_done, v_done = set(), set()
|
| 137 |
|
| 138 |
if mode == "fix":
|
| 139 |
-
candidates = flagged_pool
|
|
|
|
| 140 |
else:
|
| 141 |
candidates = [g for g in all_ordered if (mode=="label" and g not in l_done) or (mode=="verify" and g in l_done and g not in v_done)]
|
| 142 |
|
| 143 |
if not candidates:
|
| 144 |
-
return {screen_menu: gr.update(visible=True), screen_work: gr.update(visible=False), log_box: "
|
| 145 |
target_gid = candidates[0]
|
| 146 |
|
| 147 |
urls = get_group_urls(target_gid)
|
|
@@ -150,20 +153,20 @@ def render_workspace(mode, history, specific_index=None, move_back=False):
|
|
| 150 |
r1_vals = get_saved_values(target_gid, "label") if mode == "verify" else {}
|
| 151 |
target_idx = all_ordered.index(target_gid)
|
| 152 |
|
| 153 |
-
with ThreadPoolExecutor(max_workers=MAX_IMAGES) as
|
| 154 |
def fetch(u):
|
| 155 |
try:
|
| 156 |
res = requests.get(u, timeout=3, headers={'User-Agent': 'Mozilla/5.0'})
|
| 157 |
img = Image.open(BytesIO(res.content))
|
| 158 |
img.thumbnail(THUMB_SIZE); return img
|
| 159 |
except: return None
|
| 160 |
-
processed_images = list(
|
| 161 |
|
| 162 |
updates = {
|
| 163 |
screen_menu: gr.update(visible=False), screen_work: gr.update(visible=True),
|
| 164 |
header_md: f"# {mode.upper()} Property #{target_idx + 1} ({target_gid})",
|
| 165 |
state_urls: urls, state_hist: history, state_idx: target_idx,
|
| 166 |
-
top_stats: get_stats_text(), log_box: f"
|
| 167 |
}
|
| 168 |
|
| 169 |
for i in range(MAX_IMAGES):
|
|
@@ -172,7 +175,7 @@ def render_workspace(mode, history, specific_index=None, move_back=False):
|
|
| 172 |
if i < len(urls):
|
| 173 |
u = urls[i]
|
| 174 |
updates[img_objs[i]] = gr.update(value=processed_images[i], visible=True)
|
| 175 |
-
v_sc = saved_vals.get(u, {}).get('score', 5)
|
| 176 |
v_lbl = saved_vals.get(u, {}).get('label', "living_room")
|
| 177 |
is_err = (v_sc == 10 and v_lbl != "living_room")
|
| 178 |
|
|
@@ -180,7 +183,7 @@ def render_workspace(mode, history, specific_index=None, move_back=False):
|
|
| 180 |
updates[c_sld] = gr.update(visible=True, value=v_sc, interactive=True)
|
| 181 |
updates[c_drp] = gr.update(visible=True, value=v_lbl, interactive=True)
|
| 182 |
updates[c_chk] = gr.update(visible=False)
|
| 183 |
-
updates[c_lbl] = gr.update(visible=True if is_err else False, value="<span style='color:red'>⚠️ Score 10
|
| 184 |
else:
|
| 185 |
p_lbl, p_sc = r1_vals.get(u, {}).get('label', "?"), r1_vals.get(u, {}).get('score', "?")
|
| 186 |
updates[c_sld] = gr.update(visible=True, value=v_sc if u in saved_vals else p_sc)
|
|
@@ -199,8 +202,8 @@ def save_data(mode, history, urls, *args):
|
|
| 199 |
rows = []
|
| 200 |
for i, u in enumerate(urls):
|
| 201 |
sc, lbl, chk = args[i*4], args[i*4+1], args[i*4+2]
|
| 202 |
-
if mode in ["label", "fix"]: rows.append([ts, "user", gid, u, sc, lbl])
|
| 203 |
-
else: rows.append([ts, "user", gid, u, chk, lbl, sc])
|
| 204 |
|
| 205 |
fname = LABEL_FILE if mode in ["label", "fix"] else VERIFY_FILE
|
| 206 |
with FileLock(LOCK_FILE):
|
|
|
|
| 75 |
try: gid = u.split("-m")[0].split("/")[-1]
|
| 76 |
except: gid = "unknown"
|
| 77 |
if gid not in seen:
|
| 78 |
+
groups.append(gid); seen.add(gid)
|
|
|
|
| 79 |
return groups
|
| 80 |
|
| 81 |
def get_flagged_groups():
|
|
|
|
| 83 |
try:
|
| 84 |
df = pd.read_csv(LABEL_FILE)
|
| 85 |
if df.empty: return []
|
| 86 |
+
df['score'] = pd.to_numeric(df['score'], errors='coerce')
|
| 87 |
df = df.drop_duplicates(subset=['url'], keep='last')
|
| 88 |
errors = df[(df['score'] == 10) & (df['label'] != 'living_room')]
|
| 89 |
return errors['group_id'].unique().tolist()
|
|
|
|
| 114 |
df_l = pd.read_csv(LABEL_FILE).drop_duplicates(subset=['url'], keep='last')
|
| 115 |
l = len(df_l['group_id'].unique())
|
| 116 |
except: l = 0
|
| 117 |
+
err_msg = f" | ⚠️ **Fix:** {len(flagged)}" if flagged else ""
|
| 118 |
+
return f"**Total:** {len(all_gids)} | **Labeled:** {l}{err_msg}"
|
| 119 |
|
| 120 |
def render_workspace(mode, history, specific_index=None, move_back=False):
|
| 121 |
all_ordered = get_ordered_groups()
|
| 122 |
flagged_pool = get_flagged_groups()
|
| 123 |
|
| 124 |
+
current_gid = history[-1] if history else None
|
| 125 |
target_gid = None
|
| 126 |
+
|
| 127 |
if specific_index is not None:
|
| 128 |
if 0 <= specific_index < len(all_ordered): target_gid = all_ordered[specific_index]
|
| 129 |
elif move_back and len(history) > 1:
|
|
|
|
| 138 |
except: l_done, v_done = set(), set()
|
| 139 |
|
| 140 |
if mode == "fix":
|
| 141 |
+
candidates = [g for g in flagged_pool if g != current_gid]
|
| 142 |
+
if not candidates and flagged_pool: candidates = flagged_pool
|
| 143 |
else:
|
| 144 |
candidates = [g for g in all_ordered if (mode=="label" and g not in l_done) or (mode=="verify" and g in l_done and g not in v_done)]
|
| 145 |
|
| 146 |
if not candidates:
|
| 147 |
+
return {screen_menu: gr.update(visible=True), screen_work: gr.update(visible=False), log_box: "No more properties found in this mode."}
|
| 148 |
target_gid = candidates[0]
|
| 149 |
|
| 150 |
urls = get_group_urls(target_gid)
|
|
|
|
| 153 |
r1_vals = get_saved_values(target_gid, "label") if mode == "verify" else {}
|
| 154 |
target_idx = all_ordered.index(target_gid)
|
| 155 |
|
| 156 |
+
with ThreadPoolExecutor(max_workers=MAX_IMAGES) as ex:
|
| 157 |
def fetch(u):
|
| 158 |
try:
|
| 159 |
res = requests.get(u, timeout=3, headers={'User-Agent': 'Mozilla/5.0'})
|
| 160 |
img = Image.open(BytesIO(res.content))
|
| 161 |
img.thumbnail(THUMB_SIZE); return img
|
| 162 |
except: return None
|
| 163 |
+
processed_images = list(ex.map(fetch, urls))
|
| 164 |
|
| 165 |
updates = {
|
| 166 |
screen_menu: gr.update(visible=False), screen_work: gr.update(visible=True),
|
| 167 |
header_md: f"# {mode.upper()} Property #{target_idx + 1} ({target_gid})",
|
| 168 |
state_urls: urls, state_hist: history, state_idx: target_idx,
|
| 169 |
+
top_stats: get_stats_text(), log_box: f"Viewing {target_gid}"
|
| 170 |
}
|
| 171 |
|
| 172 |
for i in range(MAX_IMAGES):
|
|
|
|
| 175 |
if i < len(urls):
|
| 176 |
u = urls[i]
|
| 177 |
updates[img_objs[i]] = gr.update(value=processed_images[i], visible=True)
|
| 178 |
+
v_sc = int(float(saved_vals.get(u, {}).get('score', 5)))
|
| 179 |
v_lbl = saved_vals.get(u, {}).get('label', "living_room")
|
| 180 |
is_err = (v_sc == 10 and v_lbl != "living_room")
|
| 181 |
|
|
|
|
| 183 |
updates[c_sld] = gr.update(visible=True, value=v_sc, interactive=True)
|
| 184 |
updates[c_drp] = gr.update(visible=True, value=v_lbl, interactive=True)
|
| 185 |
updates[c_chk] = gr.update(visible=False)
|
| 186 |
+
updates[c_lbl] = gr.update(visible=True if is_err else False, value="<span style='color:red'>⚠️ ERROR: Score 10 is Living Room ONLY</span>")
|
| 187 |
else:
|
| 188 |
p_lbl, p_sc = r1_vals.get(u, {}).get('label', "?"), r1_vals.get(u, {}).get('score', "?")
|
| 189 |
updates[c_sld] = gr.update(visible=True, value=v_sc if u in saved_vals else p_sc)
|
|
|
|
| 202 |
rows = []
|
| 203 |
for i, u in enumerate(urls):
|
| 204 |
sc, lbl, chk = args[i*4], args[i*4+1], args[i*4+2]
|
| 205 |
+
if mode in ["label", "fix"]: rows.append([ts, "user", gid, u, int(sc), lbl])
|
| 206 |
+
else: rows.append([ts, "user", gid, u, chk, lbl, int(sc)])
|
| 207 |
|
| 208 |
fname = LABEL_FILE if mode in ["label", "fix"] else VERIFY_FILE
|
| 209 |
with FileLock(LOCK_FILE):
|