bishmoy commited on
Commit
b88f9b7
·
verified ·
1 Parent(s): 8285638

Initial Upload

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. app.py +80 -0
  3. marine.mp3 +3 -0
  4. utils.py +135 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ marine.mp3 filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from utils import *
3
+ import os
4
+
5
+ def build_demo():
6
+
7
+
8
+ with gr.Blocks() as demo:
9
+ state0 = gr.State()
10
+ state1 = gr.State()
11
+ with gr.Tab("Song Generation", id=0):
12
+ gr.Markdown("# 🏆 Arena Elo\nFind out who is the 🥇 song generation models!")
13
+
14
+ with gr.Row():
15
+ with gr.Column():
16
+ gr.Markdown("### 👇 Generating now!")
17
+ with gr.Row():
18
+ with gr.Column():
19
+ model_selector_left = gr.Markdown("", visible=True)
20
+ with gr.Column():
21
+ model_selector_right = gr.Markdown("", visible=True)
22
+
23
+ with gr.Row():
24
+ with gr.Column():
25
+ audio_a = gr.Audio(label="Model A")
26
+ with gr.Column():
27
+ audio_b = gr.Audio(label="Model B")
28
+ with gr.Row():
29
+ leftvote_btn = gr.Button(
30
+ value="👈 A is Fake", visible=False, interactive=False
31
+ )
32
+ rightvote_btn = gr.Button(
33
+ value="👉 B is Fake", visible=False, interactive=False
34
+ )
35
+ tie_btn = gr.Button(value="🤝 Both are Fake", visible=False, interactive=False)
36
+ bothbad_btn = gr.Button(
37
+ value="👎 Both are Real", visible=False, interactive=False
38
+ )
39
+
40
+ btn_list = [leftvote_btn, rightvote_btn, tie_btn, bothbad_btn]
41
+
42
+ leftvote_btn.click(
43
+ leftvote_last_response,
44
+ inputs=[state0, state1],
45
+ outputs=[leftvote_btn, rightvote_btn, tie_btn, bothbad_btn, model_selector_left, model_selector_right]
46
+ )
47
+ rightvote_btn.click(
48
+ rightvote_last_response,
49
+ inputs=[state0, state1],
50
+ outputs=[leftvote_btn, rightvote_btn, tie_btn, bothbad_btn, model_selector_left, model_selector_right]
51
+ )
52
+ tie_btn.click(
53
+ tievote_last_response,
54
+ inputs=[state0, state1],
55
+ outputs=[leftvote_btn, rightvote_btn, tie_btn, bothbad_btn, model_selector_left, model_selector_right]
56
+ )
57
+ bothbad_btn.click(
58
+ bothbadvote_last_response,
59
+ inputs=[state0, state1],
60
+ outputs=[leftvote_btn, rightvote_btn, tie_btn, bothbad_btn, model_selector_left, model_selector_right]
61
+ )
62
+
63
+
64
+ new_round_button = gr.Button("New Round")
65
+ new_round_button.click(generate_songs, [state0, state1], [state0, audio_a, state1, audio_b, model_selector_left, model_selector_right]).then(
66
+ enable_buttons_side_by_side,
67
+ inputs=None,
68
+ outputs=btn_list
69
+ )
70
+ with gr.Tab("Leaderboard", id=1):
71
+ gr.Markdown("# 🏆 Leaderboard work in progress ! 🏆")
72
+ return demo
73
+
74
+
75
+
76
+ if __name__ == "__main__":
77
+
78
+ # elo_results_file, leaderboard_table_file = load_elo_results(elo_results_dir)
79
+ demo = build_demo()
80
+ demo.queue(max_size=20).launch(share = True)
marine.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c5c131aa5d4dc8ea2bd916374ad37203ae5a73bb9b3dce4488530508b9a62249
3
+ size 1036320
utils.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ from datetime import datetime
4
+ from pathlib import Path
5
+ from uuid import uuid4
6
+ import datetime, json
7
+ import time
8
+ import os
9
+ from huggingface_hub import CommitScheduler
10
+ from functools import partial
11
+
12
+ def enable_buttons_side_by_side():
13
+ return tuple(gr.update(visible=True, interactive=True) for i in range(6))
14
+
15
+ def disable_buttons_side_by_side():
16
+ return tuple(gr.update(visible=i>=4, interactive=False) for i in range(6))
17
+
18
+ def get_conv_log_filename():
19
+ LOG_FILENAME = 'data/log.json'
20
+ return LOG_FILENAME
21
+
22
+ enable_btn = gr.update(interactive=True, visible=True)
23
+ disable_btn = gr.update(interactive=False)
24
+ invisible_btn = gr.update(interactive=False, visible=False)
25
+ no_change_btn = gr.update(value="No Change", interactive=True, visible=True)
26
+
27
+ DS_ID = os.getenv('DS_ID')
28
+ TOKEN = os.getenv('TOKEN')
29
+
30
+ scheduler = CommitScheduler(
31
+ repo_id= DS_ID,
32
+ repo_type="dataset",
33
+ folder_path= os.path.dirname(get_conv_log_filename()),
34
+ path_in_repo="data",
35
+ token = TOKEN,
36
+ every = 10,
37
+ )
38
+
39
+
40
+ def vote_last_response(state, vote_type, request: gr.Request):
41
+ with scheduler.lock:
42
+ with open(get_conv_log_filename(), "a") as fout:
43
+ data = {
44
+ "tstamp": round(time.time(), 4),
45
+ "type": vote_type,
46
+ "state0": state[0].dict(),
47
+ "state1": state[1].dict(),
48
+ "ip": get_ip(request),
49
+ }
50
+ fout.write(json.dumps(data) + "\n")
51
+
52
+
53
+
54
+ class AudioStateIG:
55
+ def __init__(self, model_name):
56
+ self.conv_id = uuid4().hex
57
+ self.model_name = model_name
58
+
59
+ def dict(self):
60
+ base = {
61
+ "conv_id": self.conv_id,
62
+ "model_name": self.model_name,
63
+ }
64
+ return base
65
+
66
+ def get_ip(request: gr.Request):
67
+ if request:
68
+ if "cf-connecting-ip" in request.headers:
69
+ ip = request.headers["cf-connecting-ip"] or request.client.host
70
+ else:
71
+ ip = request.client.host
72
+ else:
73
+ ip = None
74
+ return ip
75
+
76
+
77
+ def get_song():
78
+ audio_a = "/content/marine.mp3"
79
+ state = AudioStateIG("Random_Model")
80
+ return state, audio_a
81
+
82
+ def generate_songs(state0, state1):
83
+
84
+ state0, audio_a = get_song()
85
+ state1, audio_b = get_song()
86
+
87
+ return state0, audio_a, state1, audio_b, "Model A: Vote to Reveal", "Model B: Vote to Reveal"
88
+
89
+ def random_sample_button(prompt):
90
+
91
+ audio_a = "/content/marine.mp3"
92
+ audio_b = "/content/marine.mp3"
93
+ return audio_a, audio_b
94
+
95
+ def leftvote_last_response(
96
+ state0, state1, request: gr.Request
97
+ ):
98
+ vote_last_response(
99
+ [state0, state1], "leftvote", request
100
+ )
101
+ return (disable_btn,) * 4 + (
102
+ gr.Markdown(f"### Model A: {state0.model_name.split('_')[1]}", visible=True),
103
+ gr.Markdown(f"### Model B: {state1.model_name.split('_')[1]}", visible=True))
104
+
105
+ def rightvote_last_response(
106
+ state0, state1, request: gr.Request
107
+ ):
108
+ vote_last_response(
109
+ [state0, state1], "rightvote", request
110
+ )
111
+ return (disable_btn,) * 4 + (
112
+ gr.Markdown(f"### Model A: {state0.model_name.split('_')[1]}", visible=True),
113
+ gr.Markdown(f"### Model B: {state1.model_name.split('_')[1]}", visible=True))
114
+
115
+ def tievote_last_response(
116
+ state0, state1, request: gr.Request
117
+ ):
118
+ vote_last_response(
119
+ [state0, state1], "tievote", request
120
+ )
121
+ return (disable_btn,) * 4 + (
122
+ gr.Markdown(f"### Model A: {state0.model_name.split('_')[1]}", visible=True),
123
+ gr.Markdown(f"### Model B: {state1.model_name.split('_')[1]}", visible=True))
124
+
125
+ def bothbadvote_last_response(
126
+ state0, state1, request: gr.Request
127
+ ):
128
+ vote_last_response(
129
+ [state0, state1], "bothbadvote", request
130
+ )
131
+ return (disable_btn,) * 4 + (
132
+ gr.Markdown(f"### Model A: {state0.model_name.split('_')[1]}", visible=True),
133
+ gr.Markdown(f"### Model B: {state1.model_name.split('_')[1]}", visible=True))
134
+
135
+