awacke1 commited on
Commit
152d24f
Β·
verified Β·
1 Parent(s): 75ffde9

Create backup.app4.py

Browse files
Files changed (1) hide show
  1. backup.app4.py +85 -0
backup.app4.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import json
4
+
5
+ def save_user_data(email, data):
6
+ """Save user data to a file named after the user's email."""
7
+ with open(f"{email}.txt", "w") as file:
8
+ file.write(json.dumps(data))
9
+
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
+
17
+ 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 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
+
32
+ # Sidebar for selecting a user file
33
+ st.sidebar.title("Saved Users")
34
+ saved_users = list_saved_users()
35
+ selected_user = st.sidebar.selectbox("Select a user", options=['New User'] + saved_users)
36
+
37
+ # Load or initialize data
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
66
+ display_data = cached_data.copy()
67
+ display_data['password'] = '*****' # Hide the 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")
77
+ if reset_email and reset_email in saved_users:
78
+ reset_data = load_user_data(reset_email)
79
+ reset_data['password'] = 'new_password' # Reset password
80
+ save_user_data(reset_email, reset_data)
81
+ st.sidebar.success(f"Password reset for {reset_email}")
82
+
83
+ # Run the app
84
+ if __name__ == "__main__":
85
+ main()