PlotweaverModel commited on
Commit
f7baf8e
·
verified ·
1 Parent(s): 82bd757

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -67
app.py CHANGED
@@ -476,9 +476,9 @@ with gr.Blocks(title="Plotweaver AI — TTS MOS Evaluation",
476
  greeting = gr.Markdown()
477
  logout_btn = gr.Button("Log out", scale=0, size="sm")
478
 
479
- with gr.Tabs():
480
  # ---------- Rate tab ----------
481
- with gr.Tab("Rate samples") as rate_tab:
482
  with gr.Row():
483
  rate_lang = gr.Dropdown(label="Language", choices=[], interactive=True,
484
  allow_custom_value=True, scale=2)
@@ -513,73 +513,73 @@ with gr.Blocks(title="Plotweaver AI — TTS MOS Evaluation",
513
  rate_msg = gr.Markdown()
514
 
515
  # ---------- Progress tab ----------
516
- with gr.Tab("My progress") as progress_tab:
517
  refresh_prog_btn = gr.Button("Refresh", size="sm")
518
  progress_md = gr.Markdown()
519
  progress_tbl = gr.Dataframe(
520
  headers=["Language", "Rated", "Total", "Remaining"], interactive=False)
521
 
522
  # ---------- Profile tab ----------
523
- with gr.Tab("My languages") as langs_tab:
524
  gr.Markdown("Choose which languages you are eligible to evaluate.")
525
  prof_langs = gr.CheckboxGroup(label="Languages", choices=lang_choices())
526
  prof_save = gr.Button("Save", variant="primary", size="sm")
527
  prof_msg = gr.Markdown()
528
 
529
- # ---------- Admin tab ----------
530
- with gr.Tab("Admin", visible=False) as admin_tab:
531
- gr.Markdown("### Languages")
532
- with gr.Row():
533
- al_code = gr.Textbox(label="Code", info="e.g. yo, ha, ig, pcm, en-NG", scale=1)
534
- al_name = gr.Textbox(label="Name", info="e.g. Yoruba", scale=2)
535
- al_btn = gr.Button("Add language", scale=0, size="sm")
536
- al_msg = gr.Markdown()
537
- langs_tbl = gr.Dataframe(headers=["id", "code", "name"], interactive=False,
538
- label="Existing languages")
539
-
540
- gr.Markdown("### Upload audio samples")
541
- with gr.Row():
542
- up_lang = gr.Dropdown(label="Language", choices=lang_choices(),
543
- allow_custom_value=True, scale=1)
544
- up_model = gr.Textbox(label="Model / system name", value="",
545
- info="e.g. F5-TTS, XTTS-v2, MMS-TTS, human. Hidden from reviewers.",
546
- scale=2)
547
- up_files = gr.File(label="Audio files (wav/mp3/flac/ogg)", file_count="multiple",
548
- file_types=["audio"])
549
- with gr.Row():
550
- up_isref = gr.Checkbox(label="These are reference / human anchor samples", value=False)
551
- up_transcript = gr.Textbox(label="Transcript (optional, applies to all uploaded)", scale=2)
552
- up_btn = gr.Button("Upload", variant="primary", size="sm")
553
- up_msg = gr.Markdown()
554
- samples_tbl = gr.Dataframe(
555
- headers=["id", "language", "sample_name", "model", "reference"],
556
- interactive=False, label="Samples")
557
- with gr.Row():
558
- del_sample_id = gr.Number(label="Delete sample by id", precision=0)
559
- del_btn = gr.Button("Delete", variant="stop", scale=0, size="sm")
560
-
561
- gr.Markdown("### Users")
562
- refresh_users_btn = gr.Button("Refresh users", size="sm")
563
- users_tbl = gr.Dataframe(
564
- headers=["id", "username", "role", "active", "languages", "ratings"],
565
- interactive=False)
566
- with gr.Row():
567
- promote_id = gr.Number(label="User id", precision=0)
568
- role_choice = gr.Dropdown(label="Set role", choices=["reviewer", "admin"], value="reviewer")
569
- active_choice = gr.Dropdown(label="Set active", choices=["yes", "no"], value="yes")
570
- update_user_btn = gr.Button("Apply", scale=0, size="sm")
571
- user_admin_msg = gr.Markdown()
572
-
573
- gr.Markdown("### Results")
574
- with gr.Row():
575
- res_lang = gr.Dropdown(label="Language", choices=lang_choices(),
576
- allow_custom_value=True, scale=2)
577
- res_btn = gr.Button("Compute MOS", variant="primary", scale=0, size="sm")
578
- export_btn = gr.Button("Export XLSX", scale=0, size="sm")
579
- res_summary = gr.Markdown()
580
- res_model_tbl = gr.Dataframe(label="MOS by model", interactive=False)
581
- res_sample_tbl = gr.Dataframe(label="MOS by sample", interactive=False)
582
- res_file = gr.File(label="Exported file")
583
 
584
  # ===================================================================== #
585
  # Handlers
@@ -592,7 +592,7 @@ with gr.Blocks(title="Plotweaver AI — TTS MOS Evaluation",
592
  # keep typed credentials so the user can correct them
593
  return (gr.update(), gr.update(), None, "❌ Invalid username or password.",
594
  gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
595
- gr.update(), gr.update(), gr.update(), gr.update())
596
  sess = user_session(user["id"])
597
  is_admin = sess["role"] == "admin"
598
  rl = reviewer_lang_choices(sess)
@@ -602,10 +602,8 @@ with gr.Blocks(title="Plotweaver AI — TTS MOS Evaluation",
602
  sess, # session
603
  "", # li_msg
604
  gr.update(value=f"Signed in as **{sess['username']}** · {sess['role']}"), # greeting
605
- gr.update(visible=is_admin), # admin_tab
606
- gr.update(visible=not is_admin), # rate_tab
607
- gr.update(visible=not is_admin), # progress_tab
608
- gr.update(visible=not is_admin), # langs_tab
609
  gr.update(choices=rl, value=None), # rate_lang
610
  gr.update(choices=lang_choices(),
611
  value=[l["id"] for l in sess["languages"]]), # prof_langs
@@ -615,13 +613,13 @@ with gr.Blocks(title="Plotweaver AI — TTS MOS Evaluation",
615
 
616
  li_btn.click(
617
  do_login, [li_user, li_pw],
618
- [auth_col, app_col, session, li_msg, greeting, admin_tab,
619
- rate_tab, progress_tab, langs_tab, rate_lang, prof_langs, li_user, li_pw],
620
  )
621
  li_pw.submit( # allow Enter-to-login
622
  do_login, [li_user, li_pw],
623
- [auth_col, app_col, session, li_msg, greeting, admin_tab,
624
- rate_tab, progress_tab, langs_tab, rate_lang, prof_langs, li_user, li_pw],
625
  )
626
 
627
  def do_signup(username, email, password, lang_ids, code):
@@ -830,6 +828,13 @@ with gr.Blocks(title="Plotweaver AI — TTS MOS Evaluation",
830
  if s and s["role"] == "admin" else ([], [], []),
831
  [session], [langs_tbl, samples_tbl, users_tbl])
832
 
 
 
 
 
 
 
 
833
 
834
  if __name__ == "__main__":
835
  demo.queue().launch(
 
476
  greeting = gr.Markdown()
477
  logout_btn = gr.Button("Log out", scale=0, size="sm")
478
 
479
+ with gr.Tabs(visible=False) as reviewer_tabs:
480
  # ---------- Rate tab ----------
481
+ with gr.Tab("Rate samples"):
482
  with gr.Row():
483
  rate_lang = gr.Dropdown(label="Language", choices=[], interactive=True,
484
  allow_custom_value=True, scale=2)
 
513
  rate_msg = gr.Markdown()
514
 
515
  # ---------- Progress tab ----------
516
+ with gr.Tab("My progress"):
517
  refresh_prog_btn = gr.Button("Refresh", size="sm")
518
  progress_md = gr.Markdown()
519
  progress_tbl = gr.Dataframe(
520
  headers=["Language", "Rated", "Total", "Remaining"], interactive=False)
521
 
522
  # ---------- Profile tab ----------
523
+ with gr.Tab("My languages"):
524
  gr.Markdown("Choose which languages you are eligible to evaluate.")
525
  prof_langs = gr.CheckboxGroup(label="Languages", choices=lang_choices())
526
  prof_save = gr.Button("Save", variant="primary", size="sm")
527
  prof_msg = gr.Markdown()
528
 
529
+ # ---------- Admin view (entirely separate from reviewer tabs) ----------
530
+ with gr.Column(visible=False) as admin_panel:
531
+ gr.Markdown("### Languages")
532
+ with gr.Row():
533
+ al_code = gr.Textbox(label="Code", info="e.g. yo, ha, ig, pcm, en-NG", scale=1)
534
+ al_name = gr.Textbox(label="Name", info="e.g. Yoruba", scale=2)
535
+ al_btn = gr.Button("Add language", scale=0, size="sm")
536
+ al_msg = gr.Markdown()
537
+ langs_tbl = gr.Dataframe(headers=["id", "code", "name"], interactive=False,
538
+ label="Existing languages")
539
+
540
+ gr.Markdown("### Upload audio samples")
541
+ with gr.Row():
542
+ up_lang = gr.Dropdown(label="Language", choices=lang_choices(),
543
+ allow_custom_value=True, scale=1)
544
+ up_model = gr.Textbox(label="Model / system name", value="",
545
+ info="e.g. F5-TTS, XTTS-v2, MMS-TTS, human. Hidden from reviewers.",
546
+ scale=2)
547
+ up_files = gr.File(label="Audio files (wav/mp3/flac/ogg)", file_count="multiple",
548
+ file_types=["audio"])
549
+ with gr.Row():
550
+ up_isref = gr.Checkbox(label="These are reference / human anchor samples", value=False)
551
+ up_transcript = gr.Textbox(label="Transcript (optional, applies to all uploaded)", scale=2)
552
+ up_btn = gr.Button("Upload", variant="primary", size="sm")
553
+ up_msg = gr.Markdown()
554
+ samples_tbl = gr.Dataframe(
555
+ headers=["id", "language", "sample_name", "model", "reference"],
556
+ interactive=False, label="Samples")
557
+ with gr.Row():
558
+ del_sample_id = gr.Number(label="Delete sample by id", precision=0)
559
+ del_btn = gr.Button("Delete", variant="stop", scale=0, size="sm")
560
+
561
+ gr.Markdown("### Users")
562
+ refresh_users_btn = gr.Button("Refresh users", size="sm")
563
+ users_tbl = gr.Dataframe(
564
+ headers=["id", "username", "role", "active", "languages", "ratings"],
565
+ interactive=False)
566
+ with gr.Row():
567
+ promote_id = gr.Number(label="User id", precision=0)
568
+ role_choice = gr.Dropdown(label="Set role", choices=["reviewer", "admin"], value="reviewer")
569
+ active_choice = gr.Dropdown(label="Set active", choices=["yes", "no"], value="yes")
570
+ update_user_btn = gr.Button("Apply", scale=0, size="sm")
571
+ user_admin_msg = gr.Markdown()
572
+
573
+ gr.Markdown("### Results")
574
+ with gr.Row():
575
+ res_lang = gr.Dropdown(label="Language", choices=lang_choices(),
576
+ allow_custom_value=True, scale=2)
577
+ res_btn = gr.Button("Compute MOS", variant="primary", scale=0, size="sm")
578
+ export_btn = gr.Button("Export XLSX", scale=0, size="sm")
579
+ res_summary = gr.Markdown()
580
+ res_model_tbl = gr.Dataframe(label="MOS by model", interactive=False)
581
+ res_sample_tbl = gr.Dataframe(label="MOS by sample", interactive=False)
582
+ res_file = gr.File(label="Exported file")
583
 
584
  # ===================================================================== #
585
  # Handlers
 
592
  # keep typed credentials so the user can correct them
593
  return (gr.update(), gr.update(), None, "❌ Invalid username or password.",
594
  gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
595
+ gr.update(), gr.update())
596
  sess = user_session(user["id"])
597
  is_admin = sess["role"] == "admin"
598
  rl = reviewer_lang_choices(sess)
 
602
  sess, # session
603
  "", # li_msg
604
  gr.update(value=f"Signed in as **{sess['username']}** · {sess['role']}"), # greeting
605
+ gr.update(visible=not is_admin), # reviewer_tabs
606
+ gr.update(visible=is_admin), # admin_panel
 
 
607
  gr.update(choices=rl, value=None), # rate_lang
608
  gr.update(choices=lang_choices(),
609
  value=[l["id"] for l in sess["languages"]]), # prof_langs
 
613
 
614
  li_btn.click(
615
  do_login, [li_user, li_pw],
616
+ [auth_col, app_col, session, li_msg, greeting, reviewer_tabs, admin_panel,
617
+ rate_lang, prof_langs, li_user, li_pw],
618
  )
619
  li_pw.submit( # allow Enter-to-login
620
  do_login, [li_user, li_pw],
621
+ [auth_col, app_col, session, li_msg, greeting, reviewer_tabs, admin_panel,
622
+ rate_lang, prof_langs, li_user, li_pw],
623
  )
624
 
625
  def do_signup(username, email, password, lang_ids, code):
 
828
  if s and s["role"] == "admin" else ([], [], []),
829
  [session], [langs_tbl, samples_tbl, users_tbl])
830
 
831
+ # Refresh language-dependent choices on every page load, so newly added
832
+ # languages appear in the signup form (and admin dropdowns) without a restart.
833
+ def refresh_lang_choices():
834
+ ch = lang_choices()
835
+ return (gr.update(choices=ch), gr.update(choices=ch), gr.update(choices=ch))
836
+ demo.load(refresh_lang_choices, None, [su_langs, up_lang, res_lang])
837
+
838
 
839
  if __name__ == "__main__":
840
  demo.queue().launch(