Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
funcs must be at top
Browse files
app.py
CHANGED
|
@@ -19,18 +19,9 @@ DB_PATH = "database.db"
|
|
| 19 |
AUDIO_DATASET_ID = "ttseval/tts-arena-new"
|
| 20 |
|
| 21 |
####################################
|
| 22 |
-
#
|
| 23 |
####################################
|
| 24 |
|
| 25 |
-
# Download existing DB
|
| 26 |
-
print("Downloading DB...")
|
| 27 |
-
try:
|
| 28 |
-
cache_path = hf_hub_download(repo_id=DB_DATASET_ID, repo_type='dataset', filename=DB_NAME)
|
| 29 |
-
shutil.copyfile(cache_path, DB_PATH)
|
| 30 |
-
print("Downloaded DB")
|
| 31 |
-
except Exception as e:
|
| 32 |
-
print("Error while downloading DB:", e)
|
| 33 |
-
|
| 34 |
def create_db_if_missing():
|
| 35 |
conn = get_db()
|
| 36 |
cursor = conn.cursor()
|
|
@@ -49,6 +40,53 @@ def create_db_if_missing():
|
|
| 49 |
vote INTEGER
|
| 50 |
);
|
| 51 |
''')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
# Create DB table (if doesn't exist)
|
| 54 |
create_db_if_missing()
|
|
@@ -191,38 +229,6 @@ model_licenses = {
|
|
| 191 |
# return get_random_split(choice)
|
| 192 |
# else:
|
| 193 |
# return choice
|
| 194 |
-
def get_db():
|
| 195 |
-
return sqlite3.connect(DB_PATH)
|
| 196 |
-
|
| 197 |
-
def get_leaderboard():
|
| 198 |
-
conn = get_db()
|
| 199 |
-
cursor = conn.cursor()
|
| 200 |
-
cursor.execute('SELECT name, upvote, downvote FROM model WHERE (upvote + downvote) > 5')
|
| 201 |
-
data = cursor.fetchall()
|
| 202 |
-
df = pd.DataFrame(data, columns=['name', 'upvote', 'downvote'])
|
| 203 |
-
df['license'] = df['name'].replace(model_licenses)
|
| 204 |
-
df['name'] = df['name'].replace(model_names)
|
| 205 |
-
df['votes'] = df['upvote'] + df['downvote']
|
| 206 |
-
# df['score'] = round((df['upvote'] / df['votes']) * 100, 2) # Percentage score
|
| 207 |
-
|
| 208 |
-
## ELO SCORE
|
| 209 |
-
df['score'] = 1200
|
| 210 |
-
for i in range(len(df)):
|
| 211 |
-
for j in range(len(df)):
|
| 212 |
-
if i != j:
|
| 213 |
-
expected_a = 1 / (1 + 10 ** ((df['score'][j] - df['score'][i]) / 400))
|
| 214 |
-
expected_b = 1 / (1 + 10 ** ((df['score'][i] - df['score'][j]) / 400))
|
| 215 |
-
actual_a = df['upvote'][i] / df['votes'][i]
|
| 216 |
-
actual_b = df['upvote'][j] / df['votes'][j]
|
| 217 |
-
df.at[i, 'score'] += 32 * (actual_a - expected_a)
|
| 218 |
-
df.at[j, 'score'] += 32 * (actual_b - expected_b)
|
| 219 |
-
df['score'] = round(df['score'])
|
| 220 |
-
## ELO SCORE
|
| 221 |
-
df = df.sort_values(by='score', ascending=False)
|
| 222 |
-
df['order'] = ['#' + str(i + 1) for i in range(len(df))]
|
| 223 |
-
# df = df[['name', 'score', 'upvote', 'votes']]
|
| 224 |
-
df = df[['order', 'name', 'score', 'license', 'votes']]
|
| 225 |
-
return df
|
| 226 |
|
| 227 |
# def get_random_splits():
|
| 228 |
# choice1 = get_random_split()
|
|
|
|
| 19 |
AUDIO_DATASET_ID = "ttseval/tts-arena-new"
|
| 20 |
|
| 21 |
####################################
|
| 22 |
+
# Functions
|
| 23 |
####################################
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def create_db_if_missing():
|
| 26 |
conn = get_db()
|
| 27 |
cursor = conn.cursor()
|
|
|
|
| 40 |
vote INTEGER
|
| 41 |
);
|
| 42 |
''')
|
| 43 |
+
def get_db():
|
| 44 |
+
return sqlite3.connect(DB_PATH)
|
| 45 |
+
|
| 46 |
+
def get_leaderboard():
|
| 47 |
+
conn = get_db()
|
| 48 |
+
cursor = conn.cursor()
|
| 49 |
+
cursor.execute('SELECT name, upvote, downvote FROM model WHERE (upvote + downvote) > 5')
|
| 50 |
+
data = cursor.fetchall()
|
| 51 |
+
df = pd.DataFrame(data, columns=['name', 'upvote', 'downvote'])
|
| 52 |
+
df['license'] = df['name'].replace(model_licenses)
|
| 53 |
+
df['name'] = df['name'].replace(model_names)
|
| 54 |
+
df['votes'] = df['upvote'] + df['downvote']
|
| 55 |
+
# df['score'] = round((df['upvote'] / df['votes']) * 100, 2) # Percentage score
|
| 56 |
+
|
| 57 |
+
## ELO SCORE
|
| 58 |
+
df['score'] = 1200
|
| 59 |
+
for i in range(len(df)):
|
| 60 |
+
for j in range(len(df)):
|
| 61 |
+
if i != j:
|
| 62 |
+
expected_a = 1 / (1 + 10 ** ((df['score'][j] - df['score'][i]) / 400))
|
| 63 |
+
expected_b = 1 / (1 + 10 ** ((df['score'][i] - df['score'][j]) / 400))
|
| 64 |
+
actual_a = df['upvote'][i] / df['votes'][i]
|
| 65 |
+
actual_b = df['upvote'][j] / df['votes'][j]
|
| 66 |
+
df.at[i, 'score'] += 32 * (actual_a - expected_a)
|
| 67 |
+
df.at[j, 'score'] += 32 * (actual_b - expected_b)
|
| 68 |
+
df['score'] = round(df['score'])
|
| 69 |
+
## ELO SCORE
|
| 70 |
+
df = df.sort_values(by='score', ascending=False)
|
| 71 |
+
df['order'] = ['#' + str(i + 1) for i in range(len(df))]
|
| 72 |
+
# df = df[['name', 'score', 'upvote', 'votes']]
|
| 73 |
+
df = df[['order', 'name', 'score', 'license', 'votes']]
|
| 74 |
+
return df
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
####################################
|
| 78 |
+
# Space initialization
|
| 79 |
+
####################################
|
| 80 |
+
|
| 81 |
+
# Download existing DB
|
| 82 |
+
print("Downloading DB...")
|
| 83 |
+
try:
|
| 84 |
+
cache_path = hf_hub_download(repo_id=DB_DATASET_ID, repo_type='dataset', filename=DB_NAME)
|
| 85 |
+
shutil.copyfile(cache_path, DB_PATH)
|
| 86 |
+
print("Downloaded DB")
|
| 87 |
+
except Exception as e:
|
| 88 |
+
print("Error while downloading DB:", e)
|
| 89 |
+
|
| 90 |
|
| 91 |
# Create DB table (if doesn't exist)
|
| 92 |
create_db_if_missing()
|
|
|
|
| 229 |
# return get_random_split(choice)
|
| 230 |
# else:
|
| 231 |
# return choice
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
# def get_random_splits():
|
| 234 |
# choice1 = get_random_split()
|