Rustamshry commited on
Commit
ab6d52e
Β·
verified Β·
1 Parent(s): c5465d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -59
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/Qwen2.5-0.5B-Instruct")
8
 
9
  base_model = AutoModelForCausalLM.from_pretrained(
10
- "unsloth/Qwen2.5-0.5B-Instruct",
11
  dtype=torch.float32,
12
  device_map={"": "cpu"},
13
  )
14
 
15
- model = PeftModel.from_pretrained(base_model, "khazarai/SympQwen-0.5B").to("cpu")
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
- #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=512,
36
- #temperature=0.7,
37
- #top_p=0.8,
38
- #top_k=20,
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
- body {
61
- background: radial-gradient(circle at top, #DBEAFE 0%, #EFF6FF 100%);
62
- }
63
- .gradio-container {
64
- font-family: 'Inter', sans-serif;
65
- }
66
- .chat-header {
67
- text-align: center;
68
- background: linear-gradient(90deg, #60A5FA, #3B82F6);
69
- color: white;
70
- padding: 20px 10px;
71
- border-radius: 18px;
72
- margin-bottom: 20px;
73
- box-shadow: 0px 4px 20px rgba(59,130,246,0.3);
74
- }
75
- .chat-header h1 {
76
- font-size: 2.4em;
77
- font-weight: 800;
78
- margin-bottom: 0px;
79
- }
80
- .chat-header p {
81
- margin-top: 5px;
82
- color: #DBEAFE;
83
- font-weight: 500;
84
- }
85
- .send-btn {
86
- background: linear-gradient(90deg, #60A5FA, #3B82F6);
87
- color: white !important;
88
- transition: all 0.25s ease-in-out;
89
- }
90
- .send-btn:hover {
91
- transform: scale(1.05);
92
- box-shadow: 0 0 12px rgba(96,165,250,0.5);
93
- }
94
- .textbox {
95
- backdrop-filter: blur(12px);
96
- background-color: rgba(255,255,255,0.6);
97
- border-radius: 16px !important;
98
- }
99
- .footer {
100
- text-align: center;
101
- margin-top: 25px;
102
- color: #6B7280;
103
- font-size: 0.9em;
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-Az",
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,