Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -341,8 +341,45 @@ async def usage_page():
|
|
| 341 |
"""Serve an HTML page showing usage statistics"""
|
| 342 |
# Retrieve usage data
|
| 343 |
usage_data = usage_tracker.get_usage_summary()
|
| 344 |
-
|
| 345 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
html_content = f"""
|
| 347 |
<!DOCTYPE html>
|
| 348 |
<html lang="en">
|
|
@@ -370,13 +407,7 @@ async def usage_page():
|
|
| 370 |
<th>First Used</th>
|
| 371 |
<th>Last Used</th>
|
| 372 |
</tr>
|
| 373 |
-
{
|
| 374 |
-
<tr>
|
| 375 |
-
<td>{model}</td>
|
| 376 |
-
<td>{model_data['total_requests']}</td>
|
| 377 |
-
<td>{model_data['first_used']}</td>
|
| 378 |
-
<td>{model_data['last_used']}</td>
|
| 379 |
-
</tr>""" for model, model_data in usage_data['models'].items()])}
|
| 380 |
</table>
|
| 381 |
|
| 382 |
<h3>API Endpoint Usage</h3>
|
|
@@ -387,13 +418,7 @@ async def usage_page():
|
|
| 387 |
<th>First Used</th>
|
| 388 |
<th>Last Used</th>
|
| 389 |
</tr>
|
| 390 |
-
{
|
| 391 |
-
<tr>
|
| 392 |
-
<td>{endpoint}</td>
|
| 393 |
-
<td>{endpoint_data['total_requests']}</td>
|
| 394 |
-
<td>{endpoint_data['first_used']}</td>
|
| 395 |
-
<td>{endpoint_data['last_used']}</td>
|
| 396 |
-
</tr>""" for endpoint, endpoint_data in usage_data['api_endpoints'].items()])}
|
| 397 |
</table>
|
| 398 |
|
| 399 |
<h3>Daily Usage (Last 7 Days)</h3>
|
|
@@ -403,24 +428,12 @@ async def usage_page():
|
|
| 403 |
<th>Entity</th>
|
| 404 |
<th>Requests</th>
|
| 405 |
</tr>
|
| 406 |
-
{
|
| 407 |
-
"".join([
|
| 408 |
-
f"""
|
| 409 |
-
<tr>
|
| 410 |
-
<td>{date}</td>
|
| 411 |
-
<td>{entity}</td>
|
| 412 |
-
<td>{requests}</td>
|
| 413 |
-
</tr>
|
| 414 |
-
""" for entity, requests in date_data.items()
|
| 415 |
-
]) for date, date_data in usage_data['recent_daily_usage'].items()
|
| 416 |
-
])}
|
| 417 |
</table>
|
| 418 |
</body>
|
| 419 |
</html>
|
| 420 |
"""
|
| 421 |
-
|
| 422 |
return HTMLResponse(content=html_content)
|
| 423 |
-
|
| 424 |
@app.on_event("startup")
|
| 425 |
async def startup_event():
|
| 426 |
global available_model_ids
|
|
|
|
| 341 |
"""Serve an HTML page showing usage statistics"""
|
| 342 |
# Retrieve usage data
|
| 343 |
usage_data = usage_tracker.get_usage_summary()
|
| 344 |
+
|
| 345 |
+
# Model Usage Table Rows
|
| 346 |
+
model_usage_rows = "\n".join([
|
| 347 |
+
f"""
|
| 348 |
+
<tr>
|
| 349 |
+
<td>{model}</td>
|
| 350 |
+
<td>{model_data['total_requests']}</td>
|
| 351 |
+
<td>{model_data['first_used']}</td>
|
| 352 |
+
<td>{model_data['last_used']}</td>
|
| 353 |
+
</tr>
|
| 354 |
+
""" for model, model_data in usage_data['models'].items()
|
| 355 |
+
])
|
| 356 |
+
|
| 357 |
+
# API Endpoint Usage Table Rows
|
| 358 |
+
api_usage_rows = "\n".join([
|
| 359 |
+
f"""
|
| 360 |
+
<tr>
|
| 361 |
+
<td>{endpoint}</td>
|
| 362 |
+
<td>{endpoint_data['total_requests']}</td>
|
| 363 |
+
<td>{endpoint_data['first_used']}</td>
|
| 364 |
+
<td>{endpoint_data['last_used']}</td>
|
| 365 |
+
</tr>
|
| 366 |
+
""" for endpoint, endpoint_data in usage_data['api_endpoints'].items()
|
| 367 |
+
])
|
| 368 |
+
|
| 369 |
+
# Daily Usage Table Rows
|
| 370 |
+
daily_usage_rows = "\n".join([
|
| 371 |
+
"\n".join([
|
| 372 |
+
f"""
|
| 373 |
+
<tr>
|
| 374 |
+
<td>{date}</td>
|
| 375 |
+
<td>{entity}</td>
|
| 376 |
+
<td>{requests}</td>
|
| 377 |
+
</tr>
|
| 378 |
+
""" for entity, requests in date_data.items()
|
| 379 |
+
]) for date, date_data in usage_data['recent_daily_usage'].items()
|
| 380 |
+
])
|
| 381 |
+
|
| 382 |
+
# Combine the full HTML content
|
| 383 |
html_content = f"""
|
| 384 |
<!DOCTYPE html>
|
| 385 |
<html lang="en">
|
|
|
|
| 407 |
<th>First Used</th>
|
| 408 |
<th>Last Used</th>
|
| 409 |
</tr>
|
| 410 |
+
{model_usage_rows}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
</table>
|
| 412 |
|
| 413 |
<h3>API Endpoint Usage</h3>
|
|
|
|
| 418 |
<th>First Used</th>
|
| 419 |
<th>Last Used</th>
|
| 420 |
</tr>
|
| 421 |
+
{api_usage_rows}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
</table>
|
| 423 |
|
| 424 |
<h3>Daily Usage (Last 7 Days)</h3>
|
|
|
|
| 428 |
<th>Entity</th>
|
| 429 |
<th>Requests</th>
|
| 430 |
</tr>
|
| 431 |
+
{daily_usage_rows}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
</table>
|
| 433 |
</body>
|
| 434 |
</html>
|
| 435 |
"""
|
|
|
|
| 436 |
return HTMLResponse(content=html_content)
|
|
|
|
| 437 |
@app.on_event("startup")
|
| 438 |
async def startup_event():
|
| 439 |
global available_model_ids
|