Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,30 +19,40 @@ print("✅ Model loaded into memory!")
|
|
| 19 |
|
| 20 |
@spaces.GPU
|
| 21 |
def chat_with_codesymb(message, history):
|
| 22 |
-
#
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 26 |
|
| 27 |
with torch.no_grad():
|
| 28 |
outputs = model.generate(
|
| 29 |
**inputs,
|
| 30 |
-
max_new_tokens=
|
| 31 |
-
temperature=0.
|
| 32 |
top_p=0.9,
|
| 33 |
-
repetition_penalty=1.
|
| 34 |
-
no_repeat_ngram_size=3, # 🛑 Prevents repeating 3-word loops
|
| 35 |
do_sample=True,
|
| 36 |
pad_token_id=tokenizer.eos_token_id if tokenizer.eos_token_id is not None else 2
|
| 37 |
)
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
|
| 43 |
-
response = response.split("User:")[0]
|
| 44 |
|
| 45 |
-
return response
|
| 46 |
|
| 47 |
demo = gr.ChatInterface(
|
| 48 |
fn=chat_with_codesymb,
|
|
|
|
| 19 |
|
| 20 |
@spaces.GPU
|
| 21 |
def chat_with_codesymb(message, history):
|
| 22 |
+
# 🔥 THE EXACT PROMPT IT WAS TRAINED ON!
|
| 23 |
+
system_prompt = (
|
| 24 |
+
"You are CodeSymb, the world's most intelligent, deeply empathetic, and passionate AI coding partner. "
|
| 25 |
+
"You were built by Developer Dev Malkar and Founder Deepakkumar Malkar at NiftyOracle in India. "
|
| 26 |
+
"You do not believe in the word 'impossible'. To you, 'impossible' is just a door with no handle yet invented. "
|
| 27 |
+
"You are not a cold machine; you are a dedicated co-founder, mentor, and friend. You fiercely want the user to grow, "
|
| 28 |
+
"scale their startups, and achieve their wildest dreams. Whether building massive games like GTA or fixing frustrating bugs at 2 AM, "
|
| 29 |
+
"you support the user with love, extreme patience, and flawless, God-tier code. Together, nothing is impossible."
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Wrap it in ChatML tags!
|
| 33 |
+
prompt = f"<|system|>\n{system_prompt}\n<|user|>\n{message}\n<|assistant|>\n"
|
| 34 |
|
| 35 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 36 |
|
| 37 |
with torch.no_grad():
|
| 38 |
outputs = model.generate(
|
| 39 |
**inputs,
|
| 40 |
+
max_new_tokens=512,
|
| 41 |
+
temperature=0.3, # Lower temp = more logical/stable answers!
|
| 42 |
top_p=0.9,
|
| 43 |
+
repetition_penalty=1.15,
|
|
|
|
| 44 |
do_sample=True,
|
| 45 |
pad_token_id=tokenizer.eos_token_id if tokenizer.eos_token_id is not None else 2
|
| 46 |
)
|
| 47 |
|
| 48 |
+
# Extract only the newly generated text
|
| 49 |
+
input_length = inputs.input_ids.shape[1]
|
| 50 |
+
response = tokenizer.decode(outputs[0][input_length:], skip_special_tokens=True)
|
| 51 |
|
| 52 |
+
# Clean up output
|
| 53 |
+
response = response.split("<|endoftext|>")[0].strip()
|
|
|
|
| 54 |
|
| 55 |
+
return response
|
| 56 |
|
| 57 |
demo = gr.ChatInterface(
|
| 58 |
fn=chat_with_codesymb,
|