Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -341,7 +341,6 @@ 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 |
# Model Usage Table Rows
|
346 |
model_usage_rows = "\n".join([
|
347 |
f"""
|
@@ -353,7 +352,6 @@ async def usage_page():
|
|
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"""
|
@@ -365,7 +363,6 @@ async def usage_page():
|
|
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([
|
@@ -378,58 +375,154 @@ async def usage_page():
|
|
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">
|
386 |
<head>
|
387 |
<meta charset="UTF-8">
|
388 |
-
<title>
|
|
|
389 |
<style>
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
395 |
</style>
|
396 |
</head>
|
397 |
<body>
|
398 |
-
<
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
<
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
</
|
431 |
-
|
432 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
433 |
</body>
|
434 |
</html>
|
435 |
"""
|
|
|
341 |
"""Serve an HTML page showing usage statistics"""
|
342 |
# Retrieve usage data
|
343 |
usage_data = usage_tracker.get_usage_summary()
|
|
|
344 |
# Model Usage Table Rows
|
345 |
model_usage_rows = "\n".join([
|
346 |
f"""
|
|
|
352 |
</tr>
|
353 |
""" for model, model_data in usage_data['models'].items()
|
354 |
])
|
|
|
355 |
# API Endpoint Usage Table Rows
|
356 |
api_usage_rows = "\n".join([
|
357 |
f"""
|
|
|
363 |
</tr>
|
364 |
""" for endpoint, endpoint_data in usage_data['api_endpoints'].items()
|
365 |
])
|
|
|
366 |
# Daily Usage Table Rows
|
367 |
daily_usage_rows = "\n".join([
|
368 |
"\n".join([
|
|
|
375 |
""" for entity, requests in date_data.items()
|
376 |
]) for date, date_data in usage_data['recent_daily_usage'].items()
|
377 |
])
|
378 |
+
|
|
|
379 |
html_content = f"""
|
380 |
<!DOCTYPE html>
|
381 |
<html lang="en">
|
382 |
<head>
|
383 |
<meta charset="UTF-8">
|
384 |
+
<title>Lokai AI - Usage Statistics</title>
|
385 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&display=swap" rel="stylesheet">
|
386 |
<style>
|
387 |
+
:root {{
|
388 |
+
--bg-dark: #0f1011;
|
389 |
+
--bg-darker: #070708;
|
390 |
+
--text-primary: #e6e6e6;
|
391 |
+
--text-secondary: #8c8c8c;
|
392 |
+
--border-color: #2c2c2c;
|
393 |
+
--accent-color: #3a6ee0;
|
394 |
+
--accent-hover: #4a7ef0;
|
395 |
+
}}
|
396 |
+
body {{
|
397 |
+
font-family: 'Inter', sans-serif;
|
398 |
+
background-color: var(--bg-dark);
|
399 |
+
color: var(--text-primary);
|
400 |
+
max-width: 1200px;
|
401 |
+
margin: 0 auto;
|
402 |
+
padding: 40px 20px;
|
403 |
+
line-height: 1.6;
|
404 |
+
}}
|
405 |
+
.logo {{
|
406 |
+
display: flex;
|
407 |
+
align-items: center;
|
408 |
+
justify-content: center;
|
409 |
+
margin-bottom: 30px;
|
410 |
+
}}
|
411 |
+
.logo h1 {{
|
412 |
+
font-weight: 600;
|
413 |
+
font-size: 2.5em;
|
414 |
+
color: var(--text-primary);
|
415 |
+
margin-left: 15px;
|
416 |
+
}}
|
417 |
+
.logo img {{
|
418 |
+
width: 60px;
|
419 |
+
height: 60px;
|
420 |
+
border-radius: 10px;
|
421 |
+
}}
|
422 |
+
.container {{
|
423 |
+
background-color: var(--bg-darker);
|
424 |
+
border-radius: 12px;
|
425 |
+
padding: 30px;
|
426 |
+
box-shadow: 0 15px 40px rgba(0,0,0,0.3);
|
427 |
+
border: 1px solid var(--border-color);
|
428 |
+
}}
|
429 |
+
h2, h3 {{
|
430 |
+
color: var(--text-primary);
|
431 |
+
border-bottom: 2px solid var(--border-color);
|
432 |
+
padding-bottom: 10px;
|
433 |
+
font-weight: 500;
|
434 |
+
}}
|
435 |
+
.total-requests {{
|
436 |
+
background-color: var(--accent-color);
|
437 |
+
color: white;
|
438 |
+
text-align: center;
|
439 |
+
padding: 15px;
|
440 |
+
border-radius: 8px;
|
441 |
+
margin-bottom: 30px;
|
442 |
+
font-weight: 600;
|
443 |
+
letter-spacing: -0.5px;
|
444 |
+
}}
|
445 |
+
table {{
|
446 |
+
width: 100%;
|
447 |
+
border-collapse: separate;
|
448 |
+
border-spacing: 0;
|
449 |
+
margin-bottom: 30px;
|
450 |
+
background-color: var(--bg-dark);
|
451 |
+
border-radius: 8px;
|
452 |
+
overflow: hidden;
|
453 |
+
}}
|
454 |
+
th, td {{
|
455 |
+
border: 1px solid var(--border-color);
|
456 |
+
padding: 12px;
|
457 |
+
text-align: left;
|
458 |
+
transition: background-color 0.3s ease;
|
459 |
+
}}
|
460 |
+
th {{
|
461 |
+
background-color: #1e1e1e;
|
462 |
+
color: var(--text-primary);
|
463 |
+
font-weight: 600;
|
464 |
+
text-transform: uppercase;
|
465 |
+
font-size: 0.9em;
|
466 |
+
}}
|
467 |
+
tr:nth-child(even) {{
|
468 |
+
background-color: rgba(255,255,255,0.05);
|
469 |
+
}}
|
470 |
+
tr:hover {{
|
471 |
+
background-color: rgba(62,100,255,0.1);
|
472 |
+
}}
|
473 |
+
@media (max-width: 768px) {{
|
474 |
+
.container {{
|
475 |
+
padding: 15px;
|
476 |
+
}}
|
477 |
+
table {{
|
478 |
+
font-size: 0.9em;
|
479 |
+
}}
|
480 |
+
}}
|
481 |
</style>
|
482 |
</head>
|
483 |
<body>
|
484 |
+
<div class="container">
|
485 |
+
<div class="logo">
|
486 |
+
<img src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNMTAwIDM1TDUwIDkwaDEwMHoiIGZpbGw9IiMzYTZlZTAiLz48Y2lyY2xlIGN4PSIxMDAiIGN5PSIxNDAiIHI9IjMwIiBmaWxsPSIjM2E2ZWUwIi8+PC9zdmc+" alt="Lokai AI Logo">
|
487 |
+
<h1>Lokai AI</h1>
|
488 |
+
</div>
|
489 |
+
|
490 |
+
<div class="total-requests">
|
491 |
+
Total API Requests: {usage_data['total_requests']}
|
492 |
+
</div>
|
493 |
+
|
494 |
+
<h2>Model Usage</h2>
|
495 |
+
<table>
|
496 |
+
<tr>
|
497 |
+
<th>Model</th>
|
498 |
+
<th>Total Requests</th>
|
499 |
+
<th>First Used</th>
|
500 |
+
<th>Last Used</th>
|
501 |
+
</tr>
|
502 |
+
{model_usage_rows}
|
503 |
+
</table>
|
504 |
+
|
505 |
+
<h2>API Endpoint Usage</h2>
|
506 |
+
<table>
|
507 |
+
<tr>
|
508 |
+
<th>Endpoint</th>
|
509 |
+
<th>Total Requests</th>
|
510 |
+
<th>First Used</th>
|
511 |
+
<th>Last Used</th>
|
512 |
+
</tr>
|
513 |
+
{api_usage_rows}
|
514 |
+
</table>
|
515 |
+
|
516 |
+
<h2>Daily Usage (Last 7 Days)</h2>
|
517 |
+
<table>
|
518 |
+
<tr>
|
519 |
+
<th>Date</th>
|
520 |
+
<th>Entity</th>
|
521 |
+
<th>Requests</th>
|
522 |
+
</tr>
|
523 |
+
{daily_usage_rows}
|
524 |
+
</table>
|
525 |
+
</div>
|
526 |
</body>
|
527 |
</html>
|
528 |
"""
|