charantejapolavarapu commited on
Commit
2cd985f
·
verified ·
1 Parent(s): 582988e

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +12 -3
src/streamlit_app.py CHANGED
@@ -13,7 +13,8 @@ st.set_page_config(page_title="📍 BharatPulse - Local News & Sentiment", layou
13
  # IMPORTANT: For production, this 'users.json' file will not persist across deployments
14
  # on cloud platforms like Streamlit Community Cloud. Consider using a database (e.g., Firebase, PostgreSQL)
15
  # for persistent user data.
16
- USERS_FILE = "users.json"
 
17
 
18
  def load_users():
19
  """Loads user data from the JSON file."""
@@ -26,11 +27,19 @@ def load_users():
26
  # Handle case where file might be empty or corrupted
27
  st.error("Error loading user data. Initializing empty user database.")
28
  return {}
 
 
 
 
29
 
30
  def save_users(users):
31
  """Saves user data to the JSON file."""
32
- with open(USERS_FILE, "w") as f:
33
- json.dump(users, f, indent=2)
 
 
 
 
34
 
35
  def register_user(username, email, password, location):
36
  """Registers a new user."""
 
13
  # IMPORTANT: For production, this 'users.json' file will not persist across deployments
14
  # on cloud platforms like Streamlit Community Cloud. Consider using a database (e.g., Firebase, PostgreSQL)
15
  # for persistent user data.
16
+ # Changed USERS_FILE path to /tmp/ for write permissions in deployed environments
17
+ USERS_FILE = "/tmp/users.json"
18
 
19
  def load_users():
20
  """Loads user data from the JSON file."""
 
27
  # Handle case where file might be empty or corrupted
28
  st.error("Error loading user data. Initializing empty user database.")
29
  return {}
30
+ except Exception as e:
31
+ st.error(f"An unexpected error occurred while loading users: {e}")
32
+ return {}
33
+
34
 
35
  def save_users(users):
36
  """Saves user data to the JSON file."""
37
+ try:
38
+ with open(USERS_FILE, "w") as f:
39
+ json.dump(users, f, indent=2)
40
+ except Exception as e:
41
+ st.error(f"An unexpected error occurred while saving users: {e}")
42
+
43
 
44
  def register_user(username, email, password, location):
45
  """Registers a new user."""