-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_tts_task_responses.py
More file actions
276 lines (230 loc) · 10.6 KB
/
Copy pathcheck_tts_task_responses.py
File metadata and controls
276 lines (230 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#!/usr/bin/env python3
"""
Check TTS tasks for responses and extract audio URLs
"""
import sys
import os
from pathlib import Path
# Add project root to path
_project_root = os.path.dirname(os.path.abspath(__file__))
if _project_root not in sys.path:
sys.path.insert(0, _project_root)
from dotenv import load_dotenv
load_dotenv()
from sqlalchemy import create_engine, text
import json
BASE_URL = "https://violet-proxy-bl4w.onrender.com"
def get_database_url():
"""Get database URL from environment or use default"""
database_url = os.getenv(
'DATABASE_URL',
'postgresql://violet_db_user:ZiqeR2tAHgdaxjyi3YGwT3nbXBWW6t1w@dpg-d515p2vfte5s738uemkg-a.oregon-postgres.render.com/violet_db'
)
return database_url
def get_file_public_url(file_id: str):
"""Get public URL for a file from database"""
database_url = get_database_url()
try:
engine = create_engine(
database_url,
pool_pre_ping=True,
connect_args={
"connect_timeout": 10,
"sslmode": "require"
}
)
with engine.connect() as conn:
query = text("""
SELECT public_url, original_filename, file_size
FROM files
WHERE file_id = CAST(:file_id AS uuid)
""")
result = conn.execute(query, {'file_id': file_id})
file_info = result.fetchone()
if file_info:
return {
'public_url': file_info[0],
'filename': file_info[1],
'file_size': file_info[2]
}
return None
engine.dispose()
except Exception as e:
print(f"⚠️ Error querying file: {e}")
return None
def check_task_responses(task_ids):
"""Check tasks for responses and extract audio URLs"""
database_url = get_database_url()
try:
engine = create_engine(
database_url,
pool_pre_ping=True,
connect_args={
"connect_timeout": 10,
"sslmode": "require"
}
)
results = {}
with engine.connect() as conn:
for task_id, model_name in task_ids.items():
print(f"\n{'=' * 80}")
print(f" TASK: {model_name}")
print(f"{'=' * 80}")
print(f"Task ID: {task_id}")
# Get task info
query = text("""
SELECT
task_id,
task_type::text,
status::text,
model_id,
miner_responses,
created_at,
updated_at
FROM tasks
WHERE task_id = CAST(:task_id AS uuid)
""")
result = conn.execute(query, {'task_id': task_id})
task = result.fetchone()
if not task:
print(f"❌ Task not found")
results[task_id] = {
'model': model_name,
'status': 'NOT_FOUND',
'audio_urls': []
}
continue
task_type = task[1]
status = task[2]
model_id = task[3]
miner_responses = task[4]
created_at = task[5]
updated_at = task[6]
print(f"Status: {status}")
print(f"Model ID: {model_id}")
print(f"Created: {created_at}")
print(f"Updated: {updated_at}")
audio_urls = []
if miner_responses and isinstance(miner_responses, list) and len(miner_responses) > 0:
print(f"\n✅ Found {len(miner_responses)} response(s)")
for idx, response in enumerate(miner_responses, 1):
if isinstance(response, dict):
miner_uid = response.get('miner_uid', 'Unknown')
response_data = response.get('response', {}).get('response_data', {})
output_data = response_data.get('output_data', {})
audio_file = output_data.get('audio_file', {})
file_id = audio_file.get('file_id')
file_name = audio_file.get('file_name', '')
processing_time = response_data.get('processing_time', 0.0)
print(f"\n Response #{idx} (Miner UID: {miner_uid}):")
print(f" Processing Time: {processing_time:.2f}s")
if file_id:
print(f" File ID: {file_id}")
# Get public URL from database
file_info = get_file_public_url(file_id)
if file_info and file_info.get('public_url'):
public_url = file_info['public_url']
filename = file_info.get('filename', file_name) or f"{file_id}.wav"
file_size = file_info.get('file_size', 0)
print(f" ✅ Audio File:")
print(f" URL: {public_url}")
print(f" Filename: {filename}")
if file_size:
print(f" Size: {file_size:,} bytes ({file_size/1024/1024:.2f} MB)")
audio_urls.append({
'url': public_url,
'filename': filename,
'file_id': file_id,
'miner_uid': miner_uid,
'processing_time': processing_time,
'file_size': file_size
})
else:
# Fallback to proxy server URL
proxy_url = f"{BASE_URL}/api/v1/tts/audio/{file_id}"
print(f" ⚠️ Audio File (using proxy URL):")
print(f" URL: {proxy_url}")
print(f" Filename: {file_name or f'{file_id}.wav'}")
audio_urls.append({
'url': proxy_url,
'filename': file_name or f"{file_id}.wav",
'file_id': file_id,
'miner_uid': miner_uid,
'processing_time': processing_time,
'file_size': 0
})
else:
error = output_data.get('error', 'Unknown error')
print(f" ❌ No audio file (Error: {error})")
else:
print(f"\n⚠️ No responses yet")
audio_urls = []
results[task_id] = {
'model': model_name,
'status': status,
'model_id': model_id,
'response_count': len(miner_responses) if miner_responses else 0,
'audio_urls': audio_urls
}
engine.dispose()
return results
except Exception as e:
print(f"❌ Error querying tasks: {e}")
import traceback
traceback.print_exc()
return {}
def main():
# Task IDs from the created TTS tasks
task_ids = {
'6df450ae-7056-41e4-842b-af1abf24921a': 'tts_models/multilingual/multi-dataset/xtts_v2',
'b3571621-63c1-4d36-921b-fad7cab9f51a': 'tts_models/multilingual/multi-dataset/your_tts',
'b09cbfa7-f5ce-4fea-8f86-8189435ce895': 'tts_models/en/ljspeech/tacotron2-DDC',
'dac0f55b-44be-4d1a-b2d1-4a57433131d2': 'tts_models/en/vctk/vits'
}
print("\n" + "=" * 80)
print(" TTS TASK RESPONSE CHECKER")
print("=" * 80)
results = check_task_responses(task_ids)
# Summary
print("\n" + "=" * 80)
print(" SUMMARY - AUDIO FILE URLs")
print("=" * 80)
total_responses = 0
total_audio_files = 0
for task_id, info in results.items():
model = info['model']
status = info['status']
response_count = info.get('response_count', 0)
audio_urls = info.get('audio_urls', [])
total_responses += response_count
total_audio_files += len(audio_urls)
print(f"\n📋 {model}")
print(f" Task ID: {task_id}")
print(f" Status: {status}")
print(f" Responses: {response_count}")
print(f" Audio Files: {len(audio_urls)}")
if audio_urls:
for idx, audio_info in enumerate(audio_urls, 1):
print(f"\n Audio #{idx}:")
print(f" URL: {audio_info['url']}")
print(f" Filename: {audio_info['filename']}")
print(f" Miner UID: {audio_info['miner_uid']}")
if audio_info.get('file_size'):
print(f" Size: {audio_info['file_size']:,} bytes")
else:
print(f" ⚠️ No audio files available")
print(f"\n{'=' * 80}")
print(f"Total Responses: {total_responses}")
print(f"Total Audio Files: {total_audio_files}")
print(f"{'=' * 80}")
# Print all URLs in a simple list format
if total_audio_files > 0:
print(f"\n📥 All Audio URLs:")
print()
for task_id, info in results.items():
for audio_info in info.get('audio_urls', []):
print(audio_info['url'])
print(f" # {audio_info['filename']} (Miner {audio_info['miner_uid']})")
print()
if __name__ == "__main__":
main()