iris-backend / gallery.py
trretretret's picture
new login method woth deep debugging
d672525
Raw
History Blame Contribute Delete
2.48 kB
# # # import pickle
# # # # from config import GALLERY_PATH
# # # from config import Config
# # # def load_gallery():
# # # with open(Config.GALLERY_PATH, "rb") as f:
# # # return pickle.load(f)
# # # def save_gallery(data):
# # # with open(Config.GALLERY_PATH, "wb") as f:
# # # pickle.dump(data, f)
# # import os
# # import pickle
# # # from config import GALLERY_PATH
# # from config import Config
# # def load_gallery():
# # if not os.path.exists(Config.GALLERY_PATH):
# # raise FileNotFoundError(f"Gallery not found: {Config.GALLERY_PATH}")
# # with open(Config.GALLERY_PATH, "rb") as f:
# # data = pickle.load(f)
# # return data
# # def save_gallery(data):
# # with open(Config.GALLERY_PATH, "wb") as f:
# # pickle.dump(data, f)
# import os
# import pickle
# # from config import GALLERY_PATH
# from config import Config
# def load_gallery():
# if not os.path.exists(Config.GALLERY_PATH):
# raise FileNotFoundError(f"Gallery not found: {Config.GALLERY_PATH}")
# with open(Config.GALLERY_PATH, "rb") as f:
# data = pickle.load(f)
# return data
# def save_gallery(data):
# with open(Config.GALLERY_PATH, "wb") as f:
# pickle.dump(data, f)
import os
import pickle
from huggingface_hub import upload_file
from config import Config
GALLERY_REPO = "Omamaa12/iris-models"
GALLERY_FILENAME = "iris_gallery_robustt.pkl"
HF_TOKEN = os.getenv("HF_TOKEN")
def load_gallery():
if not os.path.exists(Config.GALLERY_PATH):
raise FileNotFoundError(f"Gallery not found: {Config.GALLERY_PATH}")
with open(Config.GALLERY_PATH, "rb") as f:
return pickle.load(f)
def save_gallery(data):
# 1. Save to local disk (same as before)
with open(Config.GALLERY_PATH, "wb") as f:
pickle.dump(data, f)
# 2. Push updated gallery back to HuggingFace Hub so it survives restarts
try:
upload_file(
path_or_fileobj=Config.GALLERY_PATH,
path_in_repo=GALLERY_FILENAME,
repo_id=GALLERY_REPO,
token=HF_TOKEN,
commit_message="Auto-update gallery after new registration",
)
print(f"✅ Gallery pushed to HuggingFace ({GALLERY_REPO}/{GALLERY_FILENAME})")
except Exception as e:
print(f"⚠️ Gallery saved locally but HuggingFace upload FAILED: {e}")
# Don't raise — registration still succeeded in-memory and on disk