mrfakename commited on
Commit
2e36c10
·
verified ·
1 Parent(s): 87c9725

Delete app

Browse files
Files changed (14) hide show
  1. app/__init__.py +0 -0
  2. app/config.py +0 -50
  3. app/db.py +0 -54
  4. app/init.py +0 -30
  5. app/leaderboard.py +0 -272
  6. app/messages.py +0 -63
  7. app/models.py +0 -90
  8. app/synth.py +0 -240
  9. app/ui.py +0 -146
  10. app/ui_battle.py +0 -89
  11. app/ui_leaderboard.py +0 -55
  12. app/ui_vote.py +0 -113
  13. app/utils.py +0 -20
  14. app/vote.py +0 -114
app/__init__.py DELETED
File without changes
app/config.py DELETED
@@ -1,50 +0,0 @@
1
- import os
2
-
3
- RUNNING_LOCALLY = os.getenv('RUNNING_LOCALLY', '0').lower() in ('true', '1', 't')
4
- if RUNNING_LOCALLY:
5
- print("Running locally, not syncing DB to HF dataset")
6
- else:
7
- print("Running in HF Space, syncing DB to HF dataset")
8
- # NOTE: Configure models in `models.py`
9
-
10
- #########################
11
- # General Configuration #
12
- #########################
13
-
14
- DB_NAME = "database.db"
15
-
16
- TOXICITY_CHECK = False
17
-
18
- MAX_SAMPLE_TXT_LENGTH = 300 # Maximum text length (characters)
19
- MIN_SAMPLE_TXT_LENGTH = 10 # Minimum text length (characters)
20
-
21
- DB_PATH = f"/data/{DB_NAME}" if os.path.isdir("/data") else DB_NAME # If /data available => means local storage is enabled => let's use it!
22
-
23
- ROUTER_ID = "TTS-AGI/tts-router" # You should use a router space to route TTS models to avoid exposing your API keys!
24
-
25
- SYNC_DB = not RUNNING_LOCALLY # Sync DB to HF dataset?
26
-
27
- DB_DATASET_ID = os.getenv('DATASET_ID') # HF dataset ID, can be None if not syncing
28
-
29
- SPACE_ID = os.getenv('SPACE_ID') # Don't change this! It detects if we're running in a HF Space
30
-
31
- with open(os.path.dirname(__file__) + '/../harvard_sentences.txt', 'r') as f:
32
- sents = f.read().strip().splitlines()
33
-
34
- ######################
35
- # TTS Arena Settings #
36
- ######################
37
-
38
- CITATION_TEXT = """@misc{tts-arena,
39
- title = {Text to Speech Arena},
40
- author = {mrfakename and Srivastav, Vaibhav and Fourrier, Clémentine and Pouget, Lucain and Lacombe, Yoach and main and Gandhi, Sanchit},
41
- year = 2024,
42
- publisher = {Hugging Face},
43
- howpublished = "\\url{https://huggingface.co/spaces/TTS-AGI/TTS-Arena}"
44
- }"""
45
-
46
- NEWS = """
47
- - 2025/01/21: New leaderboard UI released with enhanced UI and improved performance.
48
- - 2025/01/14: CosyVoice 2.0 was added to the Arena.
49
- - 2024/11/26: Anonymous Sparkle (Fish Speech v1.5) was added to the Arena.
50
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/db.py DELETED
@@ -1,54 +0,0 @@
1
- import sqlite3
2
- from .config import *
3
- import os
4
- import shutil
5
- from huggingface_hub import hf_hub_download
6
-
7
- def download_db():
8
- if not os.path.isfile(DB_PATH):
9
- print("Downloading DB...")
10
- try:
11
- cache_path = hf_hub_download(repo_id=DB_DATASET_ID, repo_type='dataset', filename=DB_NAME)
12
- shutil.copyfile(cache_path, DB_PATH)
13
- print("Downloaded DB")
14
- except Exception as e:
15
- print("Error while downloading DB:", e)
16
-
17
- def get_db():
18
- return sqlite3.connect(DB_PATH)
19
-
20
- def create_db():
21
- conn = get_db()
22
- cursor = conn.cursor()
23
- cursor.execute('''
24
- CREATE TABLE IF NOT EXISTS model (
25
- name TEXT UNIQUE,
26
- upvote INTEGER,
27
- downvote INTEGER
28
- );
29
- ''')
30
- cursor.execute('''
31
- CREATE TABLE IF NOT EXISTS vote (
32
- id INTEGER PRIMARY KEY AUTOINCREMENT,
33
- username TEXT,
34
- model TEXT,
35
- vote INTEGER,
36
- timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
37
- );
38
- ''')
39
- cursor.execute('''
40
- CREATE TABLE IF NOT EXISTS votelog (
41
- id INTEGER PRIMARY KEY AUTOINCREMENT,
42
- username TEXT,
43
- chosen TEXT,
44
- rejected TEXT,
45
- timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
46
- );
47
- ''')
48
- cursor.execute('''
49
- CREATE TABLE IF NOT EXISTS spokentext (
50
- id INTEGER PRIMARY KEY AUTOINCREMENT,
51
- spokentext TEXT,
52
- timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
53
- );
54
- ''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/init.py DELETED
@@ -1,30 +0,0 @@
1
- from .config import *
2
- from .db import *
3
- from huggingface_hub import CommitScheduler
4
- from pathlib import Path
5
- from gradio_client import Client
6
- import os
7
-
8
-
9
- scheduler = None
10
-
11
- if SYNC_DB:
12
- download_db()
13
- # Sync local DB with remote repo every 5 minute (only if a change is detected)
14
- scheduler = CommitScheduler(
15
- repo_id=DB_DATASET_ID,
16
- repo_type="dataset",
17
- folder_path=Path(DB_PATH).parent,
18
- every=5,
19
- allow_patterns=DB_NAME,
20
- )
21
-
22
- create_db()
23
-
24
- # Load TTS Router
25
- router = Client(ROUTER_ID, hf_token=os.getenv('HF_TOKEN'))
26
-
27
- if TOXICITY_CHECK:
28
- # Load toxicity model
29
- from detoxify import Detoxify
30
- toxicity = Detoxify('original')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/leaderboard.py DELETED
@@ -1,272 +0,0 @@
1
- from .config import *
2
- from .db import *
3
- from .models import *
4
-
5
- import pandas as pd
6
- def get_leaderboard(reveal_prelim = False, hide_battle_votes = False, sort_by_elo = False, hide_proprietary = False):
7
- conn = get_db()
8
- cursor = conn.cursor()
9
-
10
- if hide_battle_votes:
11
- sql = '''
12
- SELECT m.name,
13
- SUM(CASE WHEN v.username NOT LIKE '%_battle' AND v.vote = 1 THEN 1 ELSE 0 END) as upvote,
14
- SUM(CASE WHEN v.username NOT LIKE '%_battle' AND v.vote = -1 THEN 1 ELSE 0 END) as downvote
15
- FROM model m
16
- LEFT JOIN vote v ON m.name = v.model
17
- GROUP BY m.name
18
- '''
19
- else:
20
- sql = '''
21
- SELECT name,
22
- SUM(CASE WHEN vote = 1 THEN 1 ELSE 0 END) as upvote,
23
- SUM(CASE WHEN vote = -1 THEN 1 ELSE 0 END) as downvote
24
- FROM model
25
- LEFT JOIN vote ON model.name = vote.model
26
- GROUP BY name
27
- '''
28
-
29
- cursor.execute(sql)
30
- data = cursor.fetchall()
31
- df = pd.DataFrame(data, columns=['name', 'upvote', 'downvote'])
32
- df['name'] = df['name'].replace(model_names).replace('Anonymous Sparkle', 'Fish Speech v1.5')
33
-
34
- # Calculate total votes and win rate
35
- df['votes'] = df['upvote'] + df['downvote']
36
- df['win_rate'] = (df['upvote'] / df['votes'] * 100).round(1)
37
-
38
- # Remove models with no votes
39
- df = df[df['votes'] > 0]
40
-
41
- # Filter out rows with insufficient votes if not revealing preliminary results
42
- if not reveal_prelim:
43
- df = df[df['votes'] > 500]
44
-
45
- ## Calculate ELO SCORE (kept as secondary metric)
46
- df['elo'] = 1200
47
- for i in range(len(df)):
48
- for j in range(len(df)):
49
- if i != j:
50
- try:
51
- expected_a = 1 / (1 + 10 ** ((df['elo'].iloc[j] - df['elo'].iloc[i]) / 400))
52
- expected_b = 1 / (1 + 10 ** ((df['elo'].iloc[i] - df['elo'].iloc[j]) / 400))
53
- actual_a = df['upvote'].iloc[i] / df['votes'].iloc[i] if df['votes'].iloc[i] > 0 else 0.5
54
- actual_b = df['upvote'].iloc[j] / df['votes'].iloc[j] if df['votes'].iloc[j] > 0 else 0.5
55
- df.iloc[i, df.columns.get_loc('elo')] += 32 * (actual_a - expected_a)
56
- df.iloc[j, df.columns.get_loc('elo')] += 32 * (actual_b - expected_b)
57
- except Exception as e:
58
- print(f"Error in ELO calculation for rows {i} and {j}: {str(e)}")
59
- continue
60
- df['elo'] = round(df['elo'])
61
-
62
- # Sort based on user preference
63
- sort_column = 'elo' if sort_by_elo else 'win_rate'
64
- df = df.sort_values(by=sort_column, ascending=False)
65
- df['order'] = ['#' + str(i + 1) for i in range(len(df))]
66
-
67
- # Select and order columns for display
68
- df = df[['order', 'name', 'win_rate', 'votes', 'elo']]
69
-
70
- # Remove proprietary models if filter is enabled
71
- if hide_proprietary:
72
- df = df[~df['name'].isin(closed_source)]
73
-
74
- # Convert DataFrame to markdown table with CSS styling
75
- markdown_table = """
76
- <style>
77
- /* Reset any Gradio table styles */
78
- .leaderboard-table,
79
- .leaderboard-table th,
80
- .leaderboard-table td {
81
- border: none !important;
82
- border-collapse: separate !important;
83
- border-spacing: 0 !important;
84
- }
85
-
86
- .leaderboard-container {
87
- background: var(--background-fill-primary);
88
- border: 1px solid var(--border-color-primary);
89
- border-radius: 12px;
90
- padding: 4px;
91
- margin: 10px 0;
92
- width: 100%;
93
- overflow-x: auto; /* Enable horizontal scroll */
94
- }
95
-
96
- .leaderboard-scroll {
97
- max-height: 600px;
98
- overflow-y: auto;
99
- border-radius: 8px;
100
- }
101
-
102
- .leaderboard-table {
103
- width: 100%;
104
- border-spacing: 0;
105
- border-collapse: separate;
106
- font-size: 15px;
107
- line-height: 1.5;
108
- table-layout: auto; /* Allow flexible column widths */
109
- }
110
-
111
- .leaderboard-table th {
112
- background: var(--background-fill-secondary);
113
- color: var(--body-text-color);
114
- font-weight: 600;
115
- text-align: left;
116
- padding: 12px 16px;
117
- position: sticky;
118
- top: 0;
119
- z-index: 1;
120
- }
121
-
122
- .leaderboard-table th:after {
123
- content: '';
124
- position: absolute;
125
- left: 0;
126
- bottom: 0;
127
- width: 100%;
128
- border-bottom: 1px solid var(--border-color-primary);
129
- }
130
-
131
- .leaderboard-table td {
132
- padding: 12px 16px;
133
- color: var(--body-text-color);
134
- }
135
-
136
- .leaderboard-table tr td {
137
- border-bottom: 1px solid var(--border-color-primary);
138
- }
139
-
140
- .leaderboard-table tr:last-child td {
141
- border-bottom: none;
142
- }
143
-
144
- .leaderboard-table tr:hover td {
145
- background: var(--background-fill-secondary);
146
- }
147
-
148
- /* Column-specific styles */
149
- .leaderboard-table .col-rank {
150
- width: 70px;
151
- min-width: 70px; /* Prevent rank from shrinking */
152
- }
153
-
154
- .leaderboard-table .col-model {
155
- min-width: 200px; /* Minimum width before scrolling */
156
- }
157
-
158
- .leaderboard-table .col-winrate {
159
- width: 100px;
160
- min-width: 100px; /* Prevent win rate from shrinking */
161
- }
162
-
163
- .leaderboard-table .col-votes {
164
- width: 100px;
165
- min-width: 100px; /* Prevent votes from shrinking */
166
- }
167
-
168
- .leaderboard-table .col-arena {
169
- width: 100px;
170
- min-width: 100px; /* Prevent arena score from shrinking */
171
- }
172
-
173
- .win-rate {
174
- display: inline-block;
175
- font-weight: 600;
176
- padding: 4px 8px;
177
- border-radius: 6px;
178
- min-width: 65px;
179
- text-align: center;
180
- }
181
-
182
- .win-rate-excellent {
183
- background-color: var(--color-accent);
184
- color: var(--color-accent-foreground);
185
- }
186
-
187
- .win-rate-good {
188
- background-color: var(--color-accent-soft);
189
- color: var(--body-text-color);
190
- }
191
-
192
- .win-rate-average {
193
- background-color: var(--background-fill-secondary);
194
- color: var(--body-text-color);
195
- border: 1px solid var(--border-color-primary);
196
- }
197
-
198
- .win-rate-below {
199
- background-color: var(--error-background-fill);
200
- color: var(--body-text-color);
201
- }
202
-
203
- .model-link {
204
- color: var(--body-text-color) !important;
205
- text-decoration: none !important;
206
- border-bottom: 2px dashed rgba(128, 128, 128, 0.3);
207
- }
208
-
209
- .model-link:hover {
210
- color: var(--color-accent) !important;
211
- border-bottom-color: var(--color-accent) !important;
212
- }
213
-
214
- .proprietary-badge {
215
- display: inline-block;
216
- font-size: 12px;
217
- padding: 2px 6px;
218
- border-radius: 4px;
219
- background-color: var(--background-fill-secondary);
220
- color: var(--body-text-color);
221
- margin-left: 6px;
222
- border: 1px solid var(--border-color-primary);
223
- }
224
- </style>
225
- <div class="leaderboard-container">
226
- <div class="leaderboard-scroll">
227
- <table class="leaderboard-table">
228
- <thead>
229
- <tr>
230
- <th class="col-rank">Rank</th>
231
- <th class="col-model">Model</th>
232
- <th class="col-winrate">Win Rate</th>
233
- <th class="col-votes">Votes</th>
234
- """ + ("""<th class="col-arena">Arena Score</th>""" if sort_by_elo else "") + """
235
- </tr>
236
- </thead>
237
- <tbody>
238
- """
239
-
240
- def get_win_rate_class(win_rate):
241
- if win_rate >= 60:
242
- return "win-rate-excellent"
243
- elif win_rate >= 55:
244
- return "win-rate-good"
245
- elif win_rate >= 45:
246
- return "win-rate-average"
247
- else:
248
- return "win-rate-below"
249
-
250
- for _, row in df.iterrows():
251
- win_rate_class = get_win_rate_class(row['win_rate'])
252
- win_rate_html = f'<span class="win-rate {win_rate_class}">{row["win_rate"]}%</span>'
253
-
254
- # Add link to model name if available and proprietary badge if closed source
255
- model_name = row['name']
256
- original_model_name = model_name
257
- if model_name in model_links:
258
- model_name = f'<a href="{model_links[model_name]}" target="_blank" class="model-link">{model_name}</a>'
259
-
260
- if original_model_name in closed_source:
261
- model_name += '<span class="proprietary-badge">Proprietary</span>'
262
-
263
- markdown_table += f'''<tr>
264
- <td class="col-rank">{row['order']}</td>
265
- <td class="col-model">{model_name}</td>
266
- <td class="col-winrate">{win_rate_html}</td>
267
- <td class="col-votes">{row['votes']:,}</td>''' + (
268
- f'''<td class="col-arena">{int(row['elo'])}</td>''' if sort_by_elo else ""
269
- ) + "</tr>\n"
270
-
271
- markdown_table += "</tbody></table></div></div>"
272
- return markdown_table
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/messages.py DELETED
@@ -1,63 +0,0 @@
1
- from .config import *
2
-
3
- ############
4
- # Messages #
5
- ############
6
-
7
- MUST_BE_LOGGEDIN = "Please login with Hugging Face to participate in the TTS Arena."
8
- DESCR = """
9
- # TTS Arena: Benchmarking TTS Models in the Wild
10
-
11
- Vote to help the community find the best available text-to-speech model!
12
- """.strip()
13
- BATTLE_INSTR = """
14
- ## Battle
15
- Choose 2 candidates and vote on which one is better! Currently in beta.
16
- * Input text (English only) to synthesize audio (or press 🎲 for random text).
17
- * Listen to the two audio clips, one after the other.
18
- * Vote on which audio sounds more natural to you.
19
- """
20
- INSTR = """
21
- ## Vote
22
- * Input text (English only) to synthesize audio (or press 🎲 for random text).
23
- * Listen to the two audio clips, one after the other.
24
- * Vote on which audio sounds more natural to you.
25
- * _Note: Model names are revealed after the vote is cast._
26
- Note: It may take up to 30 seconds to synthesize audio.
27
- """.strip()
28
- request = ""
29
- if SPACE_ID:
30
- request = f"""
31
- ### Request a model
32
- Please [create a Discussion](https://huggingface.co/spaces/{SPACE_ID}/discussions/new) to request a model.
33
- """
34
- ABOUT = f"""
35
- ## About
36
- The TTS Arena evaluates leading speech synthesis models. It is inspired by LMsys's [Chatbot Arena](https://chat.lmsys.org/).
37
- ### Motivation
38
- The field of speech synthesis has long lacked an accurate method to measure the quality of different models. Objective metrics like WER (word error rate) are unreliable measures of model quality, and subjective measures such as MOS (mean opinion score) are typically small-scale experiments conducted with few listeners. As a result, these measurements are generally not useful for comparing two models of roughly similar quality. To address these drawbacks, we are inviting the community to rank models in an easy-to-use interface, and opening it up to the public in order to make both the opportunity to rank models, as well as the results, more easily accessible to everyone.
39
- ### The Arena
40
- The leaderboard allows a user to enter text, which will be synthesized by two models. After listening to each sample, the user can vote on which model sounds more natural. Due to the risks of human bias and abuse, model names are revealed only after a vote is submitted.
41
- ### Credits
42
- Thank you to the following individuals who helped make this project possible:
43
- * VB ([Twitter](https://twitter.com/reach_vb) / [Hugging Face](https://huggingface.co/reach-vb))
44
- * Clémentine Fourrier ([Twitter](https://twitter.com/clefourrier) / [Hugging Face](https://huggingface.co/clefourrier))
45
- * Lucain Pouget ([Twitter](https://twitter.com/Wauplin) / [Hugging Face](https://huggingface.co/Wauplin))
46
- * Yoach Lacombe ([Twitter](https://twitter.com/yoachlacombe) / [Hugging Face](https://huggingface.co/ylacombe))
47
- * Main Horse ([Twitter](https://twitter.com/main_horse) / [Hugging Face](https://huggingface.co/main-horse))
48
- * Sanchit Gandhi ([Twitter](https://twitter.com/sanchitgandhi99) / [Hugging Face](https://huggingface.co/sanchit-gandhi))
49
- * Apolinário Passos ([Twitter](https://twitter.com/multimodalart) / [Hugging Face](https://huggingface.co/multimodalart))
50
- * Pedro Cuenca ([Twitter](https://twitter.com/pcuenq) / [Hugging Face](https://huggingface.co/pcuenq))
51
- {request}
52
- ### Privacy statement
53
- We may store text you enter and generated audio. We store a unique ID for each session. You agree that we may collect, share, and/or publish any data you input for research and/or commercial purposes.
54
- ### License
55
- Generated audio clips cannot be redistributed and may be used for personal, non-commercial use only.
56
- Random sentences are sourced from a filtered subset of the [Harvard Sentences](https://www.cs.columbia.edu/~hgs/audio/harvard.html).
57
- """.strip()
58
- LDESC = """
59
- ## 🏆 Leaderboard
60
- Vote to help the community determine the best text-to-speech (TTS) models.
61
- The leaderboard displays models in descending order of how natural they sound (based on votes cast by the community).
62
- Important: In order to help keep results fair, the leaderboard hides results by default until the number of votes passes a threshold. Tick the `Reveal preliminary results` to show models without sufficient votes. Please note that preliminary results may be inaccurate.
63
- """.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/models.py DELETED
@@ -1,90 +0,0 @@
1
- # Models to include in the leaderboard, only include models that users can vote on
2
- AVAILABLE_MODELS = {
3
- 'ElevenLabs': 'eleven',
4
- 'Play.HT 2.0': 'playht',
5
- 'StyleTTS 2': 'styletts2',
6
- 'Parler TTS Large': 'parlerlarge',
7
- # 'Kokoro v0.19': 'kokoro0.19',
8
- # 'Kokoro v1.0': 'kokorov1',
9
- 'CosyVoice 2.0': 'cosyvoice',
10
- 'PlayDialog 1.0': 'playdialogv1',
11
- 'Papla P1': 'papla',
12
- 'Hume Octave': 'hume',
13
- # 'Fish Speech v1.5': 'anonymousfish',
14
- # 'MeloTTS': 'melo',
15
- # 'PlayDialog': 'playdialog',
16
- # 'XTTSv2': 'xtts',
17
- # 'WhisperSpeech': 'whisperspeech',
18
- # 'OpenVoice': 'openvoice',
19
- #'OpenVoice V2': 'openvoicev2',
20
- # 'Play.HT 3.0 Mini': 'playht3',
21
- # 'MetaVoice': 'metavoice',
22
- #'GPT-SoVITS': 'sovits',
23
- # 'Vokan TTS': 'vokan',
24
- # 'VoiceCraft 2.0': 'voicecraft',
25
- #'Parler TTS': 'parler',
26
- #'Fish Speech v1.4': 'fish',
27
- }
28
-
29
- model_links = {
30
- 'ElevenLabs': 'https://elevenlabs.io/',
31
- 'Play.HT 2.0': 'https://play.ht/',
32
- 'Play.HT 3.0 Mini': 'https://play.ht/',
33
- 'XTTSv2': 'https://huggingface.co/coqui/XTTS-v2',
34
- 'MeloTTS': 'https://github.com/myshell-ai/MeloTTS',
35
- 'StyleTTS 2': 'https://github.com/yl4579/StyleTTS2',
36
- 'Parler TTS Large': 'https://github.com/huggingface/parler-tts',
37
- 'Parler TTS': 'https://github.com/huggingface/parler-tts',
38
- 'Fish Speech v1.5': 'https://github.com/fishaudio/fish-speech',
39
- 'Fish Speech v1.4': 'https://github.com/fishaudio/fish-speech',
40
- 'GPT-SoVITS': 'https://github.com/RVC-Boss/GPT-SoVITS',
41
- 'WhisperSpeech': 'https://github.com/WhisperSpeech/WhisperSpeech',
42
- 'VoiceCraft 2.0': 'https://github.com/jasonppy/VoiceCraft',
43
- 'PlayDialog': 'https://play.ht/',
44
- 'Kokoro v0.19': 'https://huggingface.co/hexgrad/Kokoro-82M',
45
- 'Kokoro v1.0': 'https://huggingface.co/hexgrad/Kokoro-82M',
46
- 'CosyVoice 2.0': 'https://github.com/FunAudioLLM/CosyVoice',
47
- 'MetaVoice': 'https://github.com/metavoiceio/metavoice-src',
48
- 'OpenVoice': 'https://github.com/myshell-ai/OpenVoice',
49
- 'OpenVoice V2': 'https://github.com/myshell-ai/OpenVoice',
50
- 'Pheme': 'https://github.com/PolyAI-LDN/pheme',
51
- 'Vokan TTS': 'https://huggingface.co/ShoukanLabs/Vokan',
52
- 'Papla P1': 'https://papla.media',
53
- 'Hume Octave': 'https://www.hume.ai'
54
- }
55
-
56
- closed_source = [
57
- 'ElevenLabs',
58
- 'Play.HT 2.0',
59
- 'Play.HT 3.0 Mini',
60
- 'PlayDialog',
61
- 'Papla P1',
62
- 'Hume Octave'
63
- ]
64
-
65
- # Model name mapping, can include models that users cannot vote on
66
- model_names = {
67
- 'styletts2': 'StyleTTS 2',
68
- 'tacotron': 'Tacotron',
69
- 'tacotronph': 'Tacotron Phoneme',
70
- 'tacotrondca': 'Tacotron DCA',
71
- 'speedyspeech': 'Speedy Speech',
72
- 'overflow': 'Overflow TTS',
73
- 'anonymoussparkle': 'Anonymous Sparkle',
74
- 'vits': 'VITS',
75
- 'vitsneon': 'VITS Neon',
76
- 'neuralhmm': 'Neural HMM',
77
- 'glow': 'Glow TTS',
78
- 'fastpitch': 'FastPitch',
79
- 'jenny': 'Jenny',
80
- 'tortoise': 'Tortoise TTS',
81
- 'xtts2': 'Coqui XTTSv2',
82
- 'xtts': 'Coqui XTTS',
83
- 'openvoice': 'MyShell OpenVoice',
84
- 'elevenlabs': 'ElevenLabs',
85
- 'openai': 'OpenAI',
86
- 'hierspeech': 'HierSpeech++',
87
- 'pheme': 'PolyAI Pheme',
88
- 'speecht5': 'SpeechT5',
89
- 'metavoice': 'MetaVoice-1B',
90
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/synth.py DELETED
@@ -1,240 +0,0 @@
1
- from .models import *
2
- from .utils import *
3
- from .config import *
4
- from .init import *
5
-
6
- import gradio as gr
7
- from pydub import AudioSegment
8
- import random, os, threading, tempfile
9
- from langdetect import detect
10
- from .vote import log_text
11
-
12
- def random_m():
13
- return random.sample(list(set(AVAILABLE_MODELS.keys())), 2)
14
-
15
- def check_toxicity(text):
16
- if not TOXICITY_CHECK:
17
- return False
18
- return toxicity.predict(text)['toxicity'] > 0.8
19
-
20
- def synthandreturn(text):
21
- text = text.strip()
22
- if len(text) > MAX_SAMPLE_TXT_LENGTH:
23
- raise gr.Error(f'You exceeded the limit of {MAX_SAMPLE_TXT_LENGTH} characters')
24
- if len(text) < MIN_SAMPLE_TXT_LENGTH:
25
- raise gr.Error(f'Please input a text longer than {MIN_SAMPLE_TXT_LENGTH} characters')
26
- if (
27
- # test toxicity if not prepared text
28
- text not in sents
29
- and check_toxicity(text)
30
- ):
31
- print(f'Detected toxic content! "{text}"')
32
- raise gr.Error('Your text failed the toxicity test')
33
- if not text:
34
- raise gr.Error(f'You did not enter any text')
35
- # Check language
36
- try:
37
- if not detect(text) == "en":
38
- gr.Warning('Warning: The input text may not be in English')
39
- except:
40
- pass
41
- # Get two random models
42
- mdl1, mdl2 = random.sample(list(AVAILABLE_MODELS.keys()), 2)
43
- log_text(text)
44
- print("[debug] Using", mdl1, mdl2)
45
- def predict_and_update_result(text, model, result_storage):
46
- try:
47
- if model in AVAILABLE_MODELS:
48
- result = router.predict(text, AVAILABLE_MODELS[model].lower(), api_name="/synthesize")
49
- else:
50
- result = router.predict(text, model.lower(), api_name="/synthesize")
51
- except:
52
- raise gr.Error('Unable to call API, please try again :)')
53
- print('Done with', model)
54
- # try:
55
- # doresample(result)
56
- # except:
57
- # pass
58
- try:
59
- with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f:
60
- audio = AudioSegment.from_file(result)
61
- current_sr = audio.frame_rate
62
- if current_sr > 24000:
63
- audio = audio.set_frame_rate(24000)
64
- try:
65
- print('Trying to normalize audio')
66
- audio = match_target_amplitude(audio, -20)
67
- except:
68
- print('[WARN] Unable to normalize audio')
69
- audio.export(f.name, format="wav")
70
- os.unlink(result)
71
- result = f.name
72
- except:
73
- pass
74
- if model in AVAILABLE_MODELS.keys(): model = AVAILABLE_MODELS[model]
75
- print(model)
76
- print(f"Running model {model}")
77
- result_storage[model] = result
78
- # try:
79
- # doloudnorm(result)
80
- # except:
81
- # pass
82
- mdl1k = mdl1
83
- mdl2k = mdl2
84
- print(mdl1k, mdl2k)
85
- if mdl1 in AVAILABLE_MODELS.keys(): mdl1k=AVAILABLE_MODELS[mdl1]
86
- if mdl2 in AVAILABLE_MODELS.keys(): mdl2k=AVAILABLE_MODELS[mdl2]
87
- results = {}
88
- print(f"Sending models {mdl1k} and {mdl2k} to API")
89
- thread1 = threading.Thread(target=predict_and_update_result, args=(text, mdl1k, results))
90
- thread2 = threading.Thread(target=predict_and_update_result, args=(text, mdl2k, results))
91
-
92
- thread1.start()
93
- thread2.start()
94
- thread1.join()
95
- thread2.join()
96
- #debug
97
- # print(results)
98
- # print(list(results.keys())[0])
99
- # y, sr = librosa.load(results[list(results.keys())[0]], sr=None)
100
- # print(sr)
101
- # print(list(results.keys())[1])
102
- # y, sr = librosa.load(results[list(results.keys())[1]], sr=None)
103
- # print(sr)
104
- #debug
105
- # outputs = [text, btn, r2, model1, model2, aud1, aud2, abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
106
-
107
- print(f"Retrieving models {mdl1k} and {mdl2k} from API")
108
- return (
109
- text,
110
- "Synthesize",
111
- gr.update(visible=True), # r2
112
- mdl1, # model1
113
- mdl2, # model2
114
- gr.update(visible=True, value=results[mdl1k]), # aud1
115
- gr.update(visible=True, value=results[mdl2k]), # aud2
116
- gr.update(visible=True, interactive=False), #abetter
117
- gr.update(visible=True, interactive=False), #bbetter
118
- gr.update(visible=False), #prevmodel1
119
- gr.update(visible=False), #prevmodel2
120
- gr.update(visible=False), #nxt round btn
121
- )
122
-
123
- # Battle Mode
124
-
125
- def synthandreturn_battle(text, mdl1, mdl2):
126
- if mdl1 == mdl2:
127
- raise gr.Error('You can\'t pick two of the same models.')
128
- text = text.strip()
129
- if len(text) > MAX_SAMPLE_TXT_LENGTH:
130
- raise gr.Error(f'You exceeded the limit of {MAX_SAMPLE_TXT_LENGTH} characters')
131
- if len(text) < MIN_SAMPLE_TXT_LENGTH:
132
- raise gr.Error(f'Please input a text longer than {MIN_SAMPLE_TXT_LENGTH} characters')
133
- if (
134
- # test toxicity if not prepared text
135
- text not in sents
136
- and check_toxicity(text)
137
- ):
138
- print(f'Detected toxic content! "{text}"')
139
- raise gr.Error('Your text failed the toxicity test')
140
- if not text:
141
- raise gr.Error(f'You did not enter any text')
142
- # Check language
143
- try:
144
- if not detect(text) == "en":
145
- gr.Warning('Warning: The input text may not be in English')
146
- except:
147
- pass
148
- # Get two random models
149
- log_text(text)
150
- print("[debug] Using", mdl1, mdl2)
151
- def predict_and_update_result(text, model, result_storage):
152
- try:
153
- if model in AVAILABLE_MODELS:
154
- result = router.predict(text, AVAILABLE_MODELS[model].lower(), api_name="/synthesize")
155
- else:
156
- result = router.predict(text, model.lower(), api_name="/synthesize")
157
- except:
158
- raise gr.Error('Unable to call API, please try again :)')
159
- print('Done with', model)
160
- # try:
161
- # doresample(result)
162
- # except:
163
- # pass
164
- try:
165
- with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f:
166
- audio = AudioSegment.from_file(result)
167
- current_sr = audio.frame_rate
168
- if current_sr > 24000:
169
- audio = audio.set_frame_rate(24000)
170
- try:
171
- print('Trying to normalize audio')
172
- audio = match_target_amplitude(audio, -20)
173
- except:
174
- print('[WARN] Unable to normalize audio')
175
- audio.export(f.name, format="wav")
176
- os.unlink(result)
177
- result = f.name
178
- except:
179
- pass
180
- if model in AVAILABLE_MODELS.keys(): model = AVAILABLE_MODELS[model]
181
- print(model)
182
- print(f"Running model {model}")
183
- result_storage[model] = result
184
- # try:
185
- # doloudnorm(result)
186
- # except:
187
- # pass
188
- mdl1k = mdl1
189
- mdl2k = mdl2
190
- print(mdl1k, mdl2k)
191
- if mdl1 in AVAILABLE_MODELS.keys(): mdl1k=AVAILABLE_MODELS[mdl1]
192
- if mdl2 in AVAILABLE_MODELS.keys(): mdl2k=AVAILABLE_MODELS[mdl2]
193
- results = {}
194
- print(f"Sending models {mdl1k} and {mdl2k} to API")
195
- thread1 = threading.Thread(target=predict_and_update_result, args=(text, mdl1k, results))
196
- thread2 = threading.Thread(target=predict_and_update_result, args=(text, mdl2k, results))
197
-
198
- thread1.start()
199
- thread2.start()
200
- thread1.join()
201
- thread2.join()
202
-
203
- print(f"Retrieving models {mdl1k} and {mdl2k} from API")
204
- return (
205
- text,
206
- "Synthesize",
207
- gr.update(visible=True), # r2
208
- mdl1, # model1
209
- mdl2, # model2
210
- gr.update(visible=True, value=results[mdl1k]), # aud1
211
- gr.update(visible=True, value=results[mdl2k]), # aud2
212
- gr.update(visible=True, interactive=False), #abetter
213
- gr.update(visible=True, interactive=False), #bbetter
214
- gr.update(visible=False), #prevmodel1
215
- gr.update(visible=False), #prevmodel2
216
- gr.update(visible=False), #nxt round btn
217
- )
218
-
219
- # Unlock vote
220
-
221
- def unlock_vote(btn_index, aplayed, bplayed):
222
- # sample played
223
- if btn_index == 0:
224
- aplayed = gr.State(value=True)
225
- if btn_index == 1:
226
- bplayed = gr.State(value=True)
227
-
228
- # both audio samples played
229
- if bool(aplayed) and bool(bplayed):
230
- print('Both audio samples played, voting unlocked')
231
- return [gr.update(interactive=True), gr.update(interactive=True), gr.update(), gr.update()]
232
-
233
- return [gr.update(), gr.update(), aplayed, bplayed]
234
-
235
- def randomsent():
236
- return random.choice(sents), '🎲'
237
- def randomsent_battle():
238
- return tuple(randomsent()) + tuple(random_m())
239
- def clear_stuff():
240
- return "", "Synthesize", gr.update(visible=False), '', '', gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/ui.py DELETED
@@ -1,146 +0,0 @@
1
- import gradio as gr
2
- from .config import *
3
- from .messages import *
4
- from .ui_vote import *
5
- from .ui_battle import *
6
- from .ui_leaderboard import *
7
-
8
- with gr.Blocks() as about:
9
- with gr.Row():
10
- with gr.Accordion("News", open=False):
11
- gr.Markdown(NEWS)
12
- gr.Markdown(ABOUT)
13
-
14
- CSS = """
15
- footer {visibility: hidden}
16
- textbox {resize: none}
17
-
18
- /* Custom scrollbar styles */
19
- ::-webkit-scrollbar {
20
- width: 8px;
21
- height: 8px;
22
- }
23
-
24
- ::-webkit-scrollbar-track {
25
- background: var(--background-fill-primary);
26
- border-radius: 4px;
27
- }
28
-
29
- ::-webkit-scrollbar-thumb {
30
- background: var(--border-color-primary);
31
- border-radius: 4px;
32
- }
33
-
34
- ::-webkit-scrollbar-thumb:hover {
35
- background: var(--body-text-color);
36
- }
37
- """
38
- with gr.Blocks(css=CSS + """
39
- /* Modal styles */
40
- .shortcuts-modal {
41
- display: none;
42
- position: fixed;
43
- top: 50%;
44
- left: 50%;
45
- transform: translate(-50%, -50%);
46
- background: var(--background-fill-primary);
47
- padding: 20px;
48
- border-radius: 8px;
49
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
50
- z-index: 1000;
51
- max-width: 500px;
52
- width: 90%;
53
- }
54
- .shortcuts-modal.show {
55
- display: block;
56
- }
57
- .modal-backdrop {
58
- display: none;
59
- position: fixed;
60
- top: 0;
61
- left: 0;
62
- width: 100%;
63
- height: 100%;
64
- background: rgba(0, 0, 0, 0.5);
65
- backdrop-filter: blur(10px);
66
- z-index: 999;
67
- }
68
- .modal-backdrop.show {
69
- display: block;
70
- }
71
- .close-button {
72
- position: absolute;
73
- top: 10px;
74
- right: 10px;
75
- background: none;
76
- border: none;
77
- font-size: 20px;
78
- cursor: pointer;
79
- color: var(--body-text-color);
80
- }
81
- .close-button:hover {
82
- color: var(--error-text-color);
83
- }
84
- """, theme=gr.themes.Default(font=[gr.themes.GoogleFont("Geist"), "sans-serif"]), title="TTS Arena") as app:
85
- gr.Markdown(DESCR)
86
- gr.TabbedInterface([vote, battle, leaderboard, about], ['Vote', 'Battle', 'Leaderboard', 'About'])
87
- if CITATION_TEXT:
88
- with gr.Row():
89
- with gr.Accordion("Citation", open=False):
90
- gr.Markdown(f"If you use this data in your publication, please cite us!\n\nCopy the BibTeX citation to cite this source:\n\n```bibtext\n{CITATION_TEXT}\n```\n\nPlease note that all generated audio clips should be assumed unsuitable for redistribution or commercial use.")
91
-
92
- # Add modal HTML
93
- gr.HTML("""
94
- <div class="modal-backdrop"></div>
95
- <div class="shortcuts-modal">
96
- <button class="close-button" onclick="toggleModal(false)">×</button>
97
- <h3>Keyboard Shortcuts</h3>
98
- <p><strong>Global:</strong></p>
99
- <ul>
100
- <li><code>?</code> or <code>Shift + /</code> - Show this help dialog</li>
101
- <li><code>Esc</code> - Close this dialog</li>
102
- </ul>
103
- <p><strong>Vote & Battle Mode:</strong></p>
104
- <ul>
105
- <li><code>r</code> - Generate random text</li>
106
- <li><code>Ctrl/Cmd + Enter</code> - Synthesize text</li>
107
- <li><code>a</code> - Vote for option A</li>
108
- <li><code>b</code> - Vote for option B</li>
109
- </ul>
110
- </div>
111
- """)
112
-
113
- # # Add modal control JavaScript
114
- # app.load(None, None, js="""
115
- # function() {
116
- # function toggleModal(show) {
117
- # document.querySelector('.shortcuts-modal').classList.toggle('show', show);
118
- # document.querySelector('.modal-backdrop').classList.toggle('show', show);
119
- # }
120
-
121
- # document.addEventListener('keydown', function(e) {
122
- # // Only handle shortcuts when not typing in an input
123
- # if (document.activeElement.tagName === 'INPUT' ||
124
- # document.activeElement.tagName === 'TEXTAREA') {
125
- # return;
126
- # }
127
-
128
- # // Check for shift + / or ? key
129
- # if ((e.key === '/' && e.shiftKey) || e.key === '?') {
130
- # toggleModal(true);
131
- # }
132
- # // Check for escape key
133
- # else if (e.key === 'Escape') {
134
- # toggleModal(false);
135
- # }
136
- # });
137
-
138
- # // Close modal when clicking backdrop
139
- # document.querySelector('.modal-backdrop').addEventListener('click', function() {
140
- # toggleModal(false);
141
- # });
142
-
143
- # // Make toggleModal available globally
144
- # window.toggleModal = toggleModal;
145
- # }
146
- # """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/ui_battle.py DELETED
@@ -1,89 +0,0 @@
1
- import gradio as gr
2
- from .config import *
3
- from .ui import *
4
- from .synth import *
5
- from .vote import *
6
- from .messages import *
7
-
8
- def disable():
9
- return [gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)]
10
- def enable():
11
- return [gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)]
12
-
13
-
14
- with gr.Blocks() as battle:
15
- battle_useridstate = gr.State()
16
-
17
- gr.Markdown(BATTLE_INSTR)
18
- model1 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
19
- model2 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
20
- with gr.Group():
21
- with gr.Row():
22
- text = gr.Textbox(container=False, show_label=False, placeholder="Enter text to synthesize", lines=1, max_lines=1, scale=9999999, min_width=0)
23
- randomt_battle = gr.Button('🎲', scale=0, min_width=0, variant='tool', elem_id="battle-random-button")
24
- with gr.Row():
25
- with gr.Column(scale=10):
26
- model1s = gr.Dropdown(label="Model 1", container=False, show_label=False, choices=AVAILABLE_MODELS.keys(), interactive=True, value=list(AVAILABLE_MODELS.keys())[0])
27
- with gr.Column(scale=10):
28
- model2s = gr.Dropdown(label="Model 2", container=False, show_label=False, choices=AVAILABLE_MODELS.keys(), interactive=True, value=list(AVAILABLE_MODELS.keys())[1])
29
- randomt_battle.click(randomsent_battle, outputs=[text, randomt_battle, model1s, model2s])
30
- btn = gr.Button("Synthesize", variant='primary', elem_id="battle-synth-button")
31
- with gr.Row(visible=False) as r2:
32
- with gr.Column():
33
- with gr.Group():
34
- aud1 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, autoplay=True, elem_id="battle-a-audio")
35
- abetter = gr.Button("A is better", variant='primary', elem_id="battle-a-button")
36
- prevmodel1 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model A", text_align="center", lines=1, max_lines=1, visible=False)
37
- with gr.Column():
38
- with gr.Group():
39
- aud2 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, elem_id="battle-b-audio")
40
- bbetter = gr.Button("B is better", variant='primary', elem_id="battle-b-button")
41
- prevmodel2 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model B", text_align="center", lines=1, max_lines=1, visible=False)
42
- aud1.stop(None, None, js="""function() {
43
- document.getElementById('battle-b-audio')?.querySelector('button.play-pause-button')?.click();
44
- }""")
45
- outputs = [
46
- text,
47
- btn,
48
- r2,
49
- model1,
50
- model2,
51
- aud1,
52
- aud2,
53
- abetter,
54
- bbetter,
55
- prevmodel1,
56
- prevmodel2,
57
- ]
58
- btn.click(disable, outputs=[btn, abetter, bbetter]).then(synthandreturn_battle, inputs=[text, model1s, model2s], outputs=outputs).then(enable, outputs=[btn, abetter, bbetter])
59
- nxt_outputs = [abetter, bbetter, prevmodel1, prevmodel2]
60
- abetter.click(a_is_better_battle, outputs=nxt_outputs, inputs=[model1, model2, battle_useridstate])
61
- bbetter.click(b_is_better_battle, outputs=nxt_outputs, inputs=[model1, model2, battle_useridstate])
62
- # battle.load(random_m, outputs=[model1s, model2s], js="""function() {
63
- # document.addEventListener('keydown', function(e) {
64
- # // Only handle shortcuts if we're on the battle tab
65
- # if (!document.querySelector('#battle-a-button')?.offsetParent) {
66
- # // Check if random button is visible
67
- # if (document.querySelector('#battle-random-button')?.offsetParent) {
68
- # if (e.key === 'r') {
69
- # document.getElementById('battle-random-button')?.click();
70
- # } else if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
71
- # document.getElementById('battle-synth-button')?.click();
72
- # }
73
- # }
74
- # return;
75
- # }
76
-
77
- # // Only handle A and B keys when not typing in an input
78
- # if (document.activeElement.tagName === 'INPUT' ||
79
- # document.activeElement.tagName === 'TEXTAREA') {
80
- # return;
81
- # }
82
-
83
- # if (e.key.toLowerCase() === 'a') {
84
- # document.getElementById('battle-a-button')?.click();
85
- # } else if (e.key.toLowerCase() === 'b') {
86
- # document.getElementById('battle-b-button')?.click();
87
- # }
88
- # });
89
- # }""")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/ui_leaderboard.py DELETED
@@ -1,55 +0,0 @@
1
- import gradio as gr
2
- from .config import *
3
- from .leaderboard import *
4
- from .messages import *
5
-
6
- with gr.Blocks() as leaderboard:
7
- gr.Markdown(LDESC)
8
- table = gr.HTML() # Changed to HTML to support custom CSS
9
- reloadbtn = gr.Button("Refresh")
10
- with gr.Row():
11
- with gr.Column(scale=1):
12
- reveal_prelim = gr.Checkbox(
13
- label="Reveal preliminary results",
14
- info="Show all models, including models with very few human ratings.",
15
- )
16
- with gr.Column(scale=1):
17
- hide_battle_votes = gr.Checkbox(
18
- label="Hide Battle Mode votes",
19
- info="Exclude votes obtained through Battle Mode.",
20
- )
21
- with gr.Column(scale=1):
22
- sort_by_elo = gr.Checkbox(
23
- label="Sort by Arena Score",
24
- info="Sort models by Arena Score instead of win rate",
25
- value=True,
26
- )
27
- with gr.Column(scale=1):
28
- hide_proprietary = gr.Checkbox(
29
- label="Hide proprietary models",
30
- info="Show only open models",
31
- value=False,
32
- )
33
-
34
- def update_leaderboard(*args):
35
- return get_leaderboard(*args)
36
-
37
- reveal_prelim.input(update_leaderboard,
38
- inputs=[reveal_prelim, hide_battle_votes, sort_by_elo, hide_proprietary],
39
- outputs=[table])
40
- hide_battle_votes.input(update_leaderboard,
41
- inputs=[reveal_prelim, hide_battle_votes, sort_by_elo, hide_proprietary],
42
- outputs=[table])
43
- sort_by_elo.input(update_leaderboard,
44
- inputs=[reveal_prelim, hide_battle_votes, sort_by_elo, hide_proprietary],
45
- outputs=[table])
46
- hide_proprietary.input(update_leaderboard,
47
- inputs=[reveal_prelim, hide_battle_votes, sort_by_elo, hide_proprietary],
48
- outputs=[table])
49
- leaderboard.load(update_leaderboard,
50
- inputs=[reveal_prelim, hide_battle_votes, sort_by_elo, hide_proprietary],
51
- outputs=[table])
52
- reloadbtn.click(update_leaderboard,
53
- inputs=[reveal_prelim, hide_battle_votes, sort_by_elo, hide_proprietary],
54
- outputs=[table])
55
- # gr.Markdown("DISCLAIMER: The licenses listed may not be accurate or up to date, you are responsible for checking the licenses before using the models. Also note that some models may have additional usage restrictions.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/ui_vote.py DELETED
@@ -1,113 +0,0 @@
1
- import gradio as gr
2
- from .config import *
3
- from .synth import *
4
- from .vote import *
5
- from .messages import *
6
-
7
- def disable():
8
- return [gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)]
9
- def enable():
10
- return [gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)]
11
-
12
-
13
- with gr.Blocks() as vote:
14
- # sample played
15
- #aplayed = gr.State(value=False)
16
- #bplayed = gr.State(value=False)
17
- # voter ID
18
- useridstate = gr.State()
19
- gr.Markdown(INSTR)
20
- with gr.Group():
21
- with gr.Row():
22
- text = gr.Textbox(container=False, show_label=False, placeholder="Enter text to synthesize", lines=1, max_lines=1, scale=9999999, min_width=0)
23
- randomt = gr.Button('🎲', scale=0, min_width=0, variant='tool', elem_id="vote-random-button")
24
- randomt.click(randomsent, outputs=[text, randomt])
25
- btn = gr.Button("Synthesize", variant='primary', elem_id="vote-synth-button")
26
- model1 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
27
- #model1 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=True)
28
- model2 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
29
- #model2 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=True)
30
- with gr.Row(visible=False) as r2:
31
- with gr.Column():
32
- with gr.Group():
33
- aud1 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, autoplay=True, elem_id="vote-a-audio")
34
- abetter = gr.Button("A is better", variant='primary', elem_id="vote-a-button")
35
- prevmodel1 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model A", text_align="center", lines=1, max_lines=1, visible=False)
36
- with gr.Column():
37
- with gr.Group():
38
- aud2 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, elem_id="vote-b-audio")
39
- bbetter = gr.Button("B is better", variant='primary', elem_id="vote-b-button")
40
- prevmodel2 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model B", text_align="center", lines=1, max_lines=1, visible=False)
41
- aud1.stop(None, None, js="""function() {
42
- document.getElementById('vote-b-audio')?.querySelector('button.play-pause-button')?.click();
43
- }""")
44
- nxtroundbtn = gr.Button('Next round', visible=False)
45
- # outputs = [text, btn, r2, model1, model2, prevmodel1, aud1, prevmodel2, aud2, abetter, bbetter]
46
- outputs = [
47
- text,
48
- btn,
49
- r2,
50
- model1,
51
- model2,
52
- aud1,
53
- aud2,
54
- abetter,
55
- bbetter,
56
- prevmodel1,
57
- prevmodel2,
58
- nxtroundbtn
59
- ]
60
- """
61
- text,
62
- "Synthesize",
63
- gr.update(visible=True), # r2
64
- mdl1, # model1
65
- mdl2, # model2
66
- gr.update(visible=True, value=results[mdl1]), # aud1
67
- gr.update(visible=True, value=results[mdl2]), # aud2
68
- gr.update(visible=True, interactive=False), #abetter
69
- gr.update(visible=True, interactive=False), #bbetter
70
- gr.update(visible=False), #prevmodel1
71
- gr.update(visible=False), #prevmodel2
72
- gr.update(visible=False), #nxt round btn"""
73
- btn.click(disable, outputs=[btn, abetter, bbetter]).then(synthandreturn, inputs=[text], outputs=outputs).then(enable, outputs=[btn, abetter, bbetter])
74
- nxtroundbtn.click(clear_stuff, outputs=outputs)
75
-
76
- # Allow interaction with the vote buttons only when both audio samples have finished playing
77
- #aud1.stop(unlock_vote, outputs=[abetter, bbetter, aplayed, bplayed], inputs=[gr.State(value=0), aplayed, bplayed])
78
- #aud2.stop(unlock_vote, outputs=[abetter, bbetter, aplayed, bplayed], inputs=[gr.State(value=1), aplayed, bplayed])
79
-
80
- # nxt_outputs = [prevmodel1, prevmodel2, abetter, bbetter]
81
- nxt_outputs = [abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
82
- abetter.click(a_is_better, outputs=nxt_outputs, inputs=[model1, model2, useridstate])
83
- bbetter.click(b_is_better, outputs=nxt_outputs, inputs=[model1, model2, useridstate])
84
-
85
- # Add custom JS for keyboard shortcuts
86
- # vote.load(None, None, js="""function() {
87
- # document.addEventListener('keydown', function(e) {
88
- # // Only handle shortcuts if we're on the vote tab
89
- # if (!document.querySelector('#vote-a-button')?.offsetParent) {
90
- # // Check if random button is visible
91
- # if (document.querySelector('#vote-random-button')?.offsetParent) {
92
- # if (e.key === 'r') {
93
- # document.getElementById('vote-random-button')?.click();
94
- # } else if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
95
- # document.getElementById('vote-synth-button')?.click();
96
- # }
97
- # }
98
- # return;
99
- # }
100
-
101
- # // Only handle A and B keys when not typing in an input
102
- # if (document.activeElement.tagName === 'INPUT' ||
103
- # document.activeElement.tagName === 'TEXTAREA') {
104
- # return;
105
- # }
106
-
107
- # if (e.key.toLowerCase() === 'a') {
108
- # document.getElementById('vote-a-button')?.click();
109
- # } else if (e.key.toLowerCase() === 'b') {
110
- # document.getElementById('vote-b-button')?.click();
111
- # }
112
- # });
113
- # }""")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/utils.py DELETED
@@ -1,20 +0,0 @@
1
- import uuid
2
- import soundfile as sf
3
- import pydub
4
- import pyloudnorm as pyln
5
-
6
- def match_target_amplitude(sound, target_dBFS):
7
- change_in_dBFS = target_dBFS - sound.dBFS
8
- return sound.apply_gain(change_in_dBFS)
9
-
10
- def mkuuid(uid):
11
- if not uid:
12
- uid = uuid.uuid4()
13
- return uid
14
-
15
- def doloudnorm(path):
16
- data, rate = sf.read(path)
17
- meter = pyln.Meter(rate)
18
- loudness = meter.integrated_loudness(data)
19
- loudness_normalized_audio = pyln.normalize.loudness(data, loudness, -12.0)
20
- sf.write(path, loudness_normalized_audio, rate)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/vote.py DELETED
@@ -1,114 +0,0 @@
1
- from .utils import *
2
- from .config import *
3
- from .models import *
4
- from .db import *
5
- from .init import *
6
-
7
- import gradio as gr
8
-
9
- # Logging
10
-
11
- def log_text(text):
12
- conn = get_db()
13
- cursor = conn.cursor()
14
- cursor.execute('INSERT INTO spokentext (spokentext) VALUES (?)', (text,))
15
- if scheduler:
16
- with scheduler.lock:
17
- conn.commit()
18
- else:
19
- conn.commit()
20
- cursor.close()
21
-
22
- # Vote
23
-
24
- def upvote_model(model, uname, battle=False):
25
- conn = get_db()
26
- cursor = conn.cursor()
27
- if battle: uname = "unknown_battle"
28
- cursor.execute('UPDATE model SET upvote = upvote + 1 WHERE name = ?', (model,))
29
- if cursor.rowcount == 0:
30
- cursor.execute('INSERT OR REPLACE INTO model (name, upvote, downvote) VALUES (?, 1, 0)', (model,))
31
- cursor.execute('INSERT INTO vote (username, model, vote) VALUES (?, ?, ?)', (uname, model, 1,))
32
- if scheduler:
33
- with scheduler.lock:
34
- conn.commit()
35
- else:
36
- conn.commit()
37
- cursor.close()
38
-
39
- def downvote_model(model, uname, battle=False):
40
- conn = get_db()
41
- cursor = conn.cursor()
42
- if battle: uname = "unknown_battle"
43
- cursor.execute('UPDATE model SET downvote = downvote + 1 WHERE name = ?', (model,))
44
- if cursor.rowcount == 0:
45
- cursor.execute('INSERT OR REPLACE INTO model (name, upvote, downvote) VALUES (?, 0, 1)', (model,))
46
- cursor.execute('INSERT INTO vote (username, model, vote) VALUES (?, ?, ?)', (uname, model, -1,))
47
- if scheduler:
48
- with scheduler.lock:
49
- conn.commit()
50
- else:
51
- conn.commit()
52
- cursor.close()
53
-
54
- # Battle Mode
55
-
56
- def a_is_better_battle(model1, model2, userid):
57
- return a_is_better(model1, model2, 'unknown_battle', True)
58
- def b_is_better_battle(model1, model2, userid):
59
- return b_is_better(model1, model2, 'unknown_battle', True)
60
-
61
- # A/B better
62
-
63
- def a_is_better(model1, model2, userid, battle=False):
64
- print("A is better", model1, model2)
65
- if not model1 in AVAILABLE_MODELS.keys() and not model1 in AVAILABLE_MODELS.values():
66
- raise gr.Error('Sorry, please try voting again.')
67
- userid = mkuuid(userid)
68
- if model1 and model2:
69
- conn = get_db()
70
- cursor = conn.cursor()
71
- cursor.execute('INSERT INTO votelog (username, chosen, rejected) VALUES (?, ?, ?)', (str(userid), model1, model2,))
72
- if scheduler:
73
- with scheduler.lock:
74
- conn.commit()
75
- else:
76
- conn.commit()
77
- cursor.close()
78
- upvote_model(model1, str(userid), battle)
79
- downvote_model(model2, str(userid), battle)
80
- return reload(model1, model2, userid, chose_a=True)
81
- def b_is_better(model1, model2, userid, battle=False):
82
- print("B is better", model1, model2)
83
- if not model1 in AVAILABLE_MODELS.keys() and not model1 in AVAILABLE_MODELS.values():
84
- raise gr.Error('Sorry, please try voting again.')
85
- userid = mkuuid(userid)
86
- if model1 and model2:
87
- conn = get_db()
88
- cursor = conn.cursor()
89
- cursor.execute('INSERT INTO votelog (username, chosen, rejected) VALUES (?, ?, ?)', (str(userid), model2, model1,))
90
- if scheduler:
91
- with scheduler.lock:
92
- conn.commit()
93
- else:
94
- conn.commit()
95
- cursor.close()
96
- upvote_model(model2, str(userid), battle)
97
- downvote_model(model1, str(userid), battle)
98
- return reload(model1, model2, userid, chose_b=True)
99
-
100
- # Reload
101
-
102
- def reload(chosenmodel1=None, chosenmodel2=None, userid=None, chose_a=False, chose_b=False):
103
- out = [
104
- gr.update(interactive=False, visible=False),
105
- gr.update(interactive=False, visible=False)
106
- ]
107
- if chose_a == True:
108
- out.append(gr.update(value=f'Your vote: {chosenmodel1}', interactive=False, visible=True))
109
- out.append(gr.update(value=f'{chosenmodel2}', interactive=False, visible=True))
110
- else:
111
- out.append(gr.update(value=f'{chosenmodel1}', interactive=False, visible=True))
112
- out.append(gr.update(value=f'Your vote: {chosenmodel2}', interactive=False, visible=True))
113
- out.append(gr.update(visible=True))
114
- return out