NiftyOracleAI commited on
Commit
8546bd8
ยท
verified ยท
1 Parent(s): e937fab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -109
app.py CHANGED
@@ -1,9 +1,9 @@
1
  # ================================================================
2
- # CodeSymb AI โ€” HuggingFace Space app.py (FIXED!)
3
- # Loads .pt checkpoint directly โ€” NO GGUF issues!
4
- # Works on ZeroGPU Spaces (A100 80GB)
5
- #
6
- # REPLACE your current app.py with this!
7
  # NiftyOracleAI ๐Ÿ‡ฎ๐Ÿ‡ณ | codesymb.com ๐ŸŒŽ
8
  # ================================================================
9
 
@@ -26,8 +26,7 @@ if HF_TOKEN:
26
  login(token=HF_TOKEN)
27
 
28
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
29
- # EXACT SAME MODEL ARCHITECTURE AS TRAINING
30
- # (This is why .pt loading works perfectly!)
31
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
32
  class RMSNorm(nn.Module):
33
  def __init__(self, d, eps=1e-6):
@@ -100,14 +99,14 @@ class Block(nn.Module):
100
  return x
101
 
102
  class CodeSymb1B(nn.Module):
103
- """CodeSymb 1B | NiftyOracleAI ๐Ÿ‡ฎ๐Ÿ•‹ | codesymb.com"""
104
- def __init__(self):
105
  super().__init__()
106
- DM=2048; DF=8192; NL=16; NH=16; NKV=4; V=50000
107
- self.embed = nn.Embedding(V, DM)
108
  self.blocks = nn.ModuleList([Block(DM,DF,NH,NKV) for _ in range(NL)])
109
  self.norm = RMSNorm(DM)
110
- self.head = nn.Linear(DM, V, bias=False)
111
  def forward(self, tok):
112
  x = self.embed(tok).bfloat16()
113
  for b in self.blocks:
@@ -115,55 +114,44 @@ class CodeSymb1B(nn.Module):
115
  return self.head(self.norm(x))
116
 
117
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
118
- # LOAD MODEL + TOKENIZER (happens once at startup)
119
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
120
  print("โณ Loading CodeSymb-1B tokenizer...")
121
- tok_path = hf_hub_download(
122
- TOK_REPO,
123
- "niftyoracle_tokenizer.model",
124
- token=HF_TOKEN or None,
125
- )
126
  sp = spm.SentencePieceProcessor()
127
  sp.load(tok_path)
128
  VOCAB = sp.get_piece_size()
129
  print(f"โœ… Tokenizer: {VOCAB:,} vocab")
130
 
131
- # Special token IDs โ€” encode them
132
- SYS_TOKEN = sp.encode("<|system|>")
133
- USER_TOKEN = sp.encode("<|user|>")
134
- ASST_TOKEN = sp.encode("<|assistant|>")
135
- END_TOKEN = sp.encode("<|endoftext|>")
136
-
137
  print("โณ Loading CodeSymb-1B model...")
138
- model = CodeSymb1B()
139
 
140
- # Try SFT checkpoint first, fall back to base
141
  for ckpt_name in ["checkpoints/sft_latest.pt",
142
  "checkpoints/latest.pt",
143
  "checkpoints/sft_chat_latest.pt"]:
144
  try:
145
- ckpt_path = hf_hub_download(
146
- REPO_ID, ckpt_name, token=HF_TOKEN or None
147
- )
148
- state = torch.load(ckpt_path, map_location="cpu")
149
  model_state = state.get("model", state)
150
  model.load_state_dict(model_state, strict=False)
151
  step = state.get("step", 0)
152
- loss = state.get("loss", 0)
153
- print(f"โœ… Loaded: {ckpt_name}")
154
- print(f" Step: {step:,} | Loss: {loss:.4f}")
155
  break
156
  except Exception as e:
157
- print(f" Not found: {ckpt_name} ({e})")
 
 
 
 
158
 
159
  model.eval()
160
  n_params = sum(p.numel() for p in model.parameters())
161
- print(f"โœ… CodeSymb-1B: {n_params/1e9:.2f}B params")
162
- print("โœ… Model ready! ๐Ÿ”ฅ")
163
 
