Wajahat698 commited on
Commit
dcb2475
·
verified ·
1 Parent(s): c173c25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -19
app.py CHANGED
@@ -48,7 +48,7 @@ import asyncio
48
  import re
49
  # Set up logging to suppress Streamlit warnings about experimental functions
50
  logging.getLogger('streamlit').setLevel(logging.ERROR)
51
-
52
 
53
 
54
 
@@ -1208,10 +1208,31 @@ def display_save_confirmation(type_saved):
1208
  # Function to update the message counter in a static location
1209
  message_counter_placeholder = st.sidebar.empty()
1210
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1211
  def update_message_counter():
1212
  remaining_messages = st.session_state["message_limit"] - st.session_state["used_messages"]
1213
  message_counter_placeholder.markdown(f"**Messages Left**: {remaining_messages} / {st.session_state['message_limit']}")
1214
 
 
1215
  if st.session_state.get("wix_user_id") and st.session_state.get("email"):
1216
  retrieve_user_data(st.session_state["wix_user_id"])
1217
  display_saved_trustbuilders()
@@ -1221,24 +1242,7 @@ if st.session_state.get("wix_user_id") and st.session_state.get("email"):
1221
  welcome_placeholder.info(f"**Hello, {user_name}!**")
1222
  time.sleep(3)
1223
  welcome_placeholder.empty()
1224
- def check_user_subscription(wix_user_id):
1225
- response = requests.get(f"{backend_url}/check-subscription/{wix_user_id}")
1226
- if response.status_code == 200:
1227
- data = response.json()
1228
- st.session_state["message_limit"] = data.get("message_limit", 0)
1229
- st.session_state["used_messages"] = data.get("used_messages", 0)
1230
- update_message_counter()
1231
- else:
1232
- st.error("Error fetching user subscription details.")
1233
-
1234
- def update_message_usage(wix_user_id):
1235
- response = requests.post(f"{backend_url}/update-message-usage/{st.session_state['wix_user_id']}")
1236
- if response.status_code == 200:
1237
- st.session_state["used_messages"] += 1
1238
- update_message_counter()
1239
- else:
1240
- st.error("Error updating message usage.")
1241
- check_user_subscription(st.session_state["wix_user_id"])
1242
 
1243
  # Input for AI interaction
1244
  prompt = st.chat_input("")
 
48
  import re
49
  # Set up logging to suppress Streamlit warnings about experimental functions
50
  logging.getLogger('streamlit').setLevel(logging.ERROR)
51
+ INITIAL_MESSAGE_LIMIT = 100
52
 
53
 
54
 
 
1208
  # Function to update the message counter in a static location
1209
  message_counter_placeholder = st.sidebar.empty()
1210
 
1211
+ def initialize_message_limit(user_id):
1212
+ user_data = db.child("users").child(user_id).get().val()
1213
+ if user_data:
1214
+ st.session_state["message_limit"] = user_data.get("message_limit", INITIAL_MESSAGE_LIMIT)
1215
+ st.session_state["used_messages"] = user_data.get("used_messages", 0)
1216
+ else:
1217
+ # Set default limits for new users and store them in Firebase
1218
+ st.session_state["message_limit"] = INITIAL_MESSAGE_LIMIT
1219
+ st.session_state["used_messages"] = 0
1220
+ db.child("users").child(user_id).update({
1221
+ "message_limit": INITIAL_MESSAGE_LIMIT,
1222
+ "used_messages": 0
1223
+ })
1224
+
1225
+ def update_message_usage(user_id):
1226
+ st.session_state["used_messages"] += 1
1227
+ db.child("users").child(user_id).update({
1228
+ "used_messages": st.session_state["used_messages"]
1229
+ })
1230
+ update_message_counter()
1231
  def update_message_counter():
1232
  remaining_messages = st.session_state["message_limit"] - st.session_state["used_messages"]
1233
  message_counter_placeholder.markdown(f"**Messages Left**: {remaining_messages} / {st.session_state['message_limit']}")
1234
 
1235
+
1236
  if st.session_state.get("wix_user_id") and st.session_state.get("email"):
1237
  retrieve_user_data(st.session_state["wix_user_id"])
1238
  display_saved_trustbuilders()
 
1242
  welcome_placeholder.info(f"**Hello, {user_name}!**")
1243
  time.sleep(3)
1244
  welcome_placeholder.empty()
1245
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1246
 
1247
  # Input for AI interaction
1248
  prompt = st.chat_input("")