Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
|
|
| 1 |
"""
|
| 2 |
Treevik-2 2.5B Instruct
|
| 3 |
-
|
|
|
|
|
|
|
| 4 |
"""
|
| 5 |
|
| 6 |
import gc
|
|
@@ -16,7 +19,7 @@ import torch.nn.functional as F
|
|
| 16 |
from huggingface_hub import hf_hub_download
|
| 17 |
|
| 18 |
# ============================================================================
|
| 19 |
-
# DEVICE
|
| 20 |
# ============================================================================
|
| 21 |
|
| 22 |
torch.set_grad_enabled(False)
|
|
@@ -589,18 +592,10 @@ USER_END = enc.encode_single_token("<|user_end|>")
|
|
| 589 |
ASST_START = enc.encode_single_token("<|assistant_start|>")
|
| 590 |
ASST_END = enc.encode_single_token("<|assistant_end|>")
|
| 591 |
|
| 592 |
-
|
| 593 |
-
sum(p.numel() for p in model.parameters())
|
| 594 |
-
/ 1e9
|
| 595 |
-
)
|
| 596 |
-
|
| 597 |
-
print(
|
| 598 |
-
f"✅ Loaded on {device} "
|
| 599 |
-
f"({param_count:.1f}B params)"
|
| 600 |
-
)
|
| 601 |
|
| 602 |
# ============================================================================
|
| 603 |
-
# CHAT
|
| 604 |
# ============================================================================
|
| 605 |
|
| 606 |
@spaces.GPU
|
|
@@ -612,16 +607,6 @@ def respond(message, history):
|
|
| 612 |
|
| 613 |
ids = [BOS]
|
| 614 |
|
| 615 |
-
for user_msg, bot_msg in history:
|
| 616 |
-
|
| 617 |
-
ids += [USER_START]
|
| 618 |
-
ids += enc.encode_ordinary(user_msg)
|
| 619 |
-
ids += [USER_END]
|
| 620 |
-
|
| 621 |
-
ids += [ASST_START]
|
| 622 |
-
ids += enc.encode_ordinary(bot_msg)
|
| 623 |
-
ids += [ASST_END]
|
| 624 |
-
|
| 625 |
ids += [USER_START]
|
| 626 |
ids += enc.encode_ordinary(message)
|
| 627 |
ids += [USER_END]
|
|
@@ -630,8 +615,6 @@ def respond(message, history):
|
|
| 630 |
|
| 631 |
generated = []
|
| 632 |
|
| 633 |
-
partial = ""
|
| 634 |
-
|
| 635 |
for token in model.generate(
|
| 636 |
ids,
|
| 637 |
max_tokens=512,
|
|
@@ -649,7 +632,7 @@ def respond(message, history):
|
|
| 649 |
yield partial
|
| 650 |
|
| 651 |
# ============================================================================
|
| 652 |
-
#
|
| 653 |
# ============================================================================
|
| 654 |
|
| 655 |
css = """
|
|
@@ -674,24 +657,20 @@ footer {
|
|
| 674 |
|
| 675 |
.message.bot {
|
| 676 |
background: #1e293b !important;
|
| 677 |
-
color: #
|
| 678 |
border-radius: 18px !important;
|
| 679 |
}
|
| 680 |
|
| 681 |
textarea {
|
| 682 |
-
border-radius: 18px !important;
|
| 683 |
background: #111827 !important;
|
| 684 |
color: white !important;
|
|
|
|
| 685 |
border: 1px solid #334155 !important;
|
| 686 |
}
|
| 687 |
|
| 688 |
button {
|
| 689 |
border-radius: 14px !important;
|
| 690 |
}
|
| 691 |
-
|
| 692 |
-
.chatbot {
|
| 693 |
-
border: none !important;
|
| 694 |
-
}
|
| 695 |
"""
|
| 696 |
|
| 697 |
theme = gr.themes.Soft(
|
|
@@ -702,7 +681,6 @@ theme = gr.themes.Soft(
|
|
| 702 |
|
| 703 |
demo = gr.ChatInterface(
|
| 704 |
fn=respond,
|
| 705 |
-
type="tuples",
|
| 706 |
title="Treevik-2 2.5B",
|
| 707 |
description="""
|
| 708 |
<div style='text-align:center'>
|
|
@@ -712,29 +690,21 @@ demo = gr.ChatInterface(
|
|
| 712 |
""",
|
| 713 |
chatbot=gr.Chatbot(
|
| 714 |
height=650,
|
| 715 |
-
bubble_full_width=False,
|
| 716 |
show_copy_button=True,
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
"https://ui-avatars.com/api/?name=T&background=2563eb&color=fff",
|
| 720 |
-
),
|
| 721 |
),
|
| 722 |
textbox=gr.Textbox(
|
| 723 |
placeholder="Message Treevik...",
|
| 724 |
container=False,
|
| 725 |
-
scale=8,
|
| 726 |
),
|
| 727 |
submit_btn="Send",
|
| 728 |
-
retry_btn="Retry",
|
| 729 |
-
undo_btn="Undo",
|
| 730 |
clear_btn="Clear",
|
| 731 |
theme=theme,
|
| 732 |
css=css,
|
| 733 |
)
|
| 734 |
|
| 735 |
-
demo.queue(
|
| 736 |
-
max_size=32
|
| 737 |
-
)
|
| 738 |
|
| 739 |
demo.launch(
|
| 740 |
server_name="0.0.0.0",
|
|
|
|
| 1 |
+
|
| 2 |
"""
|
| 3 |
Treevik-2 2.5B Instruct
|
| 4 |
+
HF Spaces Ready
|
| 5 |
+
GPU + CPU Auto Detect
|
| 6 |
+
Modern ChatGPT Style UI
|
| 7 |
"""
|
| 8 |
|
| 9 |
import gc
|
|
|
|
| 19 |
from huggingface_hub import hf_hub_download
|
| 20 |
|
| 21 |
# ============================================================================
|
| 22 |
+
# DEVICE
|
| 23 |
# ============================================================================
|
| 24 |
|
| 25 |
torch.set_grad_enabled(False)
|
|
|
|
| 592 |
ASST_START = enc.encode_single_token("<|assistant_start|>")
|
| 593 |
ASST_END = enc.encode_single_token("<|assistant_end|>")
|
| 594 |
|
| 595 |
+
print("✅ Model Ready")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 596 |
|
| 597 |
# ============================================================================
|
| 598 |
+
# CHAT
|
| 599 |
# ============================================================================
|
| 600 |
|
| 601 |
@spaces.GPU
|
|
|
|
| 607 |
|
| 608 |
ids = [BOS]
|
| 609 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 610 |
ids += [USER_START]
|
| 611 |
ids += enc.encode_ordinary(message)
|
| 612 |
ids += [USER_END]
|
|
|
|
| 615 |
|
| 616 |
generated = []
|
| 617 |
|
|
|
|
|
|
|
| 618 |
for token in model.generate(
|
| 619 |
ids,
|
| 620 |
max_tokens=512,
|
|
|
|
| 632 |
yield partial
|
| 633 |
|
| 634 |
# ============================================================================
|
| 635 |
+
# UI
|
| 636 |
# ============================================================================
|
| 637 |
|
| 638 |
css = """
|
|
|
|
| 657 |
|
| 658 |
.message.bot {
|
| 659 |
background: #1e293b !important;
|
| 660 |
+
color: #f8fafc !important;
|
| 661 |
border-radius: 18px !important;
|
| 662 |
}
|
| 663 |
|
| 664 |
textarea {
|
|
|
|
| 665 |
background: #111827 !important;
|
| 666 |
color: white !important;
|
| 667 |
+
border-radius: 16px !important;
|
| 668 |
border: 1px solid #334155 !important;
|
| 669 |
}
|
| 670 |
|
| 671 |
button {
|
| 672 |
border-radius: 14px !important;
|
| 673 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 674 |
"""
|
| 675 |
|
| 676 |
theme = gr.themes.Soft(
|
|
|
|
| 681 |
|
| 682 |
demo = gr.ChatInterface(
|
| 683 |
fn=respond,
|
|
|
|
| 684 |
title="Treevik-2 2.5B",
|
| 685 |
description="""
|
| 686 |
<div style='text-align:center'>
|
|
|
|
| 690 |
""",
|
| 691 |
chatbot=gr.Chatbot(
|
| 692 |
height=650,
|
|
|
|
| 693 |
show_copy_button=True,
|
| 694 |
+
bubble_full_width=False,
|
| 695 |
+
type="messages",
|
|
|
|
|
|
|
| 696 |
),
|
| 697 |
textbox=gr.Textbox(
|
| 698 |
placeholder="Message Treevik...",
|
| 699 |
container=False,
|
|
|
|
| 700 |
),
|
| 701 |
submit_btn="Send",
|
|
|
|
|
|
|
| 702 |
clear_btn="Clear",
|
| 703 |
theme=theme,
|
| 704 |
css=css,
|
| 705 |
)
|
| 706 |
|
| 707 |
+
demo.queue()
|
|
|
|
|
|
|
| 708 |
|
| 709 |
demo.launch(
|
| 710 |
server_name="0.0.0.0",
|