Update app.py
Browse files
app.py
CHANGED
|
@@ -11,11 +11,9 @@ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
|
| 11 |
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
|
| 12 |
|
| 13 |
print("✅ Model loaded!")
|
| 14 |
-
|
| 15 |
-
# 🔹 Chat function
|
| 16 |
def chat(user_input):
|
| 17 |
-
# 🔥 Strong system prompt (
|
| 18 |
-
|
| 19 |
|
| 20 |
About you:
|
| 21 |
- Your name is G47 CHINKWENDE
|
|
@@ -35,11 +33,12 @@ Rules:
|
|
| 35 |
User: {user_input}
|
| 36 |
G47 CHINKWENDE:"""
|
| 37 |
|
|
|
|
| 38 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 39 |
|
| 40 |
output_ids = model.generate(
|
| 41 |
inputs["input_ids"],
|
| 42 |
-
max_new_tokens=150,
|
| 43 |
do_sample=True,
|
| 44 |
temperature=0.7,
|
| 45 |
top_p=0.9,
|
|
@@ -48,9 +47,9 @@ G47 CHINKWENDE:"""
|
|
| 48 |
|
| 49 |
response = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
if "
|
| 53 |
-
response = response.split("
|
| 54 |
|
| 55 |
return response
|
| 56 |
|
|
|
|
| 11 |
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
|
| 12 |
|
| 13 |
print("✅ Model loaded!")
|
|
|
|
|
|
|
| 14 |
def chat(user_input):
|
| 15 |
+
# 🔥 Strong system prompt (identity + rules)
|
| 16 |
+
prompt = f"""You are G47 CHINKWENDE, a powerful AI assistant created by Emalawi19.
|
| 17 |
|
| 18 |
About you:
|
| 19 |
- Your name is G47 CHINKWENDE
|
|
|
|
| 33 |
User: {user_input}
|
| 34 |
G47 CHINKWENDE:"""
|
| 35 |
|
| 36 |
+
# ✅ Make sure this line starts at the SAME level as the prompt variable
|
| 37 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 38 |
|
| 39 |
output_ids = model.generate(
|
| 40 |
inputs["input_ids"],
|
| 41 |
+
max_new_tokens=150,
|
| 42 |
do_sample=True,
|
| 43 |
temperature=0.7,
|
| 44 |
top_p=0.9,
|
|
|
|
| 47 |
|
| 48 |
response = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 49 |
|
| 50 |
+
# 🔹 Clean output
|
| 51 |
+
if "G47 CHINKWENDE:" in response:
|
| 52 |
+
response = response.split("G47 CHINKWENDE:")[-1].strip()
|
| 53 |
|
| 54 |
return response
|
| 55 |
|