Spaces:
Runtime error
Runtime error
trail3 app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,21 @@ memory_db = {}
|
|
| 7 |
# Load the model
|
| 8 |
interpreter = pipeline("text2text-generation", model="google/flan-t5-base")
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Interpret a message with optional memory and return AI explanation + history
|
| 11 |
def interpret_message(msg, name, closeness, traits, relation, past_events, feelings, use_memory):
|
| 12 |
if not msg.strip() or not name.strip():
|
|
@@ -30,7 +45,7 @@ def interpret_message(msg, name, closeness, traits, relation, past_events, feeli
|
|
| 30 |
}
|
| 31 |
|
| 32 |
# Construct rich prompt
|
| 33 |
-
prompt = f"""
|
| 34 |
|
| 35 |
# Save to memory if applicable
|
| 36 |
if use_memory:
|
|
@@ -68,7 +83,19 @@ def memory_chat(user_input, person_name):
|
|
| 68 |
history = memory_db[name]["history"]
|
| 69 |
past_text = "\n\n".join([f"- {h['message']}\n -> {h['interpretation']}" for h in history])
|
| 70 |
|
| 71 |
-
chat_prompt = f"""You are a relationship and social communication expert
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
response = interpreter(chat_prompt, max_new_tokens=200)[0]["generated_text"]
|
| 74 |
return response
|
|
|
|
| 7 |
# Load the model
|
| 8 |
interpreter = pipeline("text2text-generation", model="google/flan-t5-base")
|
| 9 |
|
| 10 |
+
# Few-shot examples for priming the model
|
| 11 |
+
few_shot_examples = """
|
| 12 |
+
Example 1:
|
| 13 |
+
Message: "sure. whatever you want"
|
| 14 |
+
→ Interpretation: Passive-aggressive, likely annoyed but masking it with false agreement.
|
| 15 |
+
|
| 16 |
+
Example 2:
|
| 17 |
+
Message: "we’ll see"
|
| 18 |
+
→ Interpretation: Avoidant, doesn’t want to commit or say no directly.
|
| 19 |
+
|
| 20 |
+
Example 3:
|
| 21 |
+
Message: "it's fine, don't worry about it"
|
| 22 |
+
→ Interpretation: Likely masking frustration or disappointment, doesn’t want to express upset directly.
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
# Interpret a message with optional memory and return AI explanation + history
|
| 26 |
def interpret_message(msg, name, closeness, traits, relation, past_events, feelings, use_memory):
|
| 27 |
if not msg.strip() or not name.strip():
|
|
|
|
| 45 |
}
|
| 46 |
|
| 47 |
# Construct rich prompt
|
| 48 |
+
prompt = f"""{few_shot_examples}\n\nNew message from {name}: \"{msg}\"\n\nKnown context:\n- Closeness: {closeness}\n- Personality: {traits}\n- Relationship: {relation}\n- Similar Past Events: {past_events}\n- Your Feelings: {feelings}\n\nBased on the message and context, explain what the person is *really thinking* or feeling but not saying directly.\nInfer their hidden intention, emotional state, and subtext. Then suggest how I should respond."""
|
| 49 |
|
| 50 |
# Save to memory if applicable
|
| 51 |
if use_memory:
|
|
|
|
| 83 |
history = memory_db[name]["history"]
|
| 84 |
past_text = "\n\n".join([f"- {h['message']}\n -> {h['interpretation']}" for h in history])
|
| 85 |
|
| 86 |
+
chat_prompt = f"""You are a relationship and social communication expert trained in human behavior.
|
| 87 |
+
|
| 88 |
+
Here is what you know about {name}'s recent messages and past behavior:
|
| 89 |
+
{past_text}
|
| 90 |
+
|
| 91 |
+
The user now asks: {user_input}
|
| 92 |
+
|
| 93 |
+
Respond with a supportive and emotionally intelligent answer based on past messages.
|
| 94 |
+
Avoid repeating the user's input. Be specific. If {name} is likely upset, say it.
|
| 95 |
+
If the user should give space or check in, say so.
|
| 96 |
+
|
| 97 |
+
Only output your advice in 2–4 sentences. No explanation of what you’re doing.
|
| 98 |
+
"""
|
| 99 |
|
| 100 |
response = interpreter(chat_prompt, max_new_tokens=200)[0]["generated_text"]
|
| 101 |
return response
|