File size: 5,942 Bytes
ece7ba2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
Create a torch demonstration and use data created with this program below for input and output.  Design a torch demo that uses simple convolutions to explain correlation between one word and another and add to IO patterns of this program and use requests and nlp including nltk to remix a demonstration app that uses the text files as input.  Have this allow users to build their library of prompts and add it to their user file defined by email address named text file.  Add links to sites with reference documentation.  Use this as teaching lesson in python streamlit UI and ccode yet remove all comments and just have variable names be super descriptive:  import streamlit as st
import os
import json
import base64

def save_user_data(email, data):
    """Save user data to a file named after the user's email."""
    with open(f"{email}.txt", "w") as file:
        file.write(json.dumps(data))

def load_user_data(email):
    """Load user data from a file named after the user's email, or create a new file if it doesn't exist."""
    if not os.path.isfile(f"{email}.txt"):
        return {'email': '', 'phone': '', 'password': '', 'social': {}}
    with open(f"{email}.txt", "r") as file:
        return json.loads(file.read())

def list_saved_users():
    """List all files (users) with saved states containing '@' in filename."""
    return [f[:-4] for f in os.listdir() if f.endswith('.txt') and '@' in f]

def get_file_download_link(filename):
    """Generate a file download link."""
    with open(filename, "rb") as file:
        base64_file = base64.b64encode(file.read()).decode()
    href = f'<a href="data:file/txt;base64,{base64_file}" download="{filename}">Download {filename}</a>'
    return href

def display_social_links(social_data):
    """Display social media links as Markdown."""
    st.markdown("## Social Media Links")
    for platform, url in social_data.items():
        if url:
            emoji = {"instagram": "πŸ“·", "twitter": "🐦", "facebook": "πŸ“˜", "huggingface": "πŸ€—", "github": "πŸ’»", "linkedin": "πŸ”—"}.get(platform, "")
            st.markdown(f"{emoji} [{platform.capitalize()}]({url})")

def main():
    st.title('User Data Management')

    # Sidebar for selecting a user file
    st.sidebar.title("Saved Users")
    saved_users = list_saved_users()
    selected_user = st.sidebar.selectbox("Select a user", options=['New User'] + saved_users)

    # Load or initialize data
    if selected_user and selected_user != 'New User':
        cached_data = load_user_data(selected_user)
    else:
        cached_data = {'email': '', 'phone': '', 'password': '', 'social': {}}

    # Input fields with emojis
    new_email = st.text_input("πŸ“§ Email Address", value=cached_data['email'])
    new_phone = st.text_input("πŸ“± Mobile Phone", value=cached_data['phone'])
    new_password = st.text_input("πŸ”‘ Password", value=cached_data['password'], type='password')

    # Social media fields
    st.markdown("### Social Media Profiles")
    social_fields = ["instagram", "twitter", "facebook", "huggingface", "github", "linkedin"]
    for field in social_fields:
        emoji = {"instagram": "πŸ“·", "twitter": "🐦", "facebook": "πŸ“˜", "huggingface": "πŸ€—", "github": "πŸ’»", "linkedin": "πŸ”—"}.get(field, "")
        cached_data['social'][field] = st.text_input(f"{emoji} {field.capitalize()}", value=cached_data['social'].get(field, ''))

    # Save data when changes are made
    if st.button("Save Data"):
        save_user_data(new_email, {'email': new_email, 'phone': new_phone, 'password': new_password, 'social': cached_data['social']})
        st.sidebar.success("Data updated and saved!")

    # Download link for user data file
    if selected_user and selected_user != 'New User':
        st.sidebar.markdown(get_file_download_link(f"{selected_user}.txt"), unsafe_allow_html=True)

    # File uploader
    uploaded_file = st.sidebar.file_uploader("πŸ“€ Upload User File", type='txt')
    if uploaded_file is not None:
        uploaded_data = json.loads(uploaded_file.getvalue().decode())
        save_user_data(uploaded_data['email'], uploaded_data)
        st.sidebar.success("Uploaded and saved!")

    # Display current data without password
    display_data = cached_data.copy()
    display_data['password'] = '*****'  # Hide the password
    st.write("Current Data:")
    st.json(display_data)

    # Display social media links
    display_social_links(cached_data['social'])

    # Password Reset Simulation
    if st.sidebar.button("Reset Password"):
        reset_email = st.sidebar.text_input("Enter email for password reset")
        if reset_email and reset_email in saved_users:
            reset_data = load_user_data(reset_email)
            reset_data['password'] = 'new_password'  # Reset password
            save_user_data(reset_email, reset_data)
            st.sidebar.success(f"Password reset for {reset_email}")

# Run the app
if __name__ == "__main__":
    main()
ChatGPT
To create a Python Streamlit application that demonstrates simple convolution operations in PyTorch and uses text files as input for NLP tasks, we'll integrate several components:

Streamlit UI: The interface where users interact with the application.
File Management: To load, save, and manage user-specific text files based on their email addresses.
PyTorch Convolution Demonstration: A simple demonstration of convolution operations to find correlations between words.
NLP Processing: Using NLTK and other NLP libraries to analyze the text data.
External References: Links to relevant documentation for learning purposes.
The application will allow users to upload their text files, perform NLP tasks on these files using NLTK, and demonstrate simple convolution operations in PyTorch to show relationships between words. Additionally, users can save their data and retrieve it later using their email address.

Here is the full Python Streamlit code for the described application: