in app/app.py [0:0]
def load_languages() -> dict[str, str]:
"""Load languages from JSON file or persistent storage"""
languages_path, use_persistent = get_persistent_storage_path("languages.json")
local_path = Path(__file__).parent / "languages.json"
# If persistent storage is available but file doesn't exist yet, copy the local file to persistent storage
if use_persistent and not languages_path.exists():
try:
if local_path.exists():
import shutil
shutil.copy(local_path, languages_path)
print(f"Copied languages to persistent storage at {languages_path}")
else:
with open(languages_path, "w", encoding="utf-8") as f:
json.dump({"English": "You are a helpful assistant."}, f, ensure_ascii=False, indent=2)
print(f"Created new languages file in persistent storage at {languages_path}")
except Exception as e:
print(f"Error setting up persistent storage: {e}")
languages_path = local_path # Fall back to local path if any error occurs
if not languages_path.exists() and local_path.exists():
languages_path = local_path
if languages_path.exists():
with open(languages_path, "r", encoding="utf-8") as f:
return json.load(f)
else:
default_languages = {"English": "You are a helpful assistant."}
return default_languages