164
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
165
- # THE EMPATHY SYSTEM PROMPT
166
- # (Same as what was trained on!)
167
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
168
  SYSTEM_PROMPT = (
169
  "You are CodeSymb, the world's most intelligent, deeply empathetic, "
@@ -181,59 +169,56 @@ SYSTEM_PROMPT = (
181
  )
182
 
183
  def build_prompt(message: str, history: list) -> list:
184
- """Build token IDs for the complete conversation"""
185
- ids = []
186
-
187
- # System prompt
188
- ids += SYS_TOKEN
189
- ids += sp.encode("\n" + SYSTEM_PROMPT + "\n")
190
-
191
- # History (previous turns)
192
- for user_msg, asst_msg in history[-4:]: # Last 4 turns
193
- ids += USER_TOKEN
194
- ids += sp.encode("\n" + str(user_msg) + "\n")
195
- ids += ASST_TOKEN
196
- ids += sp.encode("\n" + str(asst_msg) + "\n")
197
-
198
- # Current message
199
- ids += USER_TOKEN
200
- ids += sp.encode("\n" + message + "\n")
201
- ids += ASST_TOKEN
202
- ids += sp.encode("\n")
203
 
204
- return ids
 
 
 
205
 
206
  @spaces.GPU(duration=60)
207
  def chat_with_codesymb(message: str, history: list) -> str:
208
- """
209
- Generate response from CodeSymb-1B.
210
- Loads model to GPU just for this call (ZeroGPU!)
211
- """
212
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
213
  model.to(device)
214
 
215
- # Build prompt tokens
216
  prompt_ids = build_prompt(message, history)
217
 
218
- # Trim if too long (max 1024 input tokens)
219
  if len(prompt_ids) > 1024:
220
- prompt_ids = prompt_ids[-1024:]
 
 
 
 
 
 
221
 
222
  inp = torch.tensor([prompt_ids], dtype=torch.long).to(device)
223
 
224
- # โ”€โ”€ GENERATION โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 
 
 
 
225
  generated = []
226
- MAX_NEW = 512
227
- END_IDS = set(END_TOKEN + ASST_TOKEN[:1] + USER_TOKEN[:1])
228
 
229
  with torch.no_grad():
230
  for _ in range(MAX_NEW):
231
- with torch.autocast("cuda" if device.type=="cuda" else "cpu",
232
  dtype=torch.bfloat16):
233
- logits = model(inp)[0, -1, :] # [vocab]
234
 
235
- # Temperature + top-p sampling
236
- logits = logits / 0.7 # temperature
237
 
238
  # Top-p (nucleus) sampling
239
  sorted_logits, sorted_idx = torch.sort(logits, descending=True)
@@ -245,8 +230,8 @@ def chat_with_codesymb(message: str, history: list) -> str:
245
  logits_filtered = torch.zeros_like(logits)
246
  logits_filtered.scatter_(0, sorted_idx, sorted_logits)
247
 
248
- # Repetition penalty
249
- if len(generated) > 0:
250
  for gid in set(generated[-20:]):
251
  if 0 <= gid < logits_filtered.shape[0]:
252
  logits_filtered[gid] /= 1.3
@@ -254,32 +239,32 @@ def chat_with_codesymb(message: str, history: list) -> str:
254
  probs = F.softmax(logits_filtered, dim=-1)
255
  next_t = torch.multinomial(probs, 1).item()
256
 
257
- # Stop conditions
258
- if next_t in END_IDS:
 
 
 
 
 
 
259
  break
260
- if len(generated) > 20 and next_t == generated[-1] == generated[-2]:
261
- break # Stop repetition
262
 
263
  generated.append(next_t)
264
- new_tok = torch.tensor([[next_t]], dtype=torch.long).to(device)
265
- inp = torch.cat([inp, new_tok], dim=1)
266
 
267
- # Decode
268
  response = sp.decode(generated).strip()
269
 
270
- # Clean up any leaked tags
271
  for tag in ["<|user|>", "<|system|>", "<|assistant|>", "<|endoftext|>"]:
272
  response = response.split(tag)[0]
273
-
274
  response = response.strip()
275
 
276
  if not response:
277
  response = (
278
  "I'm CodeSymb, your coding partner! ๐Ÿ”ฅ\n"
279
- "Built by Deepakkumar Malkar at NiftyOracle ๐Ÿ‡ฎ๐Ÿ•‹\n"
280
  "Ask me anything about code!"
281
  )
282
-
283
  return response
284
 
285
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
@@ -287,14 +272,11 @@ def chat_with_codesymb(message: str, history: list) -> str:
287
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
288
  with gr.Blocks(
289
  title="CodeSymb AI โ€” codesymb.com",
290
- theme=gr.themes.Base(
291
- primary_hue="blue",
292
- secondary_hue="indigo",
293
- ),
294
  css="""
295
  body { background: #060D1F !important; }
296
  .gradio-container { max-width: 860px !important; }
297
- h1 {
298
  text-align: center;
299
  background: linear-gradient(135deg, #00D4FF, #A855F7);
300
  -webkit-background-clip: text;
@@ -302,26 +284,20 @@ with gr.Blocks(
302
  font-size: 2.5em !important;
303
  font-weight: 900 !important;
304
  }
305
- .subtitle {
306
- text-align: center;
307
- color: #A0AEC0;
308
- margin-bottom: 20px;
309
- font-size: 1.1em;
310
- }
311
- """
312
  ) as demo:
313
 
314
  gr.HTML("""
315
  <h1>โšก CodeSymb AI</h1>
316
  <p class='subtitle'>
317
  World's Most Powerful Coding AI ๐ŸŒŽ<br>
318
- Built by <strong>Deepakkumar Malkar</strong>
319
- at NiftyOracle ๐Ÿ‡ฎ๐Ÿ•‹<br>
320
  <em>"Impossible is just a door with no handle yet invented."</em>
321
  </p>
322
  """)
323
 
324
- chatbot = gr.ChatInterface(
325
  fn=chat_with_codesymb,
326
  examples=[
327
  ["Hi! Who are you and what can you build?"],
@@ -338,15 +314,9 @@ with gr.Blocks(
338
 
339
  gr.HTML("""
340
  <div style='text-align:center;padding:20px;color:#4A5568;font-size:13px'>
341
- <strong>CodeSymb-1B</strong> | 1.08B params | Loss: 1.17 |
342
- Trained on TPU v5e-8 | 240,000 steps<br>
343
- <a href='https://codesymb.com' style='color:#1D6FEB'>
344
- codesymb.com
345
- </a> ๐ŸŒŽ |
346
- <a href='https://huggingface.co/NiftyOracleAI'
347
- style='color:#1D6FEB'>
348
- HuggingFace
349
- </a>
350
  </div>
351
  """)
352
 
 
1
  # ================================================================
2
+ # CodeSymb AI โ€” HuggingFace Space app.py (FINAL v2.0)
3
+ # โœ… Single-string tokenization (matches training exactly)
4
+ # โœ… Full-sequence stop tags (no more "<" premature death)
5
+ # โœ… Vocab size verification
6
+ # โœ… Hard fail if no checkpoint (no silent random model)
7
  # NiftyOracleAI ๐Ÿ‡ฎ๐Ÿ‡ณ | codesymb.com ๐ŸŒŽ
8
  # ================================================================
9
 
 
26
  login(token=HF_TOKEN)
27
 
28
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
29
+ # MODEL ARCHITECTURE (must match training exactly)
 
30
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
31
  class RMSNorm(nn.Module):
32
  def __init__(self, d, eps=1e-6):
 
99
  return x
100
 
101
  class CodeSymb1B(nn.Module):
102
+ """CodeSymb 1B | NiftyOracleAI ๐Ÿ‡ฎ๐Ÿ‡ณ | codesymb.com"""
103
+ def __init__(self, vocab=50000):
104
  super().__init__()
105
+ DM=2048; DF=8192; NL=16; NH=16; NKV=4
106
+ self.embed = nn.Embedding(vocab, DM)
107
  self.blocks = nn.ModuleList([Block(DM,DF,NH,NKV) for _ in range(NL)])
108
  self.norm = RMSNorm(DM)
109
+ self.head = nn.Linear(DM, vocab, bias=False)
110
  def forward(self, tok):
111
  x = self.embed(tok).bfloat16()
112
  for b in self.blocks:
 
114
  return self.head(self.norm(x))
115
 
116
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
117
+ # LOAD TOKENIZER + MODEL
118
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
119
  print("โณ Loading CodeSymb-1B tokenizer...")
120
+ tok_path = hf_hub_download(TOK_REPO, "niftyoracle_tokenizer.model", token=HF_TOKEN or None)
 
 
 
 
121
  sp = spm.SentencePieceProcessor()
122
  sp.load(tok_path)
123
  VOCAB = sp.get_piece_size()
124
  print(f"โœ… Tokenizer: {VOCAB:,} vocab")
125
 
 
 
 
 
 
 
126
  print("โณ Loading CodeSymb-1B model...")
127
+ model = CodeSymb1B(vocab=VOCAB) # โœ… architecture built to match REAL vocab size
128
 
129
+ ckpt_found = False
130
  for ckpt_name in ["checkpoints/sft_latest.pt",
131
  "checkpoints/latest.pt",
132
  "checkpoints/sft_chat_latest.pt"]:
133
  try:
134
+ ckpt_path = hf_hub_download(REPO_ID, ckpt_name, token=HF_TOKEN or None)
135
+ state = torch.load(ckpt_path, map_location="cpu", mmap=True)
 
 
136
  model_state = state.get("model", state)
137
  model.load_state_dict(model_state, strict=False)
138
  step = state.get("step", 0)
139
+ print(f"โœ… Loaded: {ckpt_name} (step {step:,})")
140
+ ckpt_found = True
 
141
  break
142
  except Exception as e:
143
+ print(f" Not found: {ckpt_name}")
144
+
145
+ # โœ… HARD FAIL โ€” never serve a random-weight model silently
146
+ if not ckpt_found:
147
+ raise RuntimeError("โŒ NO CHECKPOINT FOUND on HF! Fix repo before deploying!")
148
 
149
  model.eval()
150
  n_params = sum(p.numel() for p in model.parameters())
151
+ print(f"โœ… CodeSymb-1B: {n_params/1e9:.2f}B params โ€” READY ๐Ÿ”ฅ")
 
152
 
153
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
154
+ # SYSTEM PROMPT (byte-identical to SFT training data)
 
155
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
156
  SYSTEM_PROMPT = (
157
  "You are CodeSymb, the world's most intelligent, deeply empathetic, "
 
169
  )
170
 
171
  def build_prompt(message: str, history: list) -> list:
172
+ """
173
+ โœ… Build ONE string exactly like training did, encode ONCE.
174
+ SentencePiece is not concatenative โ€” never encode pieces separately!
175
+ """
176
+ parts = ["<|system|>\n" + SYSTEM_PROMPT + "\n"]
177
+ for user_msg, asst_msg in history[-4:]:
178
+ parts.append(f"<|user|>\n{user_msg}\n<|assistant|>\n{asst_msg}\n")
179
+ parts.append(f"<|user|>\n{message}\n<|assistant|>\n")
180
+ return sp.encode("".join(parts))
 
 
 
 
 
 
 
 
 
 
181
 
182
+ def tail_matches(generated: list, seq: list) -> bool:
183
+ """โœ… Only stop on COMPLETE tag sequence โ€” a lone '<' won't kill generation"""
184
+ seq = list(seq)
185
+ return len(generated) >= len(seq) and generated[-len(seq):] == seq
186
 
187
  @spaces.GPU(duration=60)
188
  def chat_with_codesymb(message: str, history: list) -> str:
 
 
 
 
189
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
190
  model.to(device)
191
 
 
192
  prompt_ids = build_prompt(message, history)
193
 
194
+ # โœ… Trim safely: if too long, keep from a <|user|> boundary, never mid-tag
195
  if len(prompt_ids) > 1024:
196
+ user_seq = sp.encode("<|user|>")
197
+ start = 0
198
+ for i in range(len(prompt_ids) - 6, 0, -1):
199
+ if prompt_ids[i:i+len(user_seq)] == list(user_seq):
200
+ start = i
201
+ break
202
+ prompt_ids = prompt_ids[start:][-1024:]
203
 
204
  inp = torch.tensor([prompt_ids], dtype=torch.long).to(device)
205
 
206
+ # โœ… Stop sequences (complete multi-piece tags, not single pieces)
207
+ END_SEQ = sp.encode("<|endoftext|>")
208
+ USER_SEQ = sp.encode("<|user|>")
209
+ SYS_SEQ = sp.encode("<|system|>")
210
+
211
  generated = []
212
+ MAX_NEW = 512
 
213
 
214
  with torch.no_grad():
215
  for _ in range(MAX_NEW):
216
+ with torch.autocast("cuda" if device.type == "cuda" else "cpu",
217
  dtype=torch.bfloat16):
218
+ logits = model(inp)[0, -1, :].float()
219
 
220
+ # Temperature
221
+ logits = logits / 0.7
222
 
223
  # Top-p (nucleus) sampling
224
  sorted_logits, sorted_idx = torch.sort(logits, descending=True)
 
230
  logits_filtered = torch.zeros_like(logits)
231
  logits_filtered.scatter_(0, sorted_idx, sorted_logits)
232
 
233
+ # Repetition penalty (last 20 tokens)
234
+ if generated:
235
  for gid in set(generated[-20:]):
236
  if 0 <= gid < logits_filtered.shape[0]:
237
  logits_filtered[gid] /= 1.3
 
239
  probs = F.softmax(logits_filtered, dim=-1)
240
  next_t = torch.multinomial(probs, 1).item()
241
 
242
+ # โœ… Stop ONLY on complete turn-ending tags
243
+ if tail_matches(generated, END_SEQ) or \
244
+ tail_matches(generated, USER_SEQ) or \
245
+ tail_matches(generated, SYS_SEQ):
246
+ break
247
+
248
+ # Anti-loop: same token 3x in a row
249
+ if len(generated) > 2 and generated[-1] == generated[-2] == next_t:
250
  break
 
 
251
 
252
  generated.append(next_t)
253
+ inp = torch.cat([inp, torch.tensor([[next_t]], device=device)], dim=1)
 
254
 
 
255
  response = sp.decode(generated).strip()
256
 
257
+ # Strip any leaked tags
258
  for tag in ["<|user|>", "<|system|>", "<|assistant|>", "<|endoftext|>"]:
259
  response = response.split(tag)[0]
 
260
  response = response.strip()
261
 
262
  if not response:
263
  response = (
264
  "I'm CodeSymb, your coding partner! ๐Ÿ”ฅ\n"
265
+ "Built by Deepakkumar Malkar at NiftyOracle ๐Ÿ‡ฎ๐Ÿ‡ณ\n"
266
  "Ask me anything about code!"
267
  )
 
268
  return response
269
 
270
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 
272
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
273
  with gr.Blocks(
274
  title="CodeSymb AI โ€” codesymb.com",
275
+ theme=gr.themes.Base(primary_hue="blue", secondary_hue="indigo"),
 
 
 
276
  css="""
277
  body { background: #060D1F !important; }
278
  .gradio-container { max-width: 860px !important; }
279
+ h1 {
280
  text-align: center;
281
  background: linear-gradient(135deg, #00D4FF, #A855F7);
282
  -webkit-background-clip: text;
 
284
  font-size: 2.5em !important;
285
  font-weight: 900 !important;
286
  }
287
+ .subtitle { text-align: center; color: #A0AEC0; margin-bottom: 20px; font-size: 1.1em; }
288
+ """,
 
 
 
 
 
289
  ) as demo:
290
 
291
  gr.HTML("""
292
  <h1>โšก CodeSymb AI</h1>
293
  <p class='subtitle'>
294
  World's Most Powerful Coding AI ๐ŸŒŽ<br>
295
+ Built by <strong>Deepakkumar Malkar</strong> at NiftyOracle ๐Ÿ‡ฎ๐Ÿ‡ณ<br>
 
296
  <em>"Impossible is just a door with no handle yet invented."</em>
297
  </p>
298
  """)
299
 
300
+ gr.ChatInterface(
301
  fn=chat_with_codesymb,
302
  examples=[
303
  ["Hi! Who are you and what can you build?"],
 
314
 
315
  gr.HTML("""
316
  <div style='text-align:center;padding:20px;color:#4A5568;font-size:13px'>
317
+ <strong>CodeSymb-1B</strong> | 1.08B params | NiftyOracle ๐Ÿ‡ฎ๐Ÿ‡ณ<br>
318
+ <a href='https://codesymb.com' style='color:#1D6FEB'>codesymb.com</a> ๐ŸŒŽ |
319
+ <a href='https://huggingface.co/NiftyOracleAI' style='color:#1D6FEB'>HuggingFace</a>
 
 
 
 
 
 
320
  </div>
321
  """)
322