Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,7 +32,23 @@ def process_input(user_input, history):
|
|
| 32 |
return history
|
| 33 |
|
| 34 |
def visualize_memory():
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
print(f"✅ Visualization created at: {output_html}")
|
| 37 |
if os.path.exists(output_html):
|
| 38 |
return f"✅ Memory graph generated successfully!\n\nYou can open it here: {output_html}"
|
|
|
|
| 32 |
return history
|
| 33 |
|
| 34 |
def visualize_memory():
|
| 35 |
+
# Get all stored memories
|
| 36 |
+
memories = memory.memories
|
| 37 |
+
|
| 38 |
+
# Build relationships between memories (using simple semantic matching)
|
| 39 |
+
relationships = []
|
| 40 |
+
for i, (text1, vec1) in enumerate(memories):
|
| 41 |
+
for j, (text2, vec2) in enumerate(memories):
|
| 42 |
+
if i != j:
|
| 43 |
+
# Cosine similarity threshold
|
| 44 |
+
similarity = np.dot(vec1, vec2) / (np.linalg.norm(vec1) * np.linalg.norm(vec2))
|
| 45 |
+
if similarity > 0.35: # threshold for linking related memories
|
| 46 |
+
relationships.append((text1, text2, float(similarity)))
|
| 47 |
+
|
| 48 |
+
# Generate visualization
|
| 49 |
+
output_html = visualize_reasoned_graph(memories, relationships)
|
| 50 |
+
|
| 51 |
+
# Print confirmation and show output path
|
| 52 |
print(f"✅ Visualization created at: {output_html}")
|
| 53 |
if os.path.exists(output_html):
|
| 54 |
return f"✅ Memory graph generated successfully!\n\nYou can open it here: {output_html}"
|