Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import torch
|
|
| 3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
import spaces
|
| 5 |
|
| 6 |
-
# Your exact repository and GGUF path
|
| 7 |
REPO_ID = "NiftyOracleAI/NiftyOracle-Coder-30B"
|
| 8 |
GGUF_FILE = "gguf/codesymb_1b_chat_FP16.gguf"
|
| 9 |
|
|
@@ -18,36 +17,37 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 18 |
)
|
| 19 |
print("✅ Model loaded into memory!")
|
| 20 |
|
| 21 |
-
# ZeroGPU decorator: dynamically attaches the GPU when a prompt is sent
|
| 22 |
@spaces.GPU
|
| 23 |
def chat_with_codesymb(message, history):
|
| 24 |
-
#
|
| 25 |
-
prompt =
|
| 26 |
-
f"<|system|>\nYou are CodeSymb, a world-class coding assistant by NiftyOracleAI.\n"
|
| 27 |
-
f"<|user|>\n{message}\n"
|
| 28 |
-
f"<|assistant|>\n"
|
| 29 |
-
)
|
| 30 |
|
| 31 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 32 |
|
| 33 |
with torch.no_grad():
|
| 34 |
outputs = model.generate(
|
| 35 |
**inputs,
|
| 36 |
-
max_new_tokens=
|
| 37 |
-
temperature=0.
|
|
|
|
|
|
|
|
|
|
| 38 |
do_sample=True,
|
| 39 |
-
pad_token_id=tokenizer.eos_token_id
|
| 40 |
)
|
| 41 |
|
| 42 |
-
# Extract only the generated reply
|
| 43 |
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
# Clean Gradio chat interface
|
| 47 |
demo = gr.ChatInterface(
|
| 48 |
fn=chat_with_codesymb,
|
| 49 |
title="CodeSymb-1B Chat (ZeroGPU)",
|
| 50 |
-
description="Live inference for CodeSymb-1B FP16 GGUF
|
| 51 |
)
|
| 52 |
|
| 53 |
if __name__ == "__main__":
|
|
|
|
| 3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
import spaces
|
| 5 |
|
|
|
|
| 6 |
REPO_ID = "NiftyOracleAI/NiftyOracle-Coder-30B"
|
| 7 |
GGUF_FILE = "gguf/codesymb_1b_chat_FP16.gguf"
|
| 8 |
|
|
|
|
| 17 |
)
|
| 18 |
print("✅ Model loaded into memory!")
|
| 19 |
|
|
|
|
| 20 |
@spaces.GPU
|
| 21 |
def chat_with_codesymb(message, history):
|
| 22 |
+
# Standard format without unmapped special tag conflicts
|
| 23 |
+
prompt = f"User: {message}\nAssistant:"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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=256,
|
| 31 |
+
temperature=0.6,
|
| 32 |
+
top_p=0.9,
|
| 33 |
+
repetition_penalty=1.25, # 🛑 Breaks the infinite repetition loop!
|
| 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 |
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 40 |
+
|
| 41 |
+
# Strip any stray prompt echoes
|
| 42 |
+
if "User:" in response:
|
| 43 |
+
response = response.split("User:")[0]
|
| 44 |
+
|
| 45 |
+
return response.strip()
|
| 46 |
|
|
|
|
| 47 |
demo = gr.ChatInterface(
|
| 48 |
fn=chat_with_codesymb,
|
| 49 |
title="CodeSymb-1B Chat (ZeroGPU)",
|
| 50 |
+
description="Live inference for CodeSymb-1B FP16 GGUF."
|
| 51 |
)
|
| 52 |
|
| 53 |
if __name__ == "__main__":
|