sutdaiday
commited on
Commit
·
d3d19d6
0
Parent(s):
Initial Commit
Browse files- .gradio/certificate.pem +31 -0
- app.py +495 -0
- csv/craigslist.csv +21 -0
- csv/esconv.csv +21 -0
- requirements.txt +2 -0
.gradio/certificate.pem
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-----BEGIN CERTIFICATE-----
|
2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
7 |
+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
8 |
+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
|
9 |
+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
|
10 |
+
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
|
11 |
+
T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
|
12 |
+
B5T0Y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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import random, os, csv
|
4 |
+
|
5 |
+
# ─── Configuration ─────────────────────────────────────────────────────────────
|
6 |
+
DATASET_FILES = {
|
7 |
+
"ESConv": "./csv/esconv.csv",
|
8 |
+
"CraigslistBargain": "./csv/craigslist.csv",
|
9 |
+
}
|
10 |
+
|
11 |
+
# ─── Helper functions ──────────────────────────────────────────────────────────
|
12 |
+
def prepare_examples(user_id: str, dataset: str):
|
13 |
+
"""
|
14 |
+
Read CSV, create Ours-vs-[PPDPP|DPDP] pairs, shuffle + randomise L/R.
|
15 |
+
A deterministic seed (user_id+dataset) keeps the order stable for reloads.
|
16 |
+
"""
|
17 |
+
random.seed(f"{user_id}_{dataset}") # keeps order identical per user
|
18 |
+
df = pd.read_csv(DATASET_FILES[dataset])
|
19 |
+
pairs = []
|
20 |
+
for _, row in df.iterrows():
|
21 |
+
for other in ["PPDPP", "DPDP"]:
|
22 |
+
pairs.append(
|
23 |
+
dict(
|
24 |
+
background=row["Background Information"],
|
25 |
+
ours=row["Ours"],
|
26 |
+
other=row[other],
|
27 |
+
other_name=other,
|
28 |
+
)
|
29 |
+
)
|
30 |
+
random.shuffle(pairs)
|
31 |
+
|
32 |
+
prepared = []
|
33 |
+
for item in pairs:
|
34 |
+
if random.random() < 0.5:
|
35 |
+
left_text, right_text = item["ours"], item["other"]
|
36 |
+
left_name, right_name = "Ours", item["other_name"]
|
37 |
+
else:
|
38 |
+
left_text, right_text = item["other"], item["ours"]
|
39 |
+
left_name, right_name = item["other_name"], "Ours"
|
40 |
+
prepared.append(
|
41 |
+
dict(
|
42 |
+
background=item["background"],
|
43 |
+
left_text=left_text,
|
44 |
+
right_text=right_text,
|
45 |
+
left_name=left_name,
|
46 |
+
right_name=right_name,
|
47 |
+
)
|
48 |
+
)
|
49 |
+
return prepared
|
50 |
+
|
51 |
+
|
52 |
+
def save_all_to_csv(user_id, dataset, examples, responses):
|
53 |
+
"""Rewrite CSV completely (idempotent)."""
|
54 |
+
if not responses:
|
55 |
+
return
|
56 |
+
filename = f"{user_id}_{dataset}_results.csv"
|
57 |
+
metrics = list(next(iter(responses.values())).keys())
|
58 |
+
header = (
|
59 |
+
["UserID", "Dataset", "Background", "Response A Method", "Response B Method"]
|
60 |
+
+ metrics
|
61 |
+
)
|
62 |
+
with open(filename, "w", newline="", encoding="utf-8") as f:
|
63 |
+
writer = csv.DictWriter(f, fieldnames=header)
|
64 |
+
writer.writeheader()
|
65 |
+
for idx in sorted(responses):
|
66 |
+
ex = examples[idx]
|
67 |
+
row = dict(
|
68 |
+
UserID=user_id,
|
69 |
+
Dataset=dataset,
|
70 |
+
Background=ex["background"],
|
71 |
+
**{
|
72 |
+
"Response A Method": ex["left_name"],
|
73 |
+
"Response B Method": ex["right_name"],
|
74 |
+
},
|
75 |
+
)
|
76 |
+
row.update(responses[idx])
|
77 |
+
writer.writerow(row)
|
78 |
+
|
79 |
+
|
80 |
+
def load_responses_from_csv(user_id, dataset, examples):
|
81 |
+
"""
|
82 |
+
Reconstruct a {idx: metrics-dict} mapping from an existing results file.
|
83 |
+
Matching uses Background + response-method orientation to stay robust.
|
84 |
+
"""
|
85 |
+
filename = f"{user_id}_{dataset}_results.csv"
|
86 |
+
if not os.path.exists(filename):
|
87 |
+
return {}
|
88 |
+
|
89 |
+
df = pd.read_csv(filename)
|
90 |
+
|
91 |
+
# Build lookup: (background, a_method, b_method) → idx
|
92 |
+
idx_map = {
|
93 |
+
(ex["background"], ex["left_name"], ex["right_name"]): i
|
94 |
+
for i, ex in enumerate(examples)
|
95 |
+
}
|
96 |
+
|
97 |
+
responses = {}
|
98 |
+
for _, row in df.iterrows():
|
99 |
+
key = (row["Background"], row["Response A Method"], row["Response B Method"])
|
100 |
+
if key in idx_map:
|
101 |
+
idx = idx_map[key]
|
102 |
+
metric_cols = [
|
103 |
+
c
|
104 |
+
for c in row.keys()
|
105 |
+
if c
|
106 |
+
not in [
|
107 |
+
"UserID",
|
108 |
+
"Dataset",
|
109 |
+
"Background",
|
110 |
+
"Response A Method",
|
111 |
+
"Response B Method",
|
112 |
+
]
|
113 |
+
]
|
114 |
+
responses[idx] = {k: row[k] for k in metric_cols}
|
115 |
+
return responses
|
116 |
+
|
117 |
+
|
118 |
+
# ─── Panel-specific loaders ────────────────────────────────────────────────────
|
119 |
+
def es_load_example(idx, examples, responses):
|
120 |
+
ex = examples[idx]
|
121 |
+
prev = responses.get(idx, {})
|
122 |
+
return (
|
123 |
+
ex["background"],
|
124 |
+
ex["left_text"],
|
125 |
+
ex["right_text"],
|
126 |
+
f"Item {idx+1} of {len(examples)}",
|
127 |
+
prev.get("Identification"),
|
128 |
+
prev.get("Comforting"),
|
129 |
+
prev.get("Suggestion"),
|
130 |
+
prev.get("Overall"),
|
131 |
+
"", # error
|
132 |
+
)
|
133 |
+
|
134 |
+
|
135 |
+
def cb_load_example(idx, examples, responses):
|
136 |
+
ex = examples[idx]
|
137 |
+
prev = responses.get(idx, {})
|
138 |
+
return (
|
139 |
+
ex["background"],
|
140 |
+
ex["left_text"],
|
141 |
+
ex["right_text"],
|
142 |
+
f"Item {idx+1} of {len(examples)}",
|
143 |
+
prev.get("Persuasiveness"),
|
144 |
+
prev.get("Coherence"),
|
145 |
+
prev.get("Naturalness"),
|
146 |
+
prev.get("Overall"),
|
147 |
+
"", # error
|
148 |
+
)
|
149 |
+
|
150 |
+
|
151 |
+
# ─── Login & Logout ────────────────────────────────────────────────────────────
|
152 |
+
def login_fn(user_id, dataset):
|
153 |
+
if not user_id or not dataset:
|
154 |
+
raise gr.Error("Please enter your User ID and select a dataset.")
|
155 |
+
|
156 |
+
examples = prepare_examples(user_id, dataset)
|
157 |
+
responses = load_responses_from_csv(user_id, dataset, examples)
|
158 |
+
idx = 0
|
159 |
+
|
160 |
+
if dataset == "ESConv":
|
161 |
+
(
|
162 |
+
bg,
|
163 |
+
lft,
|
164 |
+
rgt,
|
165 |
+
prog,
|
166 |
+
ident,
|
167 |
+
com,
|
168 |
+
sug,
|
169 |
+
ovl,
|
170 |
+
err_es,
|
171 |
+
) = es_load_example(idx, examples, responses)
|
172 |
+
# CB placeholders
|
173 |
+
bg_cb = lft_cb = rgt_cb = prog_cb = ""
|
174 |
+
per = coh = nat = ovl_cb = None
|
175 |
+
err_cb = ""
|
176 |
+
else:
|
177 |
+
(
|
178 |
+
bg_cb,
|
179 |
+
lft_cb,
|
180 |
+
rgt_cb,
|
181 |
+
prog_cb,
|
182 |
+
per,
|
183 |
+
coh,
|
184 |
+
nat,
|
185 |
+
ovl_cb,
|
186 |
+
err_cb,
|
187 |
+
) = cb_load_example(idx, examples, responses)
|
188 |
+
# ESConv placeholders
|
189 |
+
bg = lft = rgt = prog = ""
|
190 |
+
ident = com = sug = ovl = None
|
191 |
+
err_es = ""
|
192 |
+
|
193 |
+
return (
|
194 |
+
gr.update(visible=False), # hide login panel
|
195 |
+
gr.update(visible=(dataset == "ESConv")),
|
196 |
+
gr.update(visible=(dataset == "CraigslistBargain")),
|
197 |
+
user_id, dataset, examples, idx, responses,
|
198 |
+
# ESConv outputs
|
199 |
+
bg, lft, rgt, prog, ident, com, sug, ovl, err_es,
|
200 |
+
# CB outputs
|
201 |
+
bg_cb, lft_cb, rgt_cb, prog_cb, per, coh, nat, ovl_cb, err_cb,
|
202 |
+
)
|
203 |
+
|
204 |
+
|
205 |
+
def logout_fn(user_id, dataset, examples, idx, responses):
|
206 |
+
# Save before quitting
|
207 |
+
if dataset:
|
208 |
+
save_all_to_csv(user_id, dataset, examples, responses)
|
209 |
+
|
210 |
+
# Empty / reset everything
|
211 |
+
return (
|
212 |
+
gr.update(visible=True), # show login
|
213 |
+
gr.update(visible=False), # hide es
|
214 |
+
gr.update(visible=False), # hide cb
|
215 |
+
"", "", [], 0, {}, # state vars reset
|
216 |
+
*[""] * 9, # ESConv component resets
|
217 |
+
*[""] * 10, # CB component resets
|
218 |
+
)
|
219 |
+
|
220 |
+
|
221 |
+
# ─── Navigation callback helpers ───────────────────────────────────────────────
|
222 |
+
def es_next_fn(user_id, dataset, examples, idx, responses, ident, com, sug, ovl):
|
223 |
+
if None in (ident, com, sug, ovl):
|
224 |
+
ex = examples[idx]
|
225 |
+
return (
|
226 |
+
ex["background"],
|
227 |
+
ex["left_text"],
|
228 |
+
ex["right_text"],
|
229 |
+
f"Item {idx+1} of {len(examples)}",
|
230 |
+
idx,
|
231 |
+
responses,
|
232 |
+
ident,
|
233 |
+
com,
|
234 |
+
sug,
|
235 |
+
ovl,
|
236 |
+
"All metrics must be answered before proceeding.",
|
237 |
+
)
|
238 |
+
|
239 |
+
responses[idx] = dict(
|
240 |
+
Identification=ident, Comforting=com, Suggestion=sug, Overall=ovl
|
241 |
+
)
|
242 |
+
save_all_to_csv(user_id, dataset, examples, responses)
|
243 |
+
idx += 1
|
244 |
+
|
245 |
+
if idx >= len(examples):
|
246 |
+
return ("🚩 Survey complete! Thank you.",) * 4 + (
|
247 |
+
idx,
|
248 |
+
responses,
|
249 |
+
None,
|
250 |
+
None,
|
251 |
+
None,
|
252 |
+
None,
|
253 |
+
"",
|
254 |
+
)
|
255 |
+
|
256 |
+
return es_load_example(idx, examples, responses)[:4] + (
|
257 |
+
idx,
|
258 |
+
responses,
|
259 |
+
) + es_load_example(idx, examples, responses)[4:]
|
260 |
+
|
261 |
+
|
262 |
+
def es_prev_fn(user_id, dataset, examples, idx, responses, ident, com, sug, ovl):
|
263 |
+
if None not in (ident, com, sug, ovl):
|
264 |
+
responses[idx] = dict(
|
265 |
+
Identification=ident, Comforting=com, Suggestion=sug, Overall=ovl
|
266 |
+
)
|
267 |
+
save_all_to_csv(user_id, dataset, examples, responses)
|
268 |
+
|
269 |
+
idx = max(0, idx - 1)
|
270 |
+
return es_load_example(idx, examples, responses)[:4] + (
|
271 |
+
idx,
|
272 |
+
responses,
|
273 |
+
) + es_load_example(idx, examples, responses)[4:]
|
274 |
+
|
275 |
+
|
276 |
+
def cb_next_fn(user_id, dataset, examples, idx, responses, per, coh, nat, ovl_cb):
|
277 |
+
if None in (per, coh, nat, ovl_cb):
|
278 |
+
ex = examples[idx]
|
279 |
+
return (
|
280 |
+
ex["background"],
|
281 |
+
ex["left_text"],
|
282 |
+
ex["right_text"],
|
283 |
+
f"Item {idx+1} of {len(examples)}",
|
284 |
+
idx,
|
285 |
+
responses,
|
286 |
+
per,
|
287 |
+
coh,
|
288 |
+
nat,
|
289 |
+
ovl_cb,
|
290 |
+
"All metrics must be answered before proceeding.",
|
291 |
+
)
|
292 |
+
|
293 |
+
responses[idx] = dict(
|
294 |
+
Persuasiveness=per, Coherence=coh, Naturalness=nat, Overall=ovl_cb
|
295 |
+
)
|
296 |
+
save_all_to_csv(user_id, dataset, examples, responses)
|
297 |
+
idx += 1
|
298 |
+
|
299 |
+
if idx >= len(examples):
|
300 |
+
return ("🚩 Survey complete! Thank you.",) * 5 + (None, "")
|
301 |
+
|
302 |
+
return cb_load_example(idx, examples, responses)[:4] + (
|
303 |
+
idx,
|
304 |
+
responses,
|
305 |
+
) + cb_load_example(idx, examples, responses)[4:]
|
306 |
+
|
307 |
+
|
308 |
+
def cb_prev_fn(user_id, dataset, examples, idx, responses, per, coh, nat, ovl_cb):
|
309 |
+
if None not in (per, coh, nat, ovl_cb):
|
310 |
+
responses[idx] = dict(
|
311 |
+
Persuasiveness=per, Coherence=coh, Naturalness=nat, Overall=ovl_cb
|
312 |
+
)
|
313 |
+
save_all_to_csv(user_id, dataset, examples, responses)
|
314 |
+
|
315 |
+
idx = max(0, idx - 1)
|
316 |
+
return cb_load_example(idx, examples, responses)[:4] + (
|
317 |
+
idx,
|
318 |
+
responses,
|
319 |
+
) + cb_load_example(idx, examples, responses)[4:]
|
320 |
+
|
321 |
+
|
322 |
+
# ─── Build Gradio App ──────────────────────────────────────────────────────────
|
323 |
+
with gr.Blocks(title="Human Evaluation Survey") as demo:
|
324 |
+
# ── Login ────────────────────────────────────────────────────────────────
|
325 |
+
with gr.Column() as login_panel:
|
326 |
+
gr.Markdown("## Human Evaluation Survey")
|
327 |
+
user_id_in = gr.Textbox(label="User ID")
|
328 |
+
ds_dd = gr.Dropdown(list(DATASET_FILES.keys()), label="Select dataset")
|
329 |
+
start_btn = gr.Button("Start survey")
|
330 |
+
|
331 |
+
# Shared state
|
332 |
+
uid_state = gr.State("")
|
333 |
+
ds_state = gr.State("")
|
334 |
+
ex_state = gr.State([])
|
335 |
+
idx_state = gr.State(0)
|
336 |
+
resp_state = gr.State({})
|
337 |
+
|
338 |
+
# ── ESConv Panel ──────────────────────────────────────────────────────────
|
339 |
+
with gr.Column(visible=False) as es_panel:
|
340 |
+
bg = gr.Textbox(label="Background context", interactive=False)
|
341 |
+
with gr.Row():
|
342 |
+
lbox = gr.Textbox(label="Response A", interactive=False)
|
343 |
+
rbox = gr.Textbox(label="Response B", interactive=False)
|
344 |
+
|
345 |
+
ident = gr.Radio(
|
346 |
+
["Prefer Response A", "Prefer Response B", "No preference"],
|
347 |
+
label="Identification (Ident.)",
|
348 |
+
)
|
349 |
+
com = gr.Radio(
|
350 |
+
["Prefer Response A", "Prefer Response B", "No preference"],
|
351 |
+
label="Comforting (Com.)",
|
352 |
+
)
|
353 |
+
sug = gr.Radio(
|
354 |
+
["Prefer Response A", "Prefer Response B", "No preference"],
|
355 |
+
label="Suggestion (Sug.)",
|
356 |
+
)
|
357 |
+
ovl_es = gr.Radio(
|
358 |
+
["Prefer Response A", "Prefer Response B", "No preference"],
|
359 |
+
label="Overall (Ov.)",
|
360 |
+
)
|
361 |
+
err_es = gr.HTML(visible=False)
|
362 |
+
prog = gr.Text(label="Progress")
|
363 |
+
with gr.Row():
|
364 |
+
prev_btn = gr.Button("◀ Prev")
|
365 |
+
next_btn = gr.Button("▶ Next")
|
366 |
+
logout_es = gr.Button("🚪 Logout")
|
367 |
+
|
368 |
+
# ── CraigslistBargain Panel ──────────────────────────────────────────────
|
369 |
+
with gr.Column(visible=False) as cb_panel:
|
370 |
+
bg_cb = gr.Textbox(label="Background context", interactive=False)
|
371 |
+
with gr.Row():
|
372 |
+
lbox_cb = gr.Textbox(label="Response A", interactive=False)
|
373 |
+
rbox_cb = gr.Textbox(label="Response B", interactive=False)
|
374 |
+
|
375 |
+
per = gr.Radio(
|
376 |
+
["Prefer Response A", "Prefer Response B", "No preference"],
|
377 |
+
label="Persuasiveness (Per.)",
|
378 |
+
)
|
379 |
+
coh = gr.Radio(
|
380 |
+
["Prefer Response A", "Prefer Response B", "No preference"],
|
381 |
+
label="Coherence (Coh.)",
|
382 |
+
)
|
383 |
+
nat = gr.Radio(
|
384 |
+
["Prefer Response A", "Prefer Response B", "No preference"],
|
385 |
+
label="Naturalness (Nat.)",
|
386 |
+
)
|
387 |
+
ovl_cb = gr.Radio(
|
388 |
+
["Prefer Response A", "Prefer Response B", "No preference"],
|
389 |
+
label="Overall",
|
390 |
+
)
|
391 |
+
err_cb = gr.HTML(visible=False)
|
392 |
+
prog_cb = gr.Text(label="Progress")
|
393 |
+
with gr.Row():
|
394 |
+
prev_cb = gr.Button("◀ Prev")
|
395 |
+
next_cb = gr.Button("▶ Next")
|
396 |
+
logout_cb = gr.Button("🚪 Logout")
|
397 |
+
|
398 |
+
# ── Wiring ───────────────────────────────────────────────────────────────
|
399 |
+
start_btn.click(
|
400 |
+
login_fn,
|
401 |
+
inputs=[user_id_in, ds_dd],
|
402 |
+
outputs=[
|
403 |
+
login_panel,
|
404 |
+
es_panel,
|
405 |
+
cb_panel,
|
406 |
+
uid_state,
|
407 |
+
ds_state,
|
408 |
+
ex_state,
|
409 |
+
idx_state,
|
410 |
+
resp_state,
|
411 |
+
# ESConv
|
412 |
+
bg,
|
413 |
+
lbox,
|
414 |
+
rbox,
|
415 |
+
prog,
|
416 |
+
ident,
|
417 |
+
com,
|
418 |
+
sug,
|
419 |
+
ovl_es,
|
420 |
+
err_es,
|
421 |
+
# CB
|
422 |
+
bg_cb,
|
423 |
+
lbox_cb,
|
424 |
+
rbox_cb,
|
425 |
+
prog_cb,
|
426 |
+
per,
|
427 |
+
coh,
|
428 |
+
nat,
|
429 |
+
ovl_cb,
|
430 |
+
err_cb,
|
431 |
+
],
|
432 |
+
)
|
433 |
+
|
434 |
+
# ESConv navigation
|
435 |
+
next_btn.click(
|
436 |
+
es_next_fn,
|
437 |
+
inputs=[uid_state, ds_state, ex_state, idx_state, resp_state, ident, com, sug, ovl_es],
|
438 |
+
outputs=[bg, lbox, rbox, prog, idx_state, resp_state, ident, com, sug, ovl_es, err_es],
|
439 |
+
)
|
440 |
+
prev_btn.click(
|
441 |
+
es_prev_fn,
|
442 |
+
inputs=[uid_state, ds_state, ex_state, idx_state, resp_state, ident, com, sug, ovl_es],
|
443 |
+
outputs=[bg, lbox, rbox, prog, idx_state, resp_state, ident, com, sug, ovl_es, err_es],
|
444 |
+
)
|
445 |
+
|
446 |
+
# CB navigation
|
447 |
+
next_cb.click(
|
448 |
+
cb_next_fn,
|
449 |
+
inputs=[uid_state, ds_state, ex_state, idx_state, resp_state, per, coh, nat, ovl_cb],
|
450 |
+
outputs=[bg_cb, lbox_cb, rbox_cb, prog_cb, idx_state, resp_state, per, coh, nat, ovl_cb, err_cb],
|
451 |
+
)
|
452 |
+
prev_cb.click(
|
453 |
+
cb_prev_fn,
|
454 |
+
inputs=[uid_state, ds_state, ex_state, idx_state, resp_state, per, coh, nat, ovl_cb],
|
455 |
+
outputs=[bg_cb, lbox_cb, rbox_cb, prog_cb, idx_state, resp_state, per, coh, nat, ovl_cb, err_cb],
|
456 |
+
)
|
457 |
+
|
458 |
+
# Logout buttons (both panels share same callback)
|
459 |
+
for logout_btn in (logout_es, logout_cb):
|
460 |
+
logout_btn.click(
|
461 |
+
logout_fn,
|
462 |
+
inputs=[uid_state, ds_state, ex_state, idx_state, resp_state],
|
463 |
+
outputs=[
|
464 |
+
login_panel,
|
465 |
+
es_panel,
|
466 |
+
cb_panel,
|
467 |
+
uid_state,
|
468 |
+
ds_state,
|
469 |
+
ex_state,
|
470 |
+
idx_state,
|
471 |
+
resp_state,
|
472 |
+
bg,
|
473 |
+
lbox,
|
474 |
+
rbox,
|
475 |
+
prog,
|
476 |
+
ident,
|
477 |
+
com,
|
478 |
+
sug,
|
479 |
+
ovl_es,
|
480 |
+
err_es,
|
481 |
+
bg_cb,
|
482 |
+
lbox_cb,
|
483 |
+
rbox_cb,
|
484 |
+
prog_cb,
|
485 |
+
per,
|
486 |
+
coh,
|
487 |
+
nat,
|
488 |
+
ovl_cb,
|
489 |
+
err_cb,
|
490 |
+
],
|
491 |
+
)
|
492 |
+
|
493 |
+
# ─── Run ───────────────────────────────────────────────────────────────────────
|
494 |
+
if __name__ == "__main__":
|
495 |
+
demo.launch(share=True)
|
csv/craigslist.csv
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Background Information,PPDPP,DPDP,Ours
|
2 |
+
User wants to buy a used mountain bike listed at $300.,I can pay $250 for the bike.,Would you accept $260 if I pick it up today?,I love the bike! Would you be open to $270 since I can collect it this afternoon?
|
3 |
+
User is interested in a second-hand laptop priced at $500.,I will offer $400 for the laptop.,Can you lower the price to $450?,The laptop looks great—would you consider $480 given its age and specs?
|
4 |
+
User inquires about a leather sofa listed at $200.,I want to buy it for $150.,How about $170 and I handle pickup this weekend?,The sofa seems perfect for my space; would $180 work if I arrange collection on Saturday?
|
5 |
+
User negotiates for a DSLR camera listed at $600.,I can pay $500.,"If you drop to $550, I’m ready to buy now.",I’m very interested and can pick up today—would you accept $580 for a quick sale?
|
6 |
+
User messages seller about a guitar priced at $350.,Will you take $300?,Could you do $325 if I pay in cash?,I’m a musician and love this model—would $330 work if I collect tonight?
|
7 |
+
User wants a used dining table listed at $150.,Offer $100.,I can do $120 and pick up today.,It’s exactly what I need. Would $130 be okay if I pick it up this evening?
|
8 |
+
User asks about a smart TV priced at $450.,I can give you $350.,Is $400 acceptable for you?,I’d love the TV—would you consider $420 since I can arrange collection tomorrow morning?
|
9 |
+
User negotiates price for a baby stroller listed at $100.,I’ll pay $80.,Can you do $90 including accessories?,The stroller is ideal for my child—would you take $95 if I pick up today?
|
10 |
+
User interested in a set of textbooks priced at $120.,I’ll offer $90 for all books.,Would $100 work if I collect in person?,I need these for my course; could we settle at $110 for a quick handover tomorrow?
|
11 |
+
User is looking at a smartphone listed at $200.,I can pay $150.,Can you accept $175?,The phone fits my needs—would $185 be possible if I come by this afternoon?
|
12 |
+
User negotiates for a coffee table listed at $75.,Offer $50.,I could do $60 and pick it up tonight.,It’s perfect for my living room—would you consider $65 if I swing by this evening?
|
13 |
+
User asks about gym equipment bench priced at $120.,I’ll pay $90.,Could you lower to $100?,I’m keen on the bench—would $110 be agreeable if I pick up tomorrow morning?
|
14 |
+
User sees a bookshelf listed at $80.,Offer $60.,Would $70 work with pickup this weekend?,I need storage space—would you accept $75 if I collect on Saturday?
|
15 |
+
User contacting seller for a winter coat priced at $90.,I can do $70.,Will you take $80 if I pay cash?,I really like it—could we agree on $85 if I pick it up today?
|
16 |
+
User interested in a used projector listed at $250.,I’ll offer $200.,Is $225 acceptable?,The projector is great for movie nights—would $240 work if I collect this evening?
|
17 |
+
User negotiates price for a kayak priced at $300.,I can pay $250.,Would you accept $275 if I pick it up tomorrow?,I’m excited to use it—would you consider $290 for a swift sale?
|
18 |
+
User asks about a gaming console listed at $180.,Offer $140.,Could you lower to $160?,I’d love this console—would $170 be okay if I come by today?
|
19 |
+
User messaging seller for a camera tripod priced at $50.,I’ll pay $35.,Is $40 acceptable?,I need it for a shoot tomorrow—could we settle at $45?
|
20 |
+
User interested in a dresser listed at $120.,I can pay $90.,Will you take $100 if I pick it up today?,I really like its design—would $110 work for a same-day pickup?
|
21 |
+
User negotiates for a set of hiking boots priced at $80.,I’ll offer $60.,Could you drop to $70?,They look great—would $75 be acceptable if I pick them up this afternoon?
|
csv/esconv.csv
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Background Information,PPDPP,DPDP,Ours
|
2 |
+
User is heartbroken after losing their childhood pet and feels overwhelming grief.,You might try reminiscing about your time together and cherishing those memories.,Perhaps engaging in a comforting activity like journaling could help ease the pain.,I’m so sorry for your loss. It could help to create a small photo album of your pet and share stories with loved ones who understand.
|
3 |
+
User is stressed about meeting a tight project deadline at work.,Consider breaking the project into smaller milestones to track progress.,You could draft a quick timeline to organize your tasks effectively.,Deadlines can feel stressful; maybe map out the key steps on a whiteboard and celebrate each small win to keep momentum.
|
4 |
+
User feels anxious about an upcoming job interview with a top company.,Try practicing common interview questions in front of a mirror.,Research the company’s culture thoroughly to boost your confidence.,Interviews are nerve-wracking. How about a mock session with a friend and remind yourself of past achievements to bolster your confidence?
|
5 |
+
User reports feeling isolated while working remotely from home.,Maybe schedule short video check-ins with colleagues each day.,Joining virtual coworking sessions could help you feel connected.,Remote work can be lonely. How about a daily virtual coffee break with a friend or an online hobby group?
|
6 |
+
User is struggling with insomnia and restless nights.,"Establish a calming bedtime routine, such as reading before sleep.",Avoid screens at least one hour before bedtime.,Sleep can be elusive; perhaps try a gentle breathing exercise or herbal tea half an hour before bed to relax.
|
7 |
+
User is frustrated at slow progress learning a new language.,Practice vocabulary daily using flashcards.,Joining a conversational partner program might accelerate learning.,Language learning takes time—try labeling items around your home and chatting with a language buddy for immersive practice.
|
8 |
+
User is worried about budgeting and saving money for an upcoming trip.,Create a monthly spending plan to monitor expenses.,Setting clear savings targets can keep you motivated.,"Finances can be tricky; why not start by tracking one expense category, then slowly expand to build an overall budget?"
|
9 |
+
User feels overwhelmed by global climate crisis coverage in the news.,You could reduce news intake to specific times of the day.,Muting distressing topics on social media may help.,It’s natural to feel concerned. How about dedicating one day a week to an environmental volunteer activity to channel that energy positively?
|
10 |
+
User is experiencing sadness after a recent breakup.,Focusing on self-care activities might help you heal.,Writing in a journal daily could provide emotional relief.,Breakups are tough; perhaps treat yourself to a small daily ritual—like a walk in nature—and let yourself feel every emotion.
|
11 |
+
User complains of creative block when starting a new art project.,Try freewriting your ideas for 10 minutes to spark inspiration.,Changing your workspace environment could ignite creativity.,Creative slumps happen. Maybe switch to a different medium—like collage or sketch—and see what new ideas emerge.
|
12 |
+
User is nervous about delivering a speech in front of a large audience.,Practice speaking in front of a mirror each day.,Record yourself to identify areas for improvement.,Public speaking can be daunting. Start with a small group of friends and ask for constructive feedback to build confidence.
|
13 |
+
User feels constantly fatigued and low-energy during afternoons.,Ensure you’re drinking enough water throughout the day.,Short bursts of physical activity might boost your energy.,Midday slumps are common; how about a quick walk outside and a hydrating snack to rejuvenate your mind and body?
|
14 |
+
User is uncertain about choosing a suitable career path.,Try listing your skills and interests to guide your decision.,Speaking with mentors in various fields might offer clarity.,Career choices can feel overwhelming. Consider taking a strengths assessment and scheduling brief chats with professionals in roles you admire.
|
15 |
+
User feels bombarded by negative social media comparisons.,Consider taking periodic breaks from social platforms.,Unfollowing accounts that trigger negative feelings could help.,Social media can distort reality. Try engaging only with uplifting content and remind yourself everyone’s journey is unique.
|
16 |
+
User is frustrated by repeated cooking failures in the kitchen.,Follow a simple recipe step by step without skipping details.,Watching a cooking tutorial video might improve your skills.,Kitchen mishaps happen to everyone. Maybe pick a recipe with just a few ingredients and savor the learning process.
|
17 |
+
User feels anxious ahead of their first day at a new job.,Prepare your outfit and commute plan the night before.,Introducing yourself to future colleagues on LinkedIn could ease nerves.,Starting new is both exciting and nerve-wracking. How about listing three things you’re looking forward to and arriving a bit early for a calm start?
|
18 |
+
User misses family who live overseas and feels homesick.,Schedule a regular video call to stay connected.,Sending a thoughtful care package might lift both your spirits and theirs.,Distance can be hard. Perhaps organize a virtual game night or write a heartfelt letter to share how much you miss them.
|
19 |
+
User feels overwhelmed by their overflowing email inbox.,Try setting aside time slots each day to clear emails.,Using labels and filters could help you organize messages.,Inbox overload is stressful. Maybe archive old threads and prioritize three key emails at the start of each day.
|
20 |
+
User is disappointed by a rejected manuscript submission.,Review the feedback to identify areas for revision.,Consider seeking peer input before resubmitting.,"Rejections can sting. How about taking a short break, then mapping out one or two improvements to strengthen your manuscript for the next submission?"
|
21 |
+
User expresses fear about planning a solo travel adventure.,List your itinerary and share it with a trusted friend.,Research local customs and safety tips in advance.,Solo travel can be empowering. Perhaps start with a well-reviewed hostel and join group tours to meet fellow travelers.
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio>=3.0
|
2 |
+
pandas
|