Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,15 +4,15 @@ from peft import PeftModel
|
|
| 4 |
import torch
|
| 5 |
|
| 6 |
# --- Load tokenizer and model for CPU ---
|
| 7 |
-
tokenizer = AutoTokenizer.from_pretrained("unsloth/
|
| 8 |
|
| 9 |
base_model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
-
"unsloth/
|
| 11 |
dtype=torch.float32,
|
| 12 |
device_map={"": "cpu"},
|
| 13 |
)
|
| 14 |
|
| 15 |
-
model = PeftModel.from_pretrained(base_model, "khazarai/
|
| 16 |
|
| 17 |
# --- Chatbot logic ---
|
| 18 |
def generate_response(user_input, chat_history):
|
|
@@ -25,17 +25,17 @@ def generate_response(user_input, chat_history):
|
|
| 25 |
chat_history,
|
| 26 |
tokenize=False,
|
| 27 |
add_generation_prompt=True,
|
| 28 |
-
|
| 29 |
)
|
| 30 |
|
| 31 |
inputs = tokenizer(text, return_tensors="pt").to("cpu")
|
| 32 |
|
| 33 |
output_tokens = model.generate(
|
| 34 |
**inputs,
|
| 35 |
-
max_new_tokens=
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
do_sample=True
|
| 40 |
)
|
| 41 |
|
|
@@ -57,62 +57,57 @@ def generate_response(user_input, chat_history):
|
|
| 57 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="slate")) as demo:
|
| 58 |
gr.HTML("""
|
| 59 |
<style>
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
</style>
|
| 106 |
-
|
| 107 |
-
<div class="chat-header">
|
| 108 |
-
<h1> π§ Azerbaijani Chatbot</h1>
|
| 109 |
-
</div>
|
| 110 |
""")
|
| 111 |
|
| 112 |
with gr.Row():
|
| 113 |
with gr.Column(scale=6):
|
| 114 |
chatbot = gr.Chatbot(
|
| 115 |
-
label="π¬ Chat-
|
| 116 |
height=600,
|
| 117 |
bubble_full_width=True,
|
| 118 |
show_copy_button=True,
|
|
|
|
| 4 |
import torch
|
| 5 |
|
| 6 |
# --- Load tokenizer and model for CPU ---
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("unsloth/Qwen3-1.7B")
|
| 8 |
|
| 9 |
base_model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
+
"unsloth/Qwen3-1.7B",
|
| 11 |
dtype=torch.float32,
|
| 12 |
device_map={"": "cpu"},
|
| 13 |
)
|
| 14 |
|
| 15 |
+
model = PeftModel.from_pretrained(base_model, "khazarai/Qwen-ALP-AZ").to("cpu")
|
| 16 |
|
| 17 |
# --- Chatbot logic ---
|
| 18 |
def generate_response(user_input, chat_history):
|
|
|
|
| 25 |
chat_history,
|
| 26 |
tokenize=False,
|
| 27 |
add_generation_prompt=True,
|
| 28 |
+
enable_thinking=False,
|
| 29 |
)
|
| 30 |
|
| 31 |
inputs = tokenizer(text, return_tensors="pt").to("cpu")
|
| 32 |
|
| 33 |
output_tokens = model.generate(
|
| 34 |
**inputs,
|
| 35 |
+
max_new_tokens=1024,
|
| 36 |
+
temperature=0.7,
|
| 37 |
+
top_p=0.8,
|
| 38 |
+
top_k=20,
|
| 39 |
do_sample=True
|
| 40 |
)
|
| 41 |
|
|
|
|
| 57 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="slate")) as demo:
|
| 58 |
gr.HTML("""
|
| 59 |
<style>
|
| 60 |
+
body {background: radial-gradient(circle at top, #E9D5FF 0%, #F5F3FF 100%);}
|
| 61 |
+
.gradio-container {font-family: 'Inter', sans-serif;}
|
| 62 |
+
.chat-header {
|
| 63 |
+
text-align: center;
|
| 64 |
+
background: linear-gradient(90deg, #C084FC, #A855F7);
|
| 65 |
+
color: white;
|
| 66 |
+
padding: 20px 10px;
|
| 67 |
+
border-radius: 18px;
|
| 68 |
+
margin-bottom: 20px;
|
| 69 |
+
box-shadow: 0px 4px 20px rgba(168,85,247,0.3);
|
| 70 |
+
}
|
| 71 |
+
.chat-header h1 {
|
| 72 |
+
font-size: 2.4em;
|
| 73 |
+
font-weight: 800;
|
| 74 |
+
margin-bottom: 0px;
|
| 75 |
+
}
|
| 76 |
+
.chat-header p {
|
| 77 |
+
margin-top: 5px;
|
| 78 |
+
color: #F3E8FF;
|
| 79 |
+
font-weight: 500;
|
| 80 |
+
}
|
| 81 |
+
.send-btn {
|
| 82 |
+
background: linear-gradient(90deg, #C084FC, #A855F7);
|
| 83 |
+
color: white !important;
|
| 84 |
+
transition: all 0.25s ease-in-out;
|
| 85 |
+
}
|
| 86 |
+
.send-btn:hover {
|
| 87 |
+
transform: scale(1.05);
|
| 88 |
+
box-shadow: 0 0 12px rgba(192,132,252,0.5);
|
| 89 |
+
}
|
| 90 |
+
.textbox {
|
| 91 |
+
backdrop-filter: blur(12px);
|
| 92 |
+
background-color: rgba(255,255,255,0.6);
|
| 93 |
+
border-radius: 16px !important;
|
| 94 |
+
}
|
| 95 |
+
.footer {
|
| 96 |
+
text-align: center;
|
| 97 |
+
margin-top: 25px;
|
| 98 |
+
color: #6B7280;
|
| 99 |
+
font-size: 0.9em;
|
| 100 |
+
}
|
| 101 |
+
</style>
|
| 102 |
+
<div class="chat-header">
|
| 103 |
+
<h1> π§ Azerbaijani Chatbot </h1>
|
| 104 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
""")
|
| 106 |
|
| 107 |
with gr.Row():
|
| 108 |
with gr.Column(scale=6):
|
| 109 |
chatbot = gr.Chatbot(
|
| 110 |
+
label="π¬ Chat-az",
|
| 111 |
height=600,
|
| 112 |
bubble_full_width=True,
|
| 113 |
show_copy_button=True,
|