Update app.py
Browse files
app.py
CHANGED
|
@@ -82,12 +82,11 @@ class DatabaseManager:
|
|
| 82 |
try:
|
| 83 |
# Generate secure API key
|
| 84 |
api_key = self._generate_api_key()
|
| 85 |
-
api_key_hash = hashlib.sha256(api_key.encode()).hexdigest()
|
| 86 |
|
| 87 |
data = {
|
| 88 |
"name": user_data.name.strip(),
|
| 89 |
"email": user_data.email.strip(),
|
| 90 |
-
"
|
| 91 |
"hf_user_id": hf_user_id,
|
| 92 |
"requests": 0,
|
| 93 |
"plan": user_data.plan,
|
|
@@ -121,11 +120,9 @@ class DatabaseManager:
|
|
| 121 |
async def validate_api_key(self, api_key: str) -> Optional[Dict]:
|
| 122 |
"""Validate API key and return user data"""
|
| 123 |
try:
|
| 124 |
-
api_key_hash = hashlib.sha256(api_key.encode()).hexdigest()
|
| 125 |
-
|
| 126 |
async with aiohttp.ClientSession() as session:
|
| 127 |
async with session.get(
|
| 128 |
-
f"{self.config.SUPABASE_URL}/rest/v1/users?
|
| 129 |
headers=self.headers
|
| 130 |
) as response:
|
| 131 |
if response.status == 200:
|
|
@@ -406,18 +403,42 @@ class GradioInterface:
|
|
| 406 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
|
| 407 |
|
| 408 |
:root {
|
| 409 |
-
--primary-gradient: linear-gradient(135deg, #
|
| 410 |
-
--secondary-gradient: linear-gradient(135deg, #
|
| 411 |
-
--success-gradient: linear-gradient(135deg, #
|
| 412 |
-
--
|
| 413 |
-
--
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 414 |
}
|
| 415 |
|
| 416 |
-
|
| 417 |
-
background:
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
}
|
| 422 |
|
| 423 |
.gradio-container {
|
|
@@ -430,15 +451,16 @@ class GradioInterface:
|
|
| 430 |
text-align: center;
|
| 431 |
margin-bottom: 3rem;
|
| 432 |
padding: 2rem;
|
| 433 |
-
background:
|
| 434 |
border-radius: 20px;
|
| 435 |
box-shadow: var(--card-shadow);
|
|
|
|
| 436 |
}
|
| 437 |
|
| 438 |
.main-title {
|
| 439 |
font-size: 3.5rem;
|
| 440 |
font-weight: 700;
|
| 441 |
-
background:
|
| 442 |
-webkit-background-clip: text;
|
| 443 |
-webkit-text-fill-color: transparent;
|
| 444 |
margin-bottom: 1rem;
|
|
@@ -446,17 +468,18 @@ class GradioInterface:
|
|
| 446 |
|
| 447 |
.main-subtitle {
|
| 448 |
font-size: 1.3rem;
|
| 449 |
-
color: #
|
| 450 |
font-weight: 400;
|
| 451 |
}
|
| 452 |
|
| 453 |
-
.feature-card {
|
| 454 |
-
background:
|
| 455 |
-
border-radius: 15px;
|
| 456 |
-
padding: 2rem;
|
| 457 |
-
box-shadow: var(--card-shadow);
|
| 458 |
-
transition: all 0.3s ease;
|
| 459 |
-
border: 1px solid rgba(255,255,255,0.
|
|
|
|
| 460 |
}
|
| 461 |
|
| 462 |
.feature-card:hover {
|
|
@@ -470,6 +493,9 @@ class GradioInterface:
|
|
| 470 |
padding: 0.8rem 2rem !important;
|
| 471 |
transition: all 0.3s ease !important;
|
| 472 |
border: none !important;
|
|
|
|
|
|
|
|
|
|
| 473 |
}
|
| 474 |
|
| 475 |
.gr-button-primary {
|
|
@@ -484,15 +510,16 @@ class GradioInterface:
|
|
| 484 |
|
| 485 |
.gr-button:hover {
|
| 486 |
transform: translateY(-2px) !important;
|
| 487 |
-
box-shadow: 0 8px 25px rgba(0,0,0,0.
|
| 488 |
}
|
| 489 |
|
| 490 |
.stats-card {
|
| 491 |
-
background:
|
| 492 |
color: white;
|
| 493 |
border-radius: 15px;
|
| 494 |
padding: 2rem;
|
| 495 |
margin: 1rem 0;
|
|
|
|
| 496 |
}
|
| 497 |
|
| 498 |
.metric {
|
|
@@ -503,6 +530,7 @@ class GradioInterface:
|
|
| 503 |
.metric-value {
|
| 504 |
font-size: 2.5rem;
|
| 505 |
font-weight: 700;
|
|
|
|
| 506 |
}
|
| 507 |
|
| 508 |
.metric-label {
|
|
@@ -513,19 +541,97 @@ class GradioInterface:
|
|
| 513 |
}
|
| 514 |
|
| 515 |
.alert-success {
|
| 516 |
-
background:
|
| 517 |
color: white;
|
| 518 |
padding: 1rem;
|
| 519 |
border-radius: 10px;
|
| 520 |
margin: 1rem 0;
|
|
|
|
| 521 |
}
|
| 522 |
|
| 523 |
.alert-error {
|
| 524 |
-
background:
|
| 525 |
color: white;
|
| 526 |
padding: 1rem;
|
| 527 |
border-radius: 10px;
|
| 528 |
margin: 1rem 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 529 |
}
|
| 530 |
"""
|
| 531 |
|
|
@@ -651,11 +757,25 @@ class GradioInterface:
|
|
| 651 |
with gr.Tab("π Analytics", elem_classes=["feature-card"]):
|
| 652 |
gr.Markdown("### π Platform Analytics")
|
| 653 |
|
| 654 |
-
#
|
| 655 |
gr.HTML("""
|
| 656 |
-
<div
|
| 657 |
<h3>π Advanced Analytics Coming Soon</h3>
|
| 658 |
<p>Real-time usage metrics, performance insights, and detailed reporting.</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 659 |
</div>
|
| 660 |
""")
|
| 661 |
|
|
|
|
| 82 |
try:
|
| 83 |
# Generate secure API key
|
| 84 |
api_key = self._generate_api_key()
|
|
|
|
| 85 |
|
| 86 |
data = {
|
| 87 |
"name": user_data.name.strip(),
|
| 88 |
"email": user_data.email.strip(),
|
| 89 |
+
"api_key": api_key, # Store plain API key (consider hashing in production)
|
| 90 |
"hf_user_id": hf_user_id,
|
| 91 |
"requests": 0,
|
| 92 |
"plan": user_data.plan,
|
|
|
|
| 120 |
async def validate_api_key(self, api_key: str) -> Optional[Dict]:
|
| 121 |
"""Validate API key and return user data"""
|
| 122 |
try:
|
|
|
|
|
|
|
| 123 |
async with aiohttp.ClientSession() as session:
|
| 124 |
async with session.get(
|
| 125 |
+
f"{self.config.SUPABASE_URL}/rest/v1/users?api_key=eq.{api_key}",
|
| 126 |
headers=self.headers
|
| 127 |
) as response:
|
| 128 |
if response.status == 200:
|
|
|
|
| 403 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
|
| 404 |
|
| 405 |
:root {
|
| 406 |
+
--primary-gradient: linear-gradient(135deg, #566981 0%, #3A415A 100%);
|
| 407 |
+
--secondary-gradient: linear-gradient(135deg, #3A415A 0%, #34344E 100%);
|
| 408 |
+
--success-gradient: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
|
| 409 |
+
--error-gradient: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
|
| 410 |
+
--card-shadow: 0 10px 30px rgba(0,0,0,0.3);
|
| 411 |
+
--hover-shadow: 0 15px 40px rgba(0,0,0,0.4);
|
| 412 |
+
--bg-color: #566981;
|
| 413 |
+
--text-color: #ffffff;
|
| 414 |
+
--card-bg: #3A415A;
|
| 415 |
+
--accent-color: #34344E;
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
* {
|
| 419 |
+
scrollbar-width: thin;
|
| 420 |
+
scrollbar-color: var(--card-bg) var(--bg-color);
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
*::-webkit-scrollbar {
|
| 424 |
+
width: 8px;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
*::-webkit-scrollbar-track {
|
| 428 |
+
background: var(--bg-color);
|
| 429 |
}
|
| 430 |
|
| 431 |
+
*::-webkit-scrollbar-thumb {
|
| 432 |
+
background-color: var(--card-bg);
|
| 433 |
+
border-radius: 4px;
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
body, .gradio-container {
|
| 437 |
+
background: var(--bg-color) !important;
|
| 438 |
+
color: var(--text-color) !important;
|
| 439 |
+
font-family: 'Inter', sans-serif !important;
|
| 440 |
+
margin: 0 !important;
|
| 441 |
+
padding: 0 !important;
|
| 442 |
}
|
| 443 |
|
| 444 |
.gradio-container {
|
|
|
|
| 451 |
text-align: center;
|
| 452 |
margin-bottom: 3rem;
|
| 453 |
padding: 2rem;
|
| 454 |
+
background: var(--card-bg) !important;
|
| 455 |
border-radius: 20px;
|
| 456 |
box-shadow: var(--card-shadow);
|
| 457 |
+
border: 1px solid rgba(255,255,255,0.1);
|
| 458 |
}
|
| 459 |
|
| 460 |
.main-title {
|
| 461 |
font-size: 3.5rem;
|
| 462 |
font-weight: 700;
|
| 463 |
+
background: linear-gradient(135deg, #ffffff 0%, #e2e8f0 100%);
|
| 464 |
-webkit-background-clip: text;
|
| 465 |
-webkit-text-fill-color: transparent;
|
| 466 |
margin-bottom: 1rem;
|
|
|
|
| 468 |
|
| 469 |
.main-subtitle {
|
| 470 |
font-size: 1.3rem;
|
| 471 |
+
color: #cbd5e1;
|
| 472 |
font-weight: 400;
|
| 473 |
}
|
| 474 |
|
| 475 |
+
.feature-card, .gr-form, .gr-box {
|
| 476 |
+
background: var(--card-bg) !important;
|
| 477 |
+
border-radius: 15px !important;
|
| 478 |
+
padding: 2rem !important;
|
| 479 |
+
box-shadow: var(--card-shadow) !important;
|
| 480 |
+
transition: all 0.3s ease !important;
|
| 481 |
+
border: 1px solid rgba(255,255,255,0.1) !important;
|
| 482 |
+
color: var(--text-color) !important;
|
| 483 |
}
|
| 484 |
|
| 485 |
.feature-card:hover {
|
|
|
|
| 493 |
padding: 0.8rem 2rem !important;
|
| 494 |
transition: all 0.3s ease !important;
|
| 495 |
border: none !important;
|
| 496 |
+
text-transform: uppercase !important;
|
| 497 |
+
letter-spacing: 1px !important;
|
| 498 |
+
font-size: 0.9rem !important;
|
| 499 |
}
|
| 500 |
|
| 501 |
.gr-button-primary {
|
|
|
|
| 510 |
|
| 511 |
.gr-button:hover {
|
| 512 |
transform: translateY(-2px) !important;
|
| 513 |
+
box-shadow: 0 8px 25px rgba(0,0,0,0.4) !important;
|
| 514 |
}
|
| 515 |
|
| 516 |
.stats-card {
|
| 517 |
+
background: var(--primary-gradient) !important;
|
| 518 |
color: white;
|
| 519 |
border-radius: 15px;
|
| 520 |
padding: 2rem;
|
| 521 |
margin: 1rem 0;
|
| 522 |
+
box-shadow: var(--card-shadow);
|
| 523 |
}
|
| 524 |
|
| 525 |
.metric {
|
|
|
|
| 530 |
.metric-value {
|
| 531 |
font-size: 2.5rem;
|
| 532 |
font-weight: 700;
|
| 533 |
+
color: #ffffff;
|
| 534 |
}
|
| 535 |
|
| 536 |
.metric-label {
|
|
|
|
| 541 |
}
|
| 542 |
|
| 543 |
.alert-success {
|
| 544 |
+
background: var(--success-gradient) !important;
|
| 545 |
color: white;
|
| 546 |
padding: 1rem;
|
| 547 |
border-radius: 10px;
|
| 548 |
margin: 1rem 0;
|
| 549 |
+
box-shadow: var(--card-shadow);
|
| 550 |
}
|
| 551 |
|
| 552 |
.alert-error {
|
| 553 |
+
background: var(--error-gradient) !important;
|
| 554 |
color: white;
|
| 555 |
padding: 1rem;
|
| 556 |
border-radius: 10px;
|
| 557 |
margin: 1rem 0;
|
| 558 |
+
box-shadow: var(--card-shadow);
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
.gr-textbox, .gr-dropdown, .gr-slider {
|
| 562 |
+
background: var(--accent-color) !important;
|
| 563 |
+
border: 1px solid rgba(255,255,255,0.1) !important;
|
| 564 |
+
border-radius: 8px !important;
|
| 565 |
+
color: var(--text-color) !important;
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
.gr-textbox:focus, .gr-dropdown:focus {
|
| 569 |
+
border-color: rgba(255,255,255,0.3) !important;
|
| 570 |
+
box-shadow: 0 0 0 3px rgba(255,255,255,0.1) !important;
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
.gr-tab-nav {
|
| 574 |
+
background: var(--card-bg) !important;
|
| 575 |
+
border-radius: 12px !important;
|
| 576 |
+
padding: 0.5rem !important;
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
.gr-tab-nav button {
|
| 580 |
+
background: transparent !important;
|
| 581 |
+
color: var(--text-color) !important;
|
| 582 |
+
border: none !important;
|
| 583 |
+
border-radius: 8px !important;
|
| 584 |
+
padding: 0.8rem 1.5rem !important;
|
| 585 |
+
margin: 0 0.25rem !important;
|
| 586 |
+
transition: all 0.3s ease !important;
|
| 587 |
+
}
|
| 588 |
+
|
| 589 |
+
.gr-tab-nav button.selected, .gr-tab-nav button:hover {
|
| 590 |
+
background: var(--accent-color) !important;
|
| 591 |
+
color: white !important;
|
| 592 |
+
}
|
| 593 |
+
|
| 594 |
+
.gr-accordion {
|
| 595 |
+
background: var(--accent-color) !important;
|
| 596 |
+
border-radius: 10px !important;
|
| 597 |
+
border: 1px solid rgba(255,255,255,0.1) !important;
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
.gr-accordion summary {
|
| 601 |
+
color: var(--text-color) !important;
|
| 602 |
+
font-weight: 600 !important;
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
label {
|
| 606 |
+
color: var(--text-color) !important;
|
| 607 |
+
font-weight: 600 !important;
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
.gr-markdown {
|
| 611 |
+
color: var(--text-color) !important;
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
.gr-markdown h1, .gr-markdown h2, .gr-markdown h3 {
|
| 615 |
+
color: #ffffff !important;
|
| 616 |
+
}
|
| 617 |
+
|
| 618 |
+
.dark-coming-soon {
|
| 619 |
+
background: var(--card-bg) !important;
|
| 620 |
+
border-radius: 20px !important;
|
| 621 |
+
padding: 4rem 2rem !important;
|
| 622 |
+
text-align: center !important;
|
| 623 |
+
border: 2px dashed rgba(255,255,255,0.2) !important;
|
| 624 |
+
}
|
| 625 |
+
|
| 626 |
+
.dark-coming-soon h3 {
|
| 627 |
+
color: #ffffff !important;
|
| 628 |
+
font-size: 2rem !important;
|
| 629 |
+
margin-bottom: 1rem !important;
|
| 630 |
+
}
|
| 631 |
+
|
| 632 |
+
.dark-coming-soon p {
|
| 633 |
+
color: #cbd5e1 !important;
|
| 634 |
+
font-size: 1.1rem !important;
|
| 635 |
}
|
| 636 |
"""
|
| 637 |
|
|
|
|
| 757 |
with gr.Tab("π Analytics", elem_classes=["feature-card"]):
|
| 758 |
gr.Markdown("### π Platform Analytics")
|
| 759 |
|
| 760 |
+
# Enhanced dark theme analytics placeholder
|
| 761 |
gr.HTML("""
|
| 762 |
+
<div class="dark-coming-soon">
|
| 763 |
<h3>π Advanced Analytics Coming Soon</h3>
|
| 764 |
<p>Real-time usage metrics, performance insights, and detailed reporting.</p>
|
| 765 |
+
<div style="margin-top: 2rem; display: flex; justify-content: center; gap: 2rem;">
|
| 766 |
+
<div style="text-align: center;">
|
| 767 |
+
<div style="font-size: 3rem;">β‘</div>
|
| 768 |
+
<div>Real-time Metrics</div>
|
| 769 |
+
</div>
|
| 770 |
+
<div style="text-align: center;">
|
| 771 |
+
<div style="font-size: 3rem;">π</div>
|
| 772 |
+
<div>Usage Analytics</div>
|
| 773 |
+
</div>
|
| 774 |
+
<div style="text-align: center;">
|
| 775 |
+
<div style="font-size: 3rem;">π―</div>
|
| 776 |
+
<div>Performance Insights</div>
|
| 777 |
+
</div>
|
| 778 |
+
</div>
|
| 779 |
</div>
|
| 780 |
""")
|
| 781 |
|