Spaces:
Running
Running
Merge branch 'main' into main_space
Browse files
app.py
CHANGED
@@ -496,6 +496,9 @@ def downvote_model(model, uname):
|
|
496 |
cursor.close()
|
497 |
|
498 |
def a_is_better(model1, model2, userid):
|
|
|
|
|
|
|
499 |
userid = mkuuid(userid)
|
500 |
if model1 and model2:
|
501 |
conn = get_db()
|
@@ -508,6 +511,9 @@ def a_is_better(model1, model2, userid):
|
|
508 |
downvote_model(model2, str(userid))
|
509 |
return reload(model1, model2, userid, chose_a=True)
|
510 |
def b_is_better(model1, model2, userid):
|
|
|
|
|
|
|
511 |
userid = mkuuid(userid)
|
512 |
if model1 and model2:
|
513 |
conn = get_db()
|
@@ -746,7 +752,9 @@ def synthandreturn(text):
|
|
746 |
result = f.name
|
747 |
except:
|
748 |
pass
|
749 |
-
|
|
|
|
|
750 |
result_storage[model] = result
|
751 |
# try:
|
752 |
# doloudnorm(result)
|
@@ -786,9 +794,16 @@ def synthandreturn(text):
|
|
786 |
|
787 |
return inputs
|
788 |
|
|
|
|
|
|
|
|
|
|
|
789 |
results = {}
|
790 |
-
|
791 |
-
|
|
|
|
|
792 |
thread1.start()
|
793 |
thread2.start()
|
794 |
thread1.join()
|
@@ -802,14 +817,17 @@ def synthandreturn(text):
|
|
802 |
# y, sr = librosa.load(results[list(results.keys())[1]], sr=None)
|
803 |
# print(sr)
|
804 |
#debug
|
|
|
|
|
|
|
805 |
return (
|
806 |
text,
|
807 |
"Synthesize",
|
808 |
gr.update(visible=True), # r2
|
809 |
mdl1, # model1
|
810 |
mdl2, # model2
|
811 |
-
gr.update(visible=True, value=results[
|
812 |
-
gr.update(visible=True, value=results[
|
813 |
gr.update(visible=True, interactive=False), #abetter
|
814 |
gr.update(visible=True, interactive=False), #bbetter
|
815 |
gr.update(visible=False), #prevmodel1
|
@@ -868,8 +886,8 @@ def enable():
|
|
868 |
return [gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)]
|
869 |
with gr.Blocks() as vote:
|
870 |
# sample played
|
871 |
-
aplayed = gr.State(value=False)
|
872 |
-
bplayed = gr.State(value=False)
|
873 |
# voter ID
|
874 |
useridstate = gr.State()
|
875 |
gr.Markdown(INSTR)
|
@@ -880,7 +898,9 @@ with gr.Blocks() as vote:
|
|
880 |
randomt.click(randomsent, outputs=[text, randomt])
|
881 |
btn = gr.Button("Synthesize", variant='primary')
|
882 |
model1 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
|
|
|
883 |
model2 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
|
|
|
884 |
with gr.Row(visible=False) as r2:
|
885 |
with gr.Column():
|
886 |
with gr.Group():
|
@@ -894,13 +914,39 @@ with gr.Blocks() as vote:
|
|
894 |
prevmodel2 = gr.HTML(show_label=False, value="Vote to reveal model B", visible=False)
|
895 |
nxtroundbtn = gr.Button('Next round', visible=False)
|
896 |
# outputs = [text, btn, r2, model1, model2, prevmodel1, aud1, prevmodel2, aud2, abetter, bbetter]
|
897 |
-
outputs = [
|
898 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
899 |
nxtroundbtn.click(clear_stuff, outputs=outputs)
|
900 |
|
901 |
# Allow interaction with the vote buttons only when both audio samples have finished playing
|
902 |
-
aud1.stop(unlock_vote, outputs=[abetter, bbetter, aplayed, bplayed], inputs=[gr.State(value=0), aplayed, bplayed])
|
903 |
-
aud2.stop(unlock_vote, outputs=[abetter, bbetter, aplayed, bplayed], inputs=[gr.State(value=1), aplayed, bplayed])
|
904 |
|
905 |
# nxt_outputs = [prevmodel1, prevmodel2, abetter, bbetter]
|
906 |
nxt_outputs = [abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
|
|
|
496 |
cursor.close()
|
497 |
|
498 |
def a_is_better(model1, model2, userid):
|
499 |
+
print("A is better", model1, model2)
|
500 |
+
if not model1 in AVAILABLE_MODELS.keys() and not model1 in AVAILABLE_MODELS.values():
|
501 |
+
raise gr.Error('Sorry, please try voting again.')
|
502 |
userid = mkuuid(userid)
|
503 |
if model1 and model2:
|
504 |
conn = get_db()
|
|
|
511 |
downvote_model(model2, str(userid))
|
512 |
return reload(model1, model2, userid, chose_a=True)
|
513 |
def b_is_better(model1, model2, userid):
|
514 |
+
print("B is better", model1, model2)
|
515 |
+
if not model1 in AVAILABLE_MODELS.keys() and not model1 in AVAILABLE_MODELS.values():
|
516 |
+
raise gr.Error('Sorry, please try voting again.')
|
517 |
userid = mkuuid(userid)
|
518 |
if model1 and model2:
|
519 |
conn = get_db()
|
|
|
752 |
result = f.name
|
753 |
except:
|
754 |
pass
|
755 |
+
if model in AVAILABLE_MODELS.keys(): model = AVAILABLE_MODELS[model]
|
756 |
+
print(model)
|
757 |
+
print(f"Running model {model}")
|
758 |
result_storage[model] = result
|
759 |
# try:
|
760 |
# doloudnorm(result)
|
|
|
794 |
|
795 |
return inputs
|
796 |
|
797 |
+
mdl1k = mdl1
|
798 |
+
mdl2k = mdl2
|
799 |
+
print(mdl1k, mdl2k)
|
800 |
+
if mdl1 in AVAILABLE_MODELS.keys(): mdl1k=AVAILABLE_MODELS[mdl1]
|
801 |
+
if mdl2 in AVAILABLE_MODELS.keys(): mdl2k=AVAILABLE_MODELS[mdl2]
|
802 |
results = {}
|
803 |
+
print(f"Sending models {mdl1k} and {mdl2k} to API")
|
804 |
+
thread1 = threading.Thread(target=predict_and_update_result, args=(text, mdl1k, results))
|
805 |
+
thread2 = threading.Thread(target=predict_and_update_result, args=(text, mdl2k, results))
|
806 |
+
|
807 |
thread1.start()
|
808 |
thread2.start()
|
809 |
thread1.join()
|
|
|
817 |
# y, sr = librosa.load(results[list(results.keys())[1]], sr=None)
|
818 |
# print(sr)
|
819 |
#debug
|
820 |
+
# outputs = [text, btn, r2, model1, model2, aud1, aud2, abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
|
821 |
+
|
822 |
+
print(f"Retrieving models {mdl1k} and {mdl2k} from API")
|
823 |
return (
|
824 |
text,
|
825 |
"Synthesize",
|
826 |
gr.update(visible=True), # r2
|
827 |
mdl1, # model1
|
828 |
mdl2, # model2
|
829 |
+
gr.update(visible=True, value=results[mdl1k]), # aud1
|
830 |
+
gr.update(visible=True, value=results[mdl2k]), # aud2
|
831 |
gr.update(visible=True, interactive=False), #abetter
|
832 |
gr.update(visible=True, interactive=False), #bbetter
|
833 |
gr.update(visible=False), #prevmodel1
|
|
|
886 |
return [gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)]
|
887 |
with gr.Blocks() as vote:
|
888 |
# sample played
|
889 |
+
#aplayed = gr.State(value=False)
|
890 |
+
#bplayed = gr.State(value=False)
|
891 |
# voter ID
|
892 |
useridstate = gr.State()
|
893 |
gr.Markdown(INSTR)
|
|
|
898 |
randomt.click(randomsent, outputs=[text, randomt])
|
899 |
btn = gr.Button("Synthesize", variant='primary')
|
900 |
model1 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
|
901 |
+
#model1 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=True)
|
902 |
model2 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
|
903 |
+
#model2 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=True)
|
904 |
with gr.Row(visible=False) as r2:
|
905 |
with gr.Column():
|
906 |
with gr.Group():
|
|
|
914 |
prevmodel2 = gr.HTML(show_label=False, value="Vote to reveal model B", visible=False)
|
915 |
nxtroundbtn = gr.Button('Next round', visible=False)
|
916 |
# outputs = [text, btn, r2, model1, model2, prevmodel1, aud1, prevmodel2, aud2, abetter, bbetter]
|
917 |
+
outputs = [
|
918 |
+
text,
|
919 |
+
btn,
|
920 |
+
r2,
|
921 |
+
model1,
|
922 |
+
model2,
|
923 |
+
aud1,
|
924 |
+
aud2,
|
925 |
+
abetter,
|
926 |
+
bbetter,
|
927 |
+
prevmodel1,
|
928 |
+
prevmodel2,
|
929 |
+
nxtroundbtn
|
930 |
+
]
|
931 |
+
"""
|
932 |
+
text,
|
933 |
+
"Synthesize",
|
934 |
+
gr.update(visible=True), # r2
|
935 |
+
mdl1, # model1
|
936 |
+
mdl2, # model2
|
937 |
+
gr.update(visible=True, value=results[mdl1]), # aud1
|
938 |
+
gr.update(visible=True, value=results[mdl2]), # aud2
|
939 |
+
gr.update(visible=True, interactive=False), #abetter
|
940 |
+
gr.update(visible=True, interactive=False), #bbetter
|
941 |
+
gr.update(visible=False), #prevmodel1
|
942 |
+
gr.update(visible=False), #prevmodel2
|
943 |
+
gr.update(visible=False), #nxt round btn"""
|
944 |
+
btn.click(disable, outputs=[btn, abetter, bbetter]).then(synthandreturn, inputs=[text], outputs=outputs).then(enable, outputs=[btn, abetter, bbetter])
|
945 |
nxtroundbtn.click(clear_stuff, outputs=outputs)
|
946 |
|
947 |
# Allow interaction with the vote buttons only when both audio samples have finished playing
|
948 |
+
#aud1.stop(unlock_vote, outputs=[abetter, bbetter, aplayed, bplayed], inputs=[gr.State(value=0), aplayed, bplayed])
|
949 |
+
#aud2.stop(unlock_vote, outputs=[abetter, bbetter, aplayed, bplayed], inputs=[gr.State(value=1), aplayed, bplayed])
|
950 |
|
951 |
# nxt_outputs = [prevmodel1, prevmodel2, abetter, bbetter]
|
952 |
nxt_outputs = [abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
|