Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import os
|
| 2 |
from flask import Flask, render_template, request, jsonify
|
| 3 |
-
# Using the imports and init logic you confirmed works
|
| 4 |
from memvid_sdk import create, open as open_memvid
|
| 5 |
from huggingface_hub import hf_hub_download, upload_file, HfApi
|
| 6 |
|
|
@@ -71,7 +70,6 @@ def init_db():
|
|
| 71 |
except Exception as e:
|
| 72 |
print(f"⚠️ Cloud sync warning: {e}")
|
| 73 |
|
| 74 |
-
# 2. Initialize Memvid (YOUR WORKING LOGIC)
|
| 75 |
try:
|
| 76 |
if os.path.exists(DB_PATH):
|
| 77 |
db = open_memvid(DB_PATH, read_only=False)
|
|
@@ -130,11 +128,9 @@ def add_memory():
|
|
| 130 |
return jsonify({"error": "No content provided"}), 400
|
| 131 |
|
| 132 |
try:
|
| 133 |
-
# FIX: The error "requires either 'label' or 'labels'" implies
|
| 134 |
-
# the dict must contain both the text AND a label field.
|
| 135 |
payload = {
|
| 136 |
"text": content,
|
| 137 |
-
"labels": ["web-entry"],
|
| 138 |
"title": "User Memory"
|
| 139 |
}
|
| 140 |
|
|
@@ -174,11 +170,8 @@ def search_memory():
|
|
| 174 |
if score < 0.65: continue
|
| 175 |
|
| 176 |
# --- CLEANING LOGIC ---
|
| 177 |
-
# 1. Get raw snippet
|
| 178 |
raw_snippet = hit.get('snippet', '')
|
| 179 |
|
| 180 |
-
# 2. Split by lines and remove technical metadata headers
|
| 181 |
-
# (The raw snippet appends metadata at the bottom)
|
| 182 |
lines = raw_snippet.split('\n')
|
| 183 |
content_lines = [
|
| 184 |
line for line in lines
|
|
@@ -186,16 +179,14 @@ def search_memory():
|
|
| 186 |
]
|
| 187 |
clean_text = "\n".join(content_lines).strip()
|
| 188 |
|
| 189 |
-
# 3. Use the explicit arrays provided by the SDK for tags/labels
|
| 190 |
-
# (These are much cleaner than parsing the string)
|
| 191 |
tags = hit.get('tags', [])
|
| 192 |
labels = hit.get('labels', [])
|
| 193 |
|
| 194 |
clean_results.append({
|
| 195 |
"title": hit.get('title') or "Untitled Memory",
|
| 196 |
-
"text": clean_text,
|
| 197 |
-
"tags": tags,
|
| 198 |
-
"labels": labels,
|
| 199 |
"date": hit.get('created_at', ''),
|
| 200 |
"score": f"{score:.2f}"
|
| 201 |
})
|
|
|
|
| 1 |
import os
|
| 2 |
from flask import Flask, render_template, request, jsonify
|
|
|
|
| 3 |
from memvid_sdk import create, open as open_memvid
|
| 4 |
from huggingface_hub import hf_hub_download, upload_file, HfApi
|
| 5 |
|
|
|
|
| 70 |
except Exception as e:
|
| 71 |
print(f"⚠️ Cloud sync warning: {e}")
|
| 72 |
|
|
|
|
| 73 |
try:
|
| 74 |
if os.path.exists(DB_PATH):
|
| 75 |
db = open_memvid(DB_PATH, read_only=False)
|
|
|
|
| 128 |
return jsonify({"error": "No content provided"}), 400
|
| 129 |
|
| 130 |
try:
|
|
|
|
|
|
|
| 131 |
payload = {
|
| 132 |
"text": content,
|
| 133 |
+
"labels": ["web-entry"],
|
| 134 |
"title": "User Memory"
|
| 135 |
}
|
| 136 |
|
|
|
|
| 170 |
if score < 0.65: continue
|
| 171 |
|
| 172 |
# --- CLEANING LOGIC ---
|
|
|
|
| 173 |
raw_snippet = hit.get('snippet', '')
|
| 174 |
|
|
|
|
|
|
|
| 175 |
lines = raw_snippet.split('\n')
|
| 176 |
content_lines = [
|
| 177 |
line for line in lines
|
|
|
|
| 179 |
]
|
| 180 |
clean_text = "\n".join(content_lines).strip()
|
| 181 |
|
|
|
|
|
|
|
| 182 |
tags = hit.get('tags', [])
|
| 183 |
labels = hit.get('labels', [])
|
| 184 |
|
| 185 |
clean_results.append({
|
| 186 |
"title": hit.get('title') or "Untitled Memory",
|
| 187 |
+
"text": clean_text,
|
| 188 |
+
"tags": tags,
|
| 189 |
+
"labels": labels,
|
| 190 |
"date": hit.get('created_at', ''),
|
| 191 |
"score": f"{score:.2f}"
|
| 192 |
})
|