Spaces:
Sleeping
Sleeping
Sayon Bhattacharyya commited on
Commit ·
5b545b2
1
Parent(s): 7a7dd8c
updated
Browse files- requirements.txt +1 -2
- src/streamlit_app.py +6 -52
requirements.txt
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
langchain_core
|
| 2 |
langchain_community
|
| 3 |
langchain_groq
|
| 4 |
-
streamlit==1.37.0
|
| 5 |
-
huggingface_hub>=0.20.0
|
|
|
|
| 1 |
langchain_core
|
| 2 |
langchain_community
|
| 3 |
langchain_groq
|
| 4 |
+
streamlit==1.37.0
|
|
|
src/streamlit_app.py
CHANGED
|
@@ -3,7 +3,7 @@ import json
|
|
| 3 |
from datetime import datetime
|
| 4 |
from typing import Dict, Any, List
|
| 5 |
import pandas as pd
|
| 6 |
-
|
| 7 |
import os
|
| 8 |
from service import generate_ai_response, create_user_profile_prompt, create_workout_type_prompt, create_nutrition_type_prompt, create_conversation_chat_prompt
|
| 9 |
|
|
@@ -73,61 +73,15 @@ st.markdown("""
|
|
| 73 |
</style>
|
| 74 |
""", unsafe_allow_html=True)
|
| 75 |
|
| 76 |
-
|
| 77 |
-
USERS_FILE = os.path.join("/home/user", "users.json")
|
| 78 |
-
|
| 79 |
-
# Constants
|
| 80 |
-
REPO_ID = "bsayon/Fitness-AI-Bot"
|
| 81 |
-
USERS_FILE = os.path.join("/home/user", "users.json")
|
| 82 |
-
TOKEN = os.getenv("HF_TOKEN")
|
| 83 |
|
| 84 |
def load_users() -> Dict[str, Dict]:
|
| 85 |
-
"""Load users from
|
| 86 |
-
|
| 87 |
-
if not os.path.exists(USERS_FILE):
|
| 88 |
-
# Try downloading from HF Hub if local file doesn't exist
|
| 89 |
-
st.info("Downloading users.json from Hugging Face Hub...")
|
| 90 |
-
try:
|
| 91 |
-
hf_hub_download(
|
| 92 |
-
repo_id=REPO_ID,
|
| 93 |
-
filename="users.json",
|
| 94 |
-
repo_type="space",
|
| 95 |
-
token=TOKEN,
|
| 96 |
-
local_dir="/home/user",
|
| 97 |
-
local_dir_use_symlinks=False,
|
| 98 |
-
)
|
| 99 |
-
except Exception as e:
|
| 100 |
-
st.warning(f"Could not download from HF Hub: {e}")
|
| 101 |
-
return {}
|
| 102 |
-
|
| 103 |
-
with open(USERS_FILE, 'r', encoding='utf-8') as f:
|
| 104 |
-
return json.load(f)
|
| 105 |
-
|
| 106 |
-
except (json.JSONDecodeError, FileNotFoundError):
|
| 107 |
-
return {}
|
| 108 |
|
| 109 |
def save_users(users: Dict[str, Dict]):
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
with open(USERS_FILE, 'w', encoding='utf-8') as f:
|
| 113 |
-
json.dump(users, f, indent=2, ensure_ascii=False)
|
| 114 |
-
st.success("User data saved locally.")
|
| 115 |
-
|
| 116 |
-
# Upload to Hugging Face Hub
|
| 117 |
-
try:
|
| 118 |
-
uploaded_url = hf_hub_upload(
|
| 119 |
-
repo_id=REPO_ID,
|
| 120 |
-
path_or_fileobj=USERS_FILE,
|
| 121 |
-
path_in_repo="users.json",
|
| 122 |
-
repo_type="space",
|
| 123 |
-
token=TOKEN
|
| 124 |
-
)
|
| 125 |
-
st.success("User data uploaded to Hugging Face Hub.")
|
| 126 |
-
except Exception as e:
|
| 127 |
-
st.warning(f"Upload to HF Hub failed: {e}")
|
| 128 |
-
|
| 129 |
-
except Exception as e:
|
| 130 |
-
st.error(f"Error saving user data: {str(e)}")
|
| 131 |
|
| 132 |
def create_user(session_alias: str, name: str = "") -> bool:
|
| 133 |
"""Create a new user in JSON file"""
|
|
|
|
| 3 |
from datetime import datetime
|
| 4 |
from typing import Dict, Any, List
|
| 5 |
import pandas as pd
|
| 6 |
+
import hashlib
|
| 7 |
import os
|
| 8 |
from service import generate_ai_response, create_user_profile_prompt, create_workout_type_prompt, create_nutrition_type_prompt, create_conversation_chat_prompt
|
| 9 |
|
|
|
|
| 73 |
</style>
|
| 74 |
""", unsafe_allow_html=True)
|
| 75 |
|
| 76 |
+
all_users: Dict[str, Dict] = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
def load_users() -> Dict[str, Dict]:
|
| 79 |
+
"""Load users from JSON file"""
|
| 80 |
+
return all_users
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
def save_users(users: Dict[str, Dict]):
|
| 83 |
+
global all_users
|
| 84 |
+
all_users.update(users)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
def create_user(session_alias: str, name: str = "") -> bool:
|
| 87 |
"""Create a new user in JSON file"""
|