awacke1 commited on
Commit
7b1ed9a
Β·
verified Β·
1 Parent(s): 79b82de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -5
app.py CHANGED
@@ -10,7 +10,7 @@ def save_user_data(email, data):
10
  def load_user_data(email):
11
  """Load user data from a file named after the user's email, or create a new file if it doesn't exist."""
12
  if not os.path.isfile(f"{email}.txt"):
13
- return {'email': '', 'phone': '', 'password': ''}
14
  with open(f"{email}.txt", "r") as file:
15
  return json.loads(file.read())
16
 
@@ -18,6 +18,14 @@ def list_saved_users():
18
  """List all files (users) with saved states containing '@' in filename."""
19
  return [f[:-4] for f in os.listdir() if f.endswith('.txt') and '@' in f]
20
 
 
 
 
 
 
 
 
 
21
  def main():
22
  st.title('User Data Management')
23
 
@@ -30,22 +38,28 @@ def main():
30
  if selected_user and selected_user != 'New User':
31
  cached_data = load_user_data(selected_user)
32
  else:
33
- cached_data = {'email': '', 'phone': '', 'password': ''}
34
 
35
  # Input fields with emojis
36
  new_email = st.text_input("πŸ“§ Email Address", value=cached_data['email'])
37
  new_phone = st.text_input("πŸ“± Mobile Phone", value=cached_data['phone'])
38
  new_password = st.text_input("πŸ”‘ Password", value=cached_data['password'], type='password')
39
 
 
 
 
 
 
 
 
40
  # Save data when changes are made
41
- if new_email and (new_email != cached_data['email'] or new_phone != cached_data['phone'] or new_password != cached_data['password']):
42
- cached_data = {'email': new_email, 'phone': new_phone, 'password': new_password}
43
  save_user_data(new_email, cached_data)
44
  st.sidebar.success("Data updated and saved!")
45
 
46
  # Show email link with GET parameter
47
  if new_email:
48
- st.write(f"Link for this user: https://huggingface.co/spaces/awacke1/Streamlit-Memory-Cache-Resource-and-Data/?email={new_email}`")
49
  st.session_state['last_email'] = new_email
50
 
51
  # Display current data without password
@@ -54,6 +68,9 @@ def main():
54
  st.write("Current Data:")
55
  st.json(display_data)
56
 
 
 
 
57
  # Password Reset Simulation
58
  if st.sidebar.button("Reset Password"):
59
  reset_email = st.sidebar.text_input("Enter email for password reset")
 
10
  def load_user_data(email):
11
  """Load user data from a file named after the user's email, or create a new file if it doesn't exist."""
12
  if not os.path.isfile(f"{email}.txt"):
13
+ return {'email': '', 'phone': '', 'password': '', 'social': {}}
14
  with open(f"{email}.txt", "r") as file:
15
  return json.loads(file.read())
16
 
 
18
  """List all files (users) with saved states containing '@' in filename."""
19
  return [f[:-4] for f in os.listdir() if f.endswith('.txt') and '@' in f]
20
 
21
+ def display_social_links(social_data):
22
+ """Display social media links as Markdown."""
23
+ st.markdown("## Social Media Links")
24
+ for platform, url in social_data.items():
25
+ if url:
26
+ emoji = {"instagram": "πŸ“·", "twitter": "🐦", "facebook": "πŸ“˜", "huggingface": "πŸ€—", "github": "πŸ’»", "linkedin": "πŸ”—"}.get(platform, "")
27
+ st.markdown(f"{emoji} [{platform.capitalize()}]({url})")
28
+
29
  def main():
30
  st.title('User Data Management')
31
 
 
38
  if selected_user and selected_user != 'New User':
39
  cached_data = load_user_data(selected_user)
40
  else:
41
+ cached_data = {'email': '', 'phone': '', 'password': '', 'social': {}}
42
 
43
  # Input fields with emojis
44
  new_email = st.text_input("πŸ“§ Email Address", value=cached_data['email'])
45
  new_phone = st.text_input("πŸ“± Mobile Phone", value=cached_data['phone'])
46
  new_password = st.text_input("πŸ”‘ Password", value=cached_data['password'], type='password')
47
 
48
+ # Social media fields
49
+ st.markdown("### Social Media Profiles")
50
+ social_fields = ["instagram", "twitter", "facebook", "huggingface", "github", "linkedin"]
51
+ for field in social_fields:
52
+ emoji = {"instagram": "πŸ“·", "twitter": "🐦", "facebook": "πŸ“˜", "huggingface": "πŸ€—", "github": "πŸ’»", "linkedin": "πŸ”—"}.get(field, "")
53
+ cached_data['social'][field] = st.text_input(f"{emoji} {field.capitalize()}", value=cached_data['social'].get(field, ''))
54
+
55
  # Save data when changes are made
56
+ if st.button("Save Data"):
 
57
  save_user_data(new_email, cached_data)
58
  st.sidebar.success("Data updated and saved!")
59
 
60
  # Show email link with GET parameter
61
  if new_email:
62
+ st.write(f"Link for this user: `https://huggingface.co/spaces/awacke1/Streamlit-Memory-Cache-Resource-and-Data/?email={new_email}`")
63
  st.session_state['last_email'] = new_email
64
 
65
  # Display current data without password
 
68
  st.write("Current Data:")
69
  st.json(display_data)
70
 
71
+ # Display social media links
72
+ display_social_links(cached_data['social'])
73
+
74
  # Password Reset Simulation
75
  if st.sidebar.button("Reset Password"):
76
  reset_email = st.sidebar.text_input("Enter email for password reset")