awacke1 commited on
Commit
b94e6f3
Β·
verified Β·
1 Parent(s): 0852d28

Create backup.app5.py

Browse files
Files changed (1) hide show
  1. backup.app5.py +99 -0
backup.app5.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import json
4
+ import base64
5
+
6
+ def save_user_data(email, data):
7
+ """Save user data to a file named after the user's email."""
8
+ with open(f"{email}.txt", "w") as file:
9
+ file.write(json.dumps(data))
10
+
11
+ def load_user_data(email):
12
+ """Load user data from a file named after the user's email, or create a new file if it doesn't exist."""
13
+ if not os.path.isfile(f"{email}.txt"):
14
+ return {'email': '', 'phone': '', 'password': '', 'social': {}}
15
+ with open(f"{email}.txt", "r") as file:
16
+ return json.loads(file.read())
17
+
18
+ def list_saved_users():
19
+ """List all files (users) with saved states containing '@' in filename."""
20
+ return [f[:-4] for f in os.listdir() if f.endswith('.txt') and '@' in f]
21
+
22
+ def get_file_download_link(filename):
23
+ """Generate a file download link."""
24
+ with open(filename, "rb") as file:
25
+ base64_file = base64.b64encode(file.read()).decode()
26
+ href = f'<a href="data:file/txt;base64,{base64_file}" download="{filename}">Download {filename}</a>'
27
+ return href
28
+
29
+ def display_social_links(social_data):
30
+ """Display social media links as Markdown."""
31
+ st.markdown("## Social Media Links")
32
+ for platform, url in social_data.items():
33
+ if url:
34
+ emoji = {"instagram": "πŸ“·", "twitter": "🐦", "facebook": "πŸ“˜", "huggingface": "πŸ€—", "github": "πŸ’»", "linkedin": "πŸ”—"}.get(platform, "")
35
+ st.markdown(f"{emoji} [{platform.capitalize()}]({url})")
36
+
37
+ def main():
38
+ st.title('User Data Management')
39
+
40
+ # Sidebar for selecting a user file
41
+ st.sidebar.title("Saved Users")
42
+ saved_users = list_saved_users()
43
+ selected_user = st.sidebar.selectbox("Select a user", options=['New User'] + saved_users)
44
+
45
+ # Load or initialize data
46
+ if selected_user and selected_user != 'New User':
47
+ cached_data = load_user_data(selected_user)
48
+ else:
49
+ cached_data = {'email': '', 'phone': '', 'password': '', 'social': {}}
50
+
51
+ # Input fields with emojis
52
+ new_email = st.text_input("πŸ“§ Email Address", value=cached_data['email'])
53
+ new_phone = st.text_input("πŸ“± Mobile Phone", value=cached_data['phone'])
54
+ new_password = st.text_input("πŸ”‘ Password", value=cached_data['password'], type='password')
55
+
56
+ # Social media fields
57
+ st.markdown("### Social Media Profiles")
58
+ social_fields = ["instagram", "twitter", "facebook", "huggingface", "github", "linkedin"]
59
+ for field in social_fields:
60
+ emoji = {"instagram": "πŸ“·", "twitter": "🐦", "facebook": "πŸ“˜", "huggingface": "πŸ€—", "github": "πŸ’»", "linkedin": "πŸ”—"}.get(field, "")
61
+ cached_data['social'][field] = st.text_input(f"{emoji} {field.capitalize()}", value=cached_data['social'].get(field, ''))
62
+
63
+ # Save data when changes are made
64
+ if st.button("Save Data"):
65
+ save_user_data(new_email, {'email': new_email, 'phone': new_phone, 'password': new_password, 'social': cached_data['social']})
66
+ st.sidebar.success("Data updated and saved!")
67
+
68
+ # Download link for user data file
69
+ if selected_user and selected_user != 'New User':
70
+ st.sidebar.markdown(get_file_download_link(f"{selected_user}.txt"), unsafe_allow_html=True)
71
+
72
+ # File uploader
73
+ uploaded_file = st.sidebar.file_uploader("πŸ“€ Upload User File", type='txt')
74
+ if uploaded_file is not None:
75
+ uploaded_data = json.loads(uploaded_file.getvalue().decode())
76
+ save_user_data(uploaded_data['email'], uploaded_data)
77
+ st.sidebar.success("Uploaded and saved!")
78
+
79
+ # Display current data without password
80
+ display_data = cached_data.copy()
81
+ display_data['password'] = '*****' # Hide the password
82
+ st.write("Current Data:")
83
+ st.json(display_data)
84
+
85
+ # Display social media links
86
+ display_social_links(cached_data['social'])
87
+
88
+ # Password Reset Simulation
89
+ if st.sidebar.button("Reset Password"):
90
+ reset_email = st.sidebar.text_input("Enter email for password reset")
91
+ if reset_email and reset_email in saved_users:
92
+ reset_data = load_user_data(reset_email)
93
+ reset_data['password'] = 'new_password' # Reset password
94
+ save_user_data(reset_email, reset_data)
95
+ st.sidebar.success(f"Password reset for {reset_email}")
96
+
97
+ # Run the app
98
+ if __name__ == "__main__":
99
+ main()