YUVALON commited on
Commit
285fef1
·
verified ·
1 Parent(s): 2af6db3

trail3 app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -2
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"""New 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."""
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.\n\nYou remember all past messages and responses exchanged with {name}.\nThis is the known message history:\n{past_text}\n\nNow the user wants to understand more about what {name} might be thinking or feeling deep down,\nbased on what they've said before and how they usually act.\n\nUser’s question: {user_input}\n\nUse what you know from the history to infer hidden meaning, emotional tone, and behavior patterns.\nGive a thoughtful and emotionally intelligent answer. Avoid repeating the user's feelings."""
 
 
 
 
 
 
 
 
 
 
 
 
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