rjzevallos commited on
Commit
a25ae1b
verified
1 Parent(s): b802937

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -109
app.py CHANGED
@@ -1,32 +1,9 @@
1
  import gradio as gr
2
- import pandas as pd
3
- from langdetect import detect
4
- from datasets import load_dataset
5
- import threading, time, uuid, sqlite3, shutil, os, random, asyncio, threading
6
- from pathlib import Path
7
- from huggingface_hub import CommitScheduler, delete_file, hf_hub_download
8
- from gradio_client import Client
9
- import pyloudnorm as pyln
10
- import soundfile as sf
11
- import librosa
12
- from detoxify import Detoxify
13
  import os
14
- import tempfile
15
- from pydub import AudioSegment
16
-
17
- def match_target_amplitude(sound, target_dBFS):
18
- change_in_dBFS = target_dBFS - sound.dBFS
19
- return sound.apply_gain(change_in_dBFS)
20
-
21
-
22
 
23
- toxicity = Detoxify('original')
24
- with open('bsc.txt') as f:
25
- sents = f.read().strip().splitlines()
26
-
27
-
28
  ####################################
29
- # Constants
30
  ####################################
31
  AVAILABLE_MODELS = {
32
  'XTTSv2': 'xtts',
@@ -43,84 +20,46 @@ AVAILABLE_MODELS = {
43
  SPACE_ID = os.getenv('SPACE_ID')
44
  MAX_SAMPLE_TXT_LENGTH = 300
45
  MIN_SAMPLE_TXT_LENGTH = 10
46
- DB_DATASET_ID = os.getenv('DATASET_ID')
47
- DB_NAME = "database.db"
48
-
49
- # If /data available => means local storage is enabled => let's use it!
50
- DB_PATH = f"/data/{DB_NAME}" if os.path.isdir("/data") else DB_NAME
51
- print(f"Using {DB_PATH}")
52
-
53
 
54
  ####################################
55
- # Functions
56
  ####################################
57
-
58
- def create_db_if_missing():
59
- conn = get_db()
60
- cursor = conn.cursor()
61
- cursor.execute('''
62
- CREATE TABLE IF NOT EXISTS model (
63
- name TEXT UNIQUE,
64
- upvote INTEGER,
65
- downvote INTEGER
66
- );
67
- ''')
68
- cursor.execute('''
69
- CREATE TABLE IF NOT EXISTS vote (
70
- id INTEGER PRIMARY KEY AUTOINCREMENT,
71
- username TEXT,
72
- model TEXT,
73
- vote INTEGER,
74
- timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
75
- );
76
- ''')
77
- cursor.execute('''
78
- CREATE TABLE IF NOT EXISTS votelog (
79
- id INTEGER PRIMARY KEY AUTOINCREMENT,
80
- username TEXT,
81
- chosen TEXT,
82
- rejected TEXT,
83
- timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
84
- );
85
- ''')
86
- cursor.execute('''
87
- CREATE TABLE IF NOT EXISTS spokentext (
88
- id INTEGER PRIMARY KEY AUTOINCREMENT,
89
- spokentext TEXT,
90
- timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
91
- );
92
- ''')
93
- def get_db():
94
- return sqlite3.connect(DB_PATH)
95
-
96
-
97
 
98
  ####################################
99
- # Space initialization
100
  ####################################
101
 
102
- # Download existing DB
103
- if not os.path.isfile(DB_PATH):
104
- print("Downloading DB...")
105
- try:
106
- cache_path = hf_hub_download(repo_id=DB_DATASET_ID, repo_type='dataset', filename=DB_NAME)
107
- shutil.copyfile(cache_path, DB_PATH)
108
- print("Downloaded DB")
109
- except Exception as e:
110
- print("Error while downloading DB:", e)
 
 
 
 
 
111
 
112
- # Create DB table (if doesn't exist)
113
- create_db_if_missing()
114
-
115
- # Sync local DB with remote repo every 5 minute (only if a change is detected)
116
- scheduler = CommitScheduler(
117
- repo_id=DB_DATASET_ID,
118
- repo_type="dataset",
119
- folder_path=Path(DB_PATH).parent,
120
- every=5,
121
- allow_patterns=DB_NAME,
122
- )
123
 
 
124
 
125
  """
126
  ## 馃弳 Leaderboard
@@ -129,25 +68,29 @@ The leaderboard displays models in descending order of how natural they sound (b
129
  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.
130
  """.strip()
131
 
 
 
 
132
 
133
-
134
- def del_db(txt):
135
- if not txt.lower() == 'delete db':
136
- raise gr.Error('You did not enter "delete db"')
137
-
138
- # Delete local + remote
139
- os.remove(DB_PATH)
140
- delete_file(path_in_repo=DB_NAME, repo_id=DB_DATASET_ID, repo_type='dataset')
141
-
142
- # Recreate
143
- create_db_if_missing()
144
- return 'Delete DB'
145
 
146
  theme = gr.themes.Base(
147
  font=[gr.themes.GoogleFont('Libre Franklin'), gr.themes.GoogleFont('Public Sans'), 'system-ui', 'sans-serif'],
148
  )
149
 
 
 
 
 
 
 
 
150
 
151
-
152
-
153
- demo.queue(api_open=False, default_concurrency_limit=40).launch(show_api=False)
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
2
  import os
3
+ from pathlib import Path
 
 
 
 
 
 
 
4
 
 
 
 
 
 
5
  ####################################
6
+ # Constants (static data version)
7
  ####################################
8
  AVAILABLE_MODELS = {
9
  'XTTSv2': 'xtts',
 
20
  SPACE_ID = os.getenv('SPACE_ID')
21
  MAX_SAMPLE_TXT_LENGTH = 300
22
  MIN_SAMPLE_TXT_LENGTH = 10
 
 
 
 
 
 
 
23
 
24
  ####################################
25
+ # Datos est谩ticos del leaderboard
26
  ####################################
27
+ leaderboard_data = [
28
+ {'name': 'XTTSv2', 'upvote': 150, 'downvote': 30},
29
+ {'name': 'ElevenLabs', 'upvote': 200, 'downvote': 50},
30
+ {'name': 'OpenVoice V2', 'upvote': 180, 'downvote': 40},
31
+ {'name': 'Play.HT 2.0', 'upvote': 100, 'downvote': 20},
32
+ {'name': 'MeloTTS', 'upvote': 90, 'downvote': 15},
33
+ {'name': 'StyleTTS 2', 'upvote': 170, 'downvote': 25},
34
+ {'name': 'GPT-SoVITS', 'upvote': 160, 'downvote': 35},
35
+ {'name': 'VoiceCraft 2.0', 'upvote': 140, 'downvote': 25},
36
+ {'name': 'Parler TTS', 'upvote': 110, 'downvote': 22}
37
+ ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  ####################################
40
+ # Functions (static version)
41
  ####################################
42
 
43
+ def get_leaderboard():
44
+ """
45
+ Retorna el leaderboard en orden descendente por votos positivos.
46
+ """
47
+ return sorted(leaderboard_data, key=lambda x: x['upvote'], reverse=True)
48
+
49
+ def filter_preliminary(leaderboard, reveal=False):
50
+ """
51
+ Si reveal es True, muestra todos los resultados.
52
+ Si reveal es False, filtra los modelos con menos de 50 votos combinados.
53
+ """
54
+ if reveal:
55
+ return leaderboard
56
+ return [model for model in leaderboard if model['upvote'] + model['downvote'] > 50]
57
 
58
+ ####################################
59
+ # Space initialization (static version)
60
+ ####################################
 
 
 
 
 
 
 
 
61
 
62
+ # No DB download or sync needed
63
 
64
  """
65
  ## 馃弳 Leaderboard
 
68
  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.
69
  """.strip()
70
 
71
+ ####################################
72
+ # Interfaz con Gradio
73
+ ####################################
74
 
75
+ def update_leaderboard(reveal):
76
+ """
77
+ Actualiza la tabla del leaderboard con base en si se deben mostrar
78
+ resultados preliminares o no.
79
+ """
80
+ filtered_leaderboard = filter_preliminary(get_leaderboard(), reveal)
81
+ return [[model['name'], model['upvote'], model['downvote']] for model in filtered_leaderboard]
 
 
 
 
 
82
 
83
  theme = gr.themes.Base(
84
  font=[gr.themes.GoogleFont('Libre Franklin'), gr.themes.GoogleFont('Public Sans'), 'system-ui', 'sans-serif'],
85
  )
86
 
87
+ with gr.Blocks(theme=theme) as demo:
88
+ gr.Markdown("# 馃弳 Leaderboard\nVote to help the community determine the best TTS models.\n")
89
+
90
+ reveal_checkbox = gr.Checkbox(label="Reveal preliminary results", value=False)
91
+ leaderboard_table = gr.DataFrame(headers=["Model", "Upvotes", "Downvotes"], datatype=["str", "int", "int"], value=update_leaderboard(reveal=False))
92
+
93
+ reveal_checkbox.change(fn=update_leaderboard, inputs=[reveal_checkbox], outputs=[leaderboard_table])
94
 
95
+ # Lanzar la aplicaci贸n
96
+ demo.queue(api_open=False, default_concurrency_limit=40).launch(show_api=False)