broadfield-dev commited on
Commit
a169da7
·
verified ·
1 Parent(s): 794db80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
app.py CHANGED
@@ -1,6 +1,8 @@
1
  import os
2
  from flask import Flask, render_template, request, jsonify
3
- from memvid_sdk import Memvid
 
 
4
  from huggingface_hub import hf_hub_download, upload_file, HfApi
5
 
6
  app = Flask(__name__)
@@ -72,14 +74,22 @@ def init_db():
72
 
73
  # 2. Initialize Memvid (Fixes 'no attribute create' error)
74
  try:
75
- # In Python SDKs, the constructor usually handles Open OR Create.
76
- # If the file exists, it opens it. If not, it creates it.
77
- db = Memvid(DB_PATH)
78
- print(f"✨ Memvid initialized at {DB_PATH}")
79
 
80
- except Exception as e:
81
- print(f"❌ CRITICAL ERROR initializing Memvid: {e}")
82
- db = None
 
 
 
 
 
 
 
 
83
 
84
  def sync_to_hub():
85
  """Uploads the local .mv2 file back to Hugging Face"""
 
1
  import os
2
  from flask import Flask, render_template, request, jsonify
3
+ #from memvid_sdk import Memvid
4
+ from memvid_sdk import create, open as open_memvid
5
+
6
  from huggingface_hub import hf_hub_download, upload_file, HfApi
7
 
8
  app = Flask(__name__)
 
74
 
75
  # 2. Initialize Memvid (Fixes 'no attribute create' error)
76
  try:
77
+ if os.path.exists(DB_PATH):
78
+ db = open_memvid(DB_PATH) # Use the imported 'open' function
79
+ else:
80
+ db = create(DB_PATH) # Use the imported 'create' function
81
 
82
+ except ImportError:
83
+ # If the above imports fail, fall back to the class method style
84
+ # (Only do this if the library version is different than expected)
85
+ from memvid_sdk import Memvid
86
+ if os.path.exists(DB_PATH):
87
+ # Some bindings require an empty init first
88
+ db = Memvid()
89
+ db.open(DB_PATH)
90
+ else:
91
+ db = Memvid()
92
+ db.create(DB_PATH)
93
 
94
  def sync_to_hub():
95
  """Uploads the local .mv2 file back to Hugging Face"""