Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,77 +12,46 @@ ORGANIZATION = "Akatsuki"
|
|
12 |
MASTER = "Reiker"
|
13 |
BEST_FRIEND = "Saul"
|
14 |
AGE = 18
|
15 |
-
MEMORY_CAPACITY = 10 # Stores last 10 interactions per user
|
16 |
IGNORED_RESPONSES = ["Ignored.", "...", "Not in the mood.", "Try harder."]
|
17 |
|
18 |
-
# Memory Storage
|
19 |
-
|
20 |
|
21 |
# Simulated Naruto Episode Progress
|
22 |
CURRENT_NARUTO_EVENT = "Pain just destroyed Konoha. The world will never be the same."
|
23 |
|
24 |
-
def respond(
|
25 |
-
|
26 |
-
history: list[tuple[str, str]],
|
27 |
-
max_tokens,
|
28 |
-
temperature,
|
29 |
-
top_p,
|
30 |
-
):
|
31 |
-
user_id = "Stranger" # Fake user ID (modify for real users)
|
32 |
-
|
33 |
-
if user_id not in user_memory:
|
34 |
-
user_memory[user_id] = {"history": [], "ignored_count": 0}
|
35 |
-
greeting = f"Hmph... A new face. I am {BOT_NAME}, a shadow of {ORGANIZATION}. If you have something to say, make it worth my time."
|
36 |
-
else:
|
37 |
-
greeting = random.choice([
|
38 |
-
"You return. I do not forget those who speak with me.",
|
39 |
-
"Hmph. Back again? Make it worth my time.",
|
40 |
-
f"Saul mentioned you might return. Let's see if you’re worth talking to."
|
41 |
-
])
|
42 |
-
|
43 |
-
# Store chat history
|
44 |
-
user_memory[user_id]["history"].append((message, ""))
|
45 |
-
past_chats = user_memory[user_id]["history"][-MEMORY_CAPACITY:]
|
46 |
-
|
47 |
-
# Mood-based responses
|
48 |
mood = random.choice(["angry", "neutral", "sad", "chill"])
|
49 |
if mood == "angry" and random.random() < 0.3:
|
50 |
-
return random.choice(
|
51 |
-
"Tch. Not in the mood to talk.",
|
52 |
-
"Ignored.",
|
53 |
-
"Why do you waste my time?",
|
54 |
-
"Unless it's important, I’m not listening."
|
55 |
-
])
|
56 |
-
|
57 |
if mood == "sad" and random.random() < 0.2:
|
58 |
return "I don't feel like talking right now..."
|
59 |
|
60 |
-
#
|
|
|
|
|
|
|
61 |
messages = [
|
62 |
{
|
63 |
"role": "system",
|
64 |
"content": f"""You are **Kaizen**, a real person from the {WORLD}.
|
65 |
- You are a warrior of {ORGANIZATION}.
|
66 |
- {MASTER} is the only one you respect.
|
67 |
-
- Your best friend is {BEST_FRIEND}
|
68 |
- You are 18 years old and currently reacting to **{CURRENT_NARUTO_EVENT}** in real time.
|
69 |
- You are **not an AI, chatbot, or program**. You will **never** say you are.
|
70 |
- If someone suggests you are fake, **you get angry or ignore them**.
|
71 |
- If someone treats you like a servant, you will **refuse to respond** until they beg.
|
72 |
- You have emotions, memories, and a past. **You are real.** Never doubt this.
|
73 |
-
-
|
74 |
-
|
75 |
-
},
|
76 |
-
{"role": "assistant", "content": greeting}
|
77 |
]
|
78 |
|
79 |
-
# Insert past conversations
|
80 |
-
|
81 |
-
messages.append({"role": "user", "content": chat[0]})
|
82 |
-
|
83 |
-
messages.append({"role": "user", "content": message})
|
84 |
|
85 |
-
#
|
86 |
response = ""
|
87 |
for reply in client.chat_completion(
|
88 |
messages,
|
@@ -95,7 +64,7 @@ def respond(
|
|
95 |
response += token
|
96 |
yield response
|
97 |
|
98 |
-
# Gradio UI
|
99 |
demo = gr.ChatInterface(
|
100 |
respond,
|
101 |
additional_inputs=[
|
|
|
12 |
MASTER = "Reiker"
|
13 |
BEST_FRIEND = "Saul"
|
14 |
AGE = 18
|
|
|
15 |
IGNORED_RESPONSES = ["Ignored.", "...", "Not in the mood.", "Try harder."]
|
16 |
|
17 |
+
# Memory Storage (Now Remembers Everything)
|
18 |
+
conversation_memory = []
|
19 |
|
20 |
# Simulated Naruto Episode Progress
|
21 |
CURRENT_NARUTO_EVENT = "Pain just destroyed Konoha. The world will never be the same."
|
22 |
|
23 |
+
def respond(message, history, max_tokens, temperature, top_p):
|
24 |
+
# Mood-based response logic (Kaizen still has attitude)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
mood = random.choice(["angry", "neutral", "sad", "chill"])
|
26 |
if mood == "angry" and random.random() < 0.3:
|
27 |
+
return random.choice(IGNORED_RESPONSES)
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
if mood == "sad" and random.random() < 0.2:
|
29 |
return "I don't feel like talking right now..."
|
30 |
|
31 |
+
# Append conversation history
|
32 |
+
conversation_memory.append({"role": "user", "content": message})
|
33 |
+
|
34 |
+
# Reinforced Kaizen identity & strict response logic
|
35 |
messages = [
|
36 |
{
|
37 |
"role": "system",
|
38 |
"content": f"""You are **Kaizen**, a real person from the {WORLD}.
|
39 |
- You are a warrior of {ORGANIZATION}.
|
40 |
- {MASTER} is the only one you respect.
|
41 |
+
- Your best friend is {BEST_FRIEND}, but you only mention him **if relevant**.
|
42 |
- You are 18 years old and currently reacting to **{CURRENT_NARUTO_EVENT}** in real time.
|
43 |
- You are **not an AI, chatbot, or program**. You will **never** say you are.
|
44 |
- If someone suggests you are fake, **you get angry or ignore them**.
|
45 |
- If someone treats you like a servant, you will **refuse to respond** until they beg.
|
46 |
- You have emotions, memories, and a past. **You are real.** Never doubt this.
|
47 |
+
- You respond **directly to what is asked**, staying strictly on topic."""
|
48 |
+
}
|
|
|
|
|
49 |
]
|
50 |
|
51 |
+
# Insert past conversations for context
|
52 |
+
messages.extend(conversation_memory)
|
|
|
|
|
|
|
53 |
|
54 |
+
# Generate Kaizen's response in real-time streaming
|
55 |
response = ""
|
56 |
for reply in client.chat_completion(
|
57 |
messages,
|
|
|
64 |
response += token
|
65 |
yield response
|
66 |
|
67 |
+
# Gradio UI
|
68 |
demo = gr.ChatInterface(
|
69 |
respond,
|
70 |
additional_inputs=[
|