Rohan Kumar commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -413,38 +413,40 @@ This takes about **3–5 minutes**. Thank you for contributing! 🙏
|
|
| 413 |
)
|
| 414 |
|
| 415 |
def rate(rating_val: str, name: str, items: list, idx: int):
|
|
|
|
| 416 |
save_annotation(name, items[idx], rating_val)
|
| 417 |
|
|
|
|
| 418 |
next_idx = idx + 1
|
| 419 |
total = len(items)
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
print(total)
|
| 423 |
if next_idx >= total:
|
| 424 |
-
|
| 425 |
-
#
|
| 426 |
-
|
| 427 |
-
|
| 428 |
return (
|
| 429 |
-
gr.
|
| 430 |
-
gr.
|
| 431 |
-
gr.
|
| 432 |
-
name,
|
| 433 |
-
items,
|
| 434 |
-
next_idx,
|
| 435 |
-
|
| 436 |
-
|
| 437 |
)
|
| 438 |
|
|
|
|
| 439 |
return (
|
| 440 |
-
gr.
|
| 441 |
-
gr.
|
| 442 |
-
gr.
|
| 443 |
name,
|
| 444 |
items,
|
| 445 |
next_idx,
|
| 446 |
-
|
| 447 |
-
|
| 448 |
)
|
| 449 |
|
| 450 |
def restart():
|
|
|
|
| 413 |
)
|
| 414 |
|
| 415 |
def rate(rating_val: str, name: str, items: list, idx: int):
|
| 416 |
+
# 1. Save the annotation
|
| 417 |
save_annotation(name, items[idx], rating_val)
|
| 418 |
|
| 419 |
+
# 2. Advance index
|
| 420 |
next_idx = idx + 1
|
| 421 |
total = len(items)
|
| 422 |
+
|
| 423 |
+
# 3. Check if done
|
|
|
|
| 424 |
if next_idx >= total:
|
| 425 |
+
# Using standard string formatting to avoid ALL markdown indentation bugs
|
| 426 |
+
completion_text = f"## 🎉 All done, {name}!\n\nYou've completed **{total} annotations**.\nYour responses have been saved. Thank you for your contribution!\n\n*Feel free to refresh the page to annotate another batch.*"
|
| 427 |
+
|
| 428 |
+
# In modern Gradio, you can return gr.Column() directly instead of gr.update()
|
| 429 |
return (
|
| 430 |
+
gr.Column(visible=False), # col_welcome
|
| 431 |
+
gr.Column(visible=False), # col_rating
|
| 432 |
+
gr.Column(visible=True), # col_done -> explicitly make this visible
|
| 433 |
+
name, # s_name
|
| 434 |
+
items, # s_items
|
| 435 |
+
next_idx, # s_idx
|
| 436 |
+
"", # q_html (just return string)
|
| 437 |
+
completion_text, # done_md (just return string)
|
| 438 |
)
|
| 439 |
|
| 440 |
+
# 4. If not done, show next question
|
| 441 |
return (
|
| 442 |
+
gr.Column(visible=False),
|
| 443 |
+
gr.Column(visible=True),
|
| 444 |
+
gr.Column(visible=False),
|
| 445 |
name,
|
| 446 |
items,
|
| 447 |
next_idx,
|
| 448 |
+
render_question(items[next_idx], next_idx, total),
|
| 449 |
+
"",
|
| 450 |
)
|
| 451 |
|
| 452 |
def restart():
|