Spaces:
Runtime error
Runtime error
Commit
·
273fb8f
1
Parent(s):
9aa727e
update
Browse files
app.py
CHANGED
@@ -64,6 +64,8 @@ from datetime import datetime
|
|
64 |
from huggingface_hub import HfApi
|
65 |
|
66 |
|
|
|
|
|
67 |
def save_session_data(username, data):
|
68 |
try:
|
69 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
@@ -77,31 +79,29 @@ def save_session_data(username, data):
|
|
77 |
with open(temp_file_path, 'w') as f:
|
78 |
f.write(json_data)
|
79 |
|
80 |
-
# Upload the file to Hugging Face
|
81 |
api = HfApi()
|
82 |
api.upload_file(
|
83 |
path_or_fileobj=temp_file_path,
|
84 |
path_in_repo=f"session_data/{file_name}",
|
85 |
-
repo_id="luulinh90s/Tabular-LLM-Study-
|
86 |
repo_type="space",
|
87 |
)
|
88 |
|
89 |
# Remove the temporary file
|
90 |
os.remove(temp_file_path)
|
91 |
|
92 |
-
logger.info(f"Session data saved for user {username} in Hugging Face Space")
|
93 |
except Exception as e:
|
94 |
logger.exception(f"Error saving session data for user {username}: {e}")
|
95 |
|
96 |
|
97 |
-
from huggingface_hub import hf_hub_download
|
98 |
-
|
99 |
-
|
100 |
def load_session_data(username):
|
101 |
try:
|
102 |
-
# List files in the session_data directory
|
103 |
api = HfApi()
|
104 |
-
files = api.list_repo_files(repo_id="luulinh90s/Tabular-LLM-Study-
|
105 |
|
106 |
# Filter and sort files for the user
|
107 |
user_files = [f for f in files if f.startswith(f'session_data/{username}_') and f.endswith('_session.json')]
|
@@ -113,13 +113,14 @@ def load_session_data(username):
|
|
113 |
# Get the most recent file
|
114 |
latest_file = sorted(user_files, reverse=True)[0]
|
115 |
|
116 |
-
# Download the file
|
117 |
-
file_path = hf_hub_download(repo_id="luulinh90s/Tabular-LLM-Study-
|
|
|
118 |
|
119 |
with open(file_path, 'r') as f:
|
120 |
data = json.load(f)
|
121 |
|
122 |
-
logger.info(f"Session data loaded for user {username} from Hugging Face Space")
|
123 |
return data
|
124 |
except Exception as e:
|
125 |
logger.exception(f"Error loading session data for user {username}: {e}")
|
|
|
64 |
from huggingface_hub import HfApi
|
65 |
|
66 |
|
67 |
+
from huggingface_hub import HfApi
|
68 |
+
|
69 |
def save_session_data(username, data):
|
70 |
try:
|
71 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
79 |
with open(temp_file_path, 'w') as f:
|
80 |
f.write(json_data)
|
81 |
|
82 |
+
# Upload the file to a separate Hugging Face Space dedicated to data storage
|
83 |
api = HfApi()
|
84 |
api.upload_file(
|
85 |
path_or_fileobj=temp_file_path,
|
86 |
path_in_repo=f"session_data/{file_name}",
|
87 |
+
repo_id="luulinh90s/Tabular-LLM-Study-Data", # Replace with your new data storage Space name
|
88 |
repo_type="space",
|
89 |
)
|
90 |
|
91 |
# Remove the temporary file
|
92 |
os.remove(temp_file_path)
|
93 |
|
94 |
+
logger.info(f"Session data saved for user {username} in Hugging Face Data Space")
|
95 |
except Exception as e:
|
96 |
logger.exception(f"Error saving session data for user {username}: {e}")
|
97 |
|
98 |
|
99 |
+
from huggingface_hub import hf_hub_download, HfApi
|
|
|
|
|
100 |
def load_session_data(username):
|
101 |
try:
|
102 |
+
# List files in the session_data directory of the data storage Space
|
103 |
api = HfApi()
|
104 |
+
files = api.list_repo_files(repo_id="luulinh90s/Tabular-LLM-Study-Data", repo_type="space", path="session_data")
|
105 |
|
106 |
# Filter and sort files for the user
|
107 |
user_files = [f for f in files if f.startswith(f'session_data/{username}_') and f.endswith('_session.json')]
|
|
|
113 |
# Get the most recent file
|
114 |
latest_file = sorted(user_files, reverse=True)[0]
|
115 |
|
116 |
+
# Download the file from the data storage Space
|
117 |
+
file_path = hf_hub_download(repo_id="luulinh90s/Tabular-LLM-Study-Data", repo_type="space",
|
118 |
+
filename=latest_file)
|
119 |
|
120 |
with open(file_path, 'r') as f:
|
121 |
data = json.load(f)
|
122 |
|
123 |
+
logger.info(f"Session data loaded for user {username} from Hugging Face Data Space")
|
124 |
return data
|
125 |
except Exception as e:
|
126 |
logger.exception(f"Error loading session data for user {username}: {e}")
|