Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,13 +2,16 @@ import os
|
|
| 2 |
import re
|
| 3 |
import json
|
| 4 |
import pickle
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
from urllib.parse import quote
|
| 6 |
|
| 7 |
import numpy as np
|
| 8 |
import gradio as gr
|
| 9 |
from rank_bm25 import BM25Okapi
|
| 10 |
from sentence_transformers import SentenceTransformer
|
| 11 |
-
from openai import OpenAI
|
| 12 |
|
| 13 |
# =====================================================
|
| 14 |
# CONFIG
|
|
@@ -280,16 +283,21 @@ def oai_json(prompt: str) -> dict:
|
|
| 280 |
# =====================================================
|
| 281 |
# LOGO
|
| 282 |
# =====================================================
|
| 283 |
-
def
|
| 284 |
-
if os.path.exists(LOGO_FILE):
|
| 285 |
-
return
|
| 286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
|
| 288 |
|
| 289 |
def render_logo():
|
| 290 |
-
|
| 291 |
-
if
|
| 292 |
-
return f'<img src="{
|
| 293 |
return '<div class="bc-logo-fallback">BRAIN<br>CHAT</div>'
|
| 294 |
|
| 295 |
|
|
@@ -447,7 +455,8 @@ CSS = """
|
|
| 447 |
--accent-soft: #f5ef9a;
|
| 448 |
--user-bubble: #ffffff;
|
| 449 |
--bot-bubble: #f5efad;
|
| 450 |
-
--text-dark: #
|
|
|
|
| 451 |
--text-light: #ffffff;
|
| 452 |
--shadow: rgba(30,20,50,0.18);
|
| 453 |
}
|
|
@@ -464,7 +473,7 @@ footer{display:none !important;}
|
|
| 464 |
}
|
| 465 |
|
| 466 |
.bc-settings{
|
| 467 |
-
background: linear-gradient(180deg, #
|
| 468 |
border-radius: 20px;
|
| 469 |
padding: 14px;
|
| 470 |
box-shadow: 0 10px 24px var(--shadow);
|
|
@@ -522,7 +531,7 @@ footer{display:none !important;}
|
|
| 522 |
text-align:center;
|
| 523 |
font-size: 13px;
|
| 524 |
font-weight: 900;
|
| 525 |
-
color: var(--text-dark);
|
| 526 |
background: rgba(255,255,255,0.40);
|
| 527 |
line-height: 1.05;
|
| 528 |
}
|
|
@@ -568,24 +577,29 @@ footer{display:none !important;}
|
|
| 568 |
max-width: 80%;
|
| 569 |
padding: 15px 18px;
|
| 570 |
border-radius: 22px;
|
| 571 |
-
line-height: 1.
|
| 572 |
font-size: 15px;
|
| 573 |
box-shadow: 0 10px 18px rgba(0,0,0,0.10);
|
| 574 |
word-wrap: break-word;
|
|
|
|
| 575 |
}
|
| 576 |
|
| 577 |
.bc-user-bubble{
|
| 578 |
background: var(--user-bubble);
|
| 579 |
-
color: var(--text-dark);
|
| 580 |
border-bottom-left-radius: 8px;
|
| 581 |
}
|
| 582 |
|
| 583 |
.bc-bot-bubble{
|
| 584 |
background: var(--bot-bubble);
|
| 585 |
-
color: var(--text-dark);
|
| 586 |
border-bottom-right-radius: 8px;
|
| 587 |
}
|
| 588 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 589 |
.bc-empty{
|
| 590 |
display:flex;
|
| 591 |
justify-content:center;
|
|
@@ -620,7 +634,7 @@ footer{display:none !important;}
|
|
| 620 |
justify-content:center;
|
| 621 |
font-size: 30px;
|
| 622 |
font-weight: 900;
|
| 623 |
-
color: var(--text-dark);
|
| 624 |
user-select:none;
|
| 625 |
}
|
| 626 |
|
|
@@ -629,7 +643,7 @@ footer{display:none !important;}
|
|
| 629 |
border: none !important;
|
| 630 |
box-shadow: none !important;
|
| 631 |
border-radius: 999px !important;
|
| 632 |
-
color: var(--text-dark) !important;
|
| 633 |
padding: 11px 14px !important;
|
| 634 |
min-height: 42px !important;
|
| 635 |
}
|
|
@@ -643,7 +657,7 @@ footer{display:none !important;}
|
|
| 643 |
border-radius: 999px !important;
|
| 644 |
border: none !important;
|
| 645 |
background: rgba(255,255,255,0.34) !important;
|
| 646 |
-
color: var(--text-dark) !important;
|
| 647 |
font-size: 20px !important;
|
| 648 |
font-weight: 900 !important;
|
| 649 |
box-shadow: none !important;
|
|
|
|
| 2 |
import re
|
| 3 |
import json
|
| 4 |
import pickle
|
| 5 |
+
import base64
|
| 6 |
+
import mimetypes
|
| 7 |
+
|
| 8 |
+
from openai import OpenAI
|
| 9 |
from urllib.parse import quote
|
| 10 |
|
| 11 |
import numpy as np
|
| 12 |
import gradio as gr
|
| 13 |
from rank_bm25 import BM25Okapi
|
| 14 |
from sentence_transformers import SentenceTransformer
|
|
|
|
| 15 |
|
| 16 |
# =====================================================
|
| 17 |
# CONFIG
|
|
|
|
| 283 |
# =====================================================
|
| 284 |
# LOGO
|
| 285 |
# =====================================================
|
| 286 |
+
def get_logo_data_uri():
|
| 287 |
+
if not os.path.exists(LOGO_FILE):
|
| 288 |
+
return None
|
| 289 |
+
mime_type, _ = mimetypes.guess_type(LOGO_FILE)
|
| 290 |
+
if not mime_type:
|
| 291 |
+
mime_type = "image/png"
|
| 292 |
+
with open(LOGO_FILE, "rb") as f:
|
| 293 |
+
encoded = base64.b64encode(f.read()).decode("utf-8")
|
| 294 |
+
return f"data:{mime_type};base64,{encoded}"
|
| 295 |
|
| 296 |
|
| 297 |
def render_logo():
|
| 298 |
+
data_uri = get_logo_data_uri()
|
| 299 |
+
if data_uri:
|
| 300 |
+
return f'<img src="{data_uri}" alt="BrainChat logo" class="bc-logo-img">'
|
| 301 |
return '<div class="bc-logo-fallback">BRAIN<br>CHAT</div>'
|
| 302 |
|
| 303 |
|
|
|
|
| 455 |
--accent-soft: #f5ef9a;
|
| 456 |
--user-bubble: #ffffff;
|
| 457 |
--bot-bubble: #f5efad;
|
| 458 |
+
--text-dark: #241336;
|
| 459 |
+
--text-dark-strong: #170c25;
|
| 460 |
--text-light: #ffffff;
|
| 461 |
--shadow: rgba(30,20,50,0.18);
|
| 462 |
}
|
|
|
|
| 473 |
}
|
| 474 |
|
| 475 |
.bc-settings{
|
| 476 |
+
background: linear-gradient(180deg, #4a4c59 0%, #434552 100%);
|
| 477 |
border-radius: 20px;
|
| 478 |
padding: 14px;
|
| 479 |
box-shadow: 0 10px 24px var(--shadow);
|
|
|
|
| 531 |
text-align:center;
|
| 532 |
font-size: 13px;
|
| 533 |
font-weight: 900;
|
| 534 |
+
color: var(--text-dark-strong);
|
| 535 |
background: rgba(255,255,255,0.40);
|
| 536 |
line-height: 1.05;
|
| 537 |
}
|
|
|
|
| 577 |
max-width: 80%;
|
| 578 |
padding: 15px 18px;
|
| 579 |
border-radius: 22px;
|
| 580 |
+
line-height: 1.6;
|
| 581 |
font-size: 15px;
|
| 582 |
box-shadow: 0 10px 18px rgba(0,0,0,0.10);
|
| 583 |
word-wrap: break-word;
|
| 584 |
+
font-weight: 500;
|
| 585 |
}
|
| 586 |
|
| 587 |
.bc-user-bubble{
|
| 588 |
background: var(--user-bubble);
|
| 589 |
+
color: var(--text-dark-strong) !important;
|
| 590 |
border-bottom-left-radius: 8px;
|
| 591 |
}
|
| 592 |
|
| 593 |
.bc-bot-bubble{
|
| 594 |
background: var(--bot-bubble);
|
| 595 |
+
color: var(--text-dark-strong) !important;
|
| 596 |
border-bottom-right-radius: 8px;
|
| 597 |
}
|
| 598 |
|
| 599 |
+
.bc-bubble strong{
|
| 600 |
+
color: var(--text-dark-strong) !important;
|
| 601 |
+
}
|
| 602 |
+
|
| 603 |
.bc-empty{
|
| 604 |
display:flex;
|
| 605 |
justify-content:center;
|
|
|
|
| 634 |
justify-content:center;
|
| 635 |
font-size: 30px;
|
| 636 |
font-weight: 900;
|
| 637 |
+
color: var(--text-dark-strong);
|
| 638 |
user-select:none;
|
| 639 |
}
|
| 640 |
|
|
|
|
| 643 |
border: none !important;
|
| 644 |
box-shadow: none !important;
|
| 645 |
border-radius: 999px !important;
|
| 646 |
+
color: var(--text-dark-strong) !important;
|
| 647 |
padding: 11px 14px !important;
|
| 648 |
min-height: 42px !important;
|
| 649 |
}
|
|
|
|
| 657 |
border-radius: 999px !important;
|
| 658 |
border: none !important;
|
| 659 |
background: rgba(255,255,255,0.34) !important;
|
| 660 |
+
color: var(--text-dark-strong) !important;
|
| 661 |
font-size: 20px !important;
|
| 662 |
font-weight: 900 !important;
|
| 663 |
box-shadow: none !important;
|