Spaces:
Runtime error
Runtime error
Memory app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,56 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
with gr.Blocks(title="Textual Chemistry") as app:
|
| 7 |
gr.Markdown("## π¬ Textual Chemistry\n_What do they really mean?_")
|
| 8 |
|
|
@@ -20,11 +68,13 @@ with gr.Blocks(title="Textual Chemistry") as app:
|
|
| 20 |
past_events = gr.Textbox(label="Similar Past Situations", placeholder="e.g., Last time I canceled they acted cold")
|
| 21 |
user_feelings = gr.Textbox(label="Your Current Feelings", placeholder="e.g., I feel confused or anxious")
|
| 22 |
|
| 23 |
-
output = gr.Textbox(label="AI Interpretation", lines=
|
| 24 |
|
| 25 |
submit_btn = gr.Button("Interpret Message")
|
| 26 |
-
submit_btn.click(
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
|
| 30 |
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# π In-memory memory store
|
| 4 |
+
memory_db = {}
|
| 5 |
|
| 6 |
+
# π§ Interpretation logic (placeholder for now)
|
| 7 |
+
def interpret_message(msg, name, closeness, traits, relation, past_events, feelings, use_memory):
|
| 8 |
+
if not msg.strip() or not name.strip():
|
| 9 |
+
return "Please enter both a message and a personβs name."
|
| 10 |
+
|
| 11 |
+
name = name.strip().title() # Normalize name
|
| 12 |
+
|
| 13 |
+
# Load or create person record
|
| 14 |
+
if use_memory:
|
| 15 |
+
if name in memory_db:
|
| 16 |
+
existing = memory_db[name]
|
| 17 |
+
closeness = closeness or existing.get("closeness")
|
| 18 |
+
traits = traits or existing.get("personality")
|
| 19 |
+
relation = relation or existing.get("relationship")
|
| 20 |
+
else:
|
| 21 |
+
memory_db[name] = {
|
| 22 |
+
"closeness": closeness,
|
| 23 |
+
"personality": traits,
|
| 24 |
+
"relationship": relation,
|
| 25 |
+
"history": []
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
# Build prompt
|
| 29 |
+
prompt = f"""New message from {name}: "{msg}"
|
| 30 |
+
|
| 31 |
+
Known context:
|
| 32 |
+
- Closeness: {closeness}
|
| 33 |
+
- Personality: {traits}
|
| 34 |
+
- Relationship: {relation}
|
| 35 |
+
- Similar Past Events: {past_events}
|
| 36 |
+
- Your Feelings: {feelings}
|
| 37 |
+
|
| 38 |
+
Interpret and suggest how I should respond."""
|
| 39 |
+
|
| 40 |
+
# Save to memory
|
| 41 |
+
if use_memory:
|
| 42 |
+
memory_db[name]["closeness"] = closeness
|
| 43 |
+
memory_db[name]["personality"] = traits
|
| 44 |
+
memory_db[name]["relationship"] = relation
|
| 45 |
+
memory_db[name]["history"].append({
|
| 46 |
+
"message": msg,
|
| 47 |
+
"prompt_used": prompt,
|
| 48 |
+
"interpretation": "TO BE FILLED"
|
| 49 |
+
})
|
| 50 |
+
|
| 51 |
+
return f"π§ Memory active for {name}.\n\n{prompt}"
|
| 52 |
+
|
| 53 |
+
# ποΈ Gradio UI
|
| 54 |
with gr.Blocks(title="Textual Chemistry") as app:
|
| 55 |
gr.Markdown("## π¬ Textual Chemistry\n_What do they really mean?_")
|
| 56 |
|
|
|
|
| 68 |
past_events = gr.Textbox(label="Similar Past Situations", placeholder="e.g., Last time I canceled they acted cold")
|
| 69 |
user_feelings = gr.Textbox(label="Your Current Feelings", placeholder="e.g., I feel confused or anxious")
|
| 70 |
|
| 71 |
+
output = gr.Textbox(label="AI Interpretation", lines=10)
|
| 72 |
|
| 73 |
submit_btn = gr.Button("Interpret Message")
|
| 74 |
+
submit_btn.click(
|
| 75 |
+
fn=interpret_message,
|
| 76 |
+
inputs=[message, person_name, closeness, sender_traits, relationship, past_events, user_feelings, use_memory],
|
| 77 |
+
outputs=output
|
| 78 |
+
)
|
| 79 |
|
| 80 |
app.launch()
|