File size: 13,298 Bytes
d2433e1
 
 
 
 
a303d1a
d2433e1
3a6134f
31e5e99
 
 
 
 
b1cb4d9
31e5e99
 
 
 
 
b1cb4d9
31e5e99
 
1db2277
3a6134f
a35d7d7
 
31e5e99
a35d7d7
 
 
3a6134f
a35d7d7
 
 
3a6134f
a35d7d7
 
 
3a6134f
 
5ae614b
a303d1a
 
 
 
 
d2433e1
a303d1a
 
6f0ce48
 
a303d1a
 
 
 
 
 
 
 
 
d2433e1
 
 
a303d1a
 
 
 
d2433e1
a303d1a
 
 
 
 
 
 
 
 
 
 
d2433e1
a303d1a
 
 
 
 
d2433e1
3a6134f
a303d1a
 
 
 
 
 
 
 
 
6f0ce48
a303d1a
 
d2433e1
a303d1a
 
 
 
 
 
 
 
d2433e1
a303d1a
 
 
 
 
 
 
 
 
d2433e1
a303d1a
 
 
 
 
6f0ce48
a303d1a
 
 
 
 
 
d2433e1
6f0ce48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1db2277
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b084f9
1db2277
6325e52
 
 
 
 
7a9a7a5
 
 
 
 
 
6325e52
7a9a7a5
 
 
c770b63
 
 
6325e52
c770b63
 
6325e52
 
7a9a7a5
 
 
6325e52
 
 
 
 
 
 
 
 
 
 
 
 
 
c770b63
 
 
6325e52
c770b63
 
6325e52
 
 
7a9a7a5
 
6325e52
 
 
 
 
 
 
 
c770b63
6325e52
 
 
c770b63
 
 
6325e52
c770b63
 
6325e52
 
 
7a9a7a5
 
6325e52
 
 
 
 
 
 
 
 
 
 
 
 
 
c770b63
 
 
6325e52
c770b63
 
6325e52
 
 
1db2277
3a6134f
 
 
 
2336c3f
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
import streamlit as st
import datetime
import json
import requests
import os
from streamlit_option_menu import option_menu  # For better navigation

# OpenAI API Configuration
TimeCapsuleGroq = os.getenv("TimeCapsuleGroq")  # Set this in Hugging Face Secrets
TimeCapsuleGroq = "https://api.openai.com/v1/chat/completions"
'curl https://api.groq.com/openai/v1/chat/completions -s \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GROQ_API_KEY" \
-d '{
"model": "llama-3.3-70b-versatile",
"messages": [{
    "role": "user",
    "content": "Explain the importance of fast language models"
}]
}



# Function to call OpenAI API
def generate_time_capsule_content(prompt):
    headers = {
        "Authorization": f"Bearer {TimeCapsuleGroq}",
        "Content-Type": "application/json",
    }
    data = {
        "model": "gpt-3.5-turbo",  # Use GPT-3.5 or GPT-4
        "messages": [{"role": "user", "content": prompt}],
        "max_tokens": 500,
    }
    response = requests.post(OPENAI_API_URL, headers=headers, json=data)
    if response.status_code == 200:
        return response.json()["choices"][0]["message"]["content"]
    else:
        st.error(f"๐Ÿšจ Error calling OpenAI API: {response.status_code} - {response.text}")
        return None

# Initialize session state for capsules
if "capsules" not in st.session_state:
    st.session_state.capsules = []

# Navigation Menu
with st.sidebar:
    selected_tab = option_menu(
        menu_title="Main Menu",
        options=["Create Capsule", "My Capsules", "Unbox Capsule", "Share"],
        icons=["capsule", "archive", "gift", "share"],
        default_index=0,
    )

# Tab 1: Create Capsule
if selected_tab == "Create Capsule":
    st.header("๐Ÿ“ฆ Create Your Time Capsule")
    st.write("Tell us about your life, dreams, and thoughts. The AI will create a unique time capsule for you.")

    # User Input Fields
    name = st.text_input("Your Name", placeholder="John Doe")
    email = st.text_input("Your Email (for future delivery)", placeholder="john.doe@example.com")
    capsule_date = st.date_input("When should we deliver your time capsule?", min_value=datetime.date.today())
    theme = st.selectbox("Choose a Theme", ["Nostalgic", "Futuristic", "Inspirational", "Adventurous"])
    current_life = st.text_area("What's happening in your life right now?", placeholder="I'm currently studying computer science and dreaming of starting my own startup...")
    goals = st.text_area("What are your goals and dreams?", placeholder="I want to build a successful AI startup and travel the world...")
    thoughts = st.text_area("What's on your mind?", placeholder="I feel a bit overwhelmed but excited about the future...")

    # Generate Time Capsule
    if st.button("Create Time Capsule"):
        if name and email and current_life and goals and thoughts:
            with st.spinner("๐Ÿช„ Creating your time capsule..."):
                # Combine user input into a single prompt
                prompt = f"""
                Name: {name}
                Current Life: {current_life}
                Goals: {goals}
                Thoughts: {thoughts}
                Theme: {theme}

                Generate:
                1. A reflective summary of this person's current state.
                2. Fun predictions about their future.
                3. A heartfelt letter from their past self to their future self.
                """

                # Call OpenAI API to generate the time capsule content
                capsule_content = generate_time_capsule_content(prompt)
                if capsule_content:
                    # Save the time capsule to session state
                    capsule_data = {
                        "name": name,
                        "email": email,
                        "delivery_date": capsule_date.strftime("%Y-%m-%d"),
                        "theme": theme,
                        "content": capsule_content,
                        "created_at": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
                    }
                    st.session_state.capsules.append(capsule_data)

                    # Display the time capsule content
                    st.success("๐ŸŽ‰ Your time capsule is ready!")
                    st.subheader("โœจ Reflective Summary")
                    st.write(capsule_content.split("1. ")[1].split("2. ")[0].strip())
                    st.subheader("๐Ÿ”ฎ Future Predictions")
                    st.write(capsule_content.split("2. ")[1].split("3. ")[0].strip())
                    st.subheader("๐Ÿ’Œ Letter from Your Past Self")
                    st.write(capsule_content.split("3. ")[1].strip())

                    # Option to download the time capsule
                    st.download_button(
                        label="Download Your Time Capsule",
                        data=json.dumps(capsule_data, indent=2),
                        file_name=f"time_capsule_{name.replace(' ', '_')}.json",
                        mime="application/json",
                    )
        else:
            st.warning("Please fill in all fields and click 'Create Time Capsule'.")

# Tab 2: My Capsules
elif selected_tab == "My Capsules":
    st.header("๐Ÿ“š My Time Capsules")
    if st.session_state.capsules:
        for i, capsule in enumerate(st.session_state.capsules):
            with st.expander(f"Capsule {i+1}: {capsule['name']} - {capsule['delivery_date']}", expanded=False):
                st.write(f"**Theme:** {capsule['theme']}")
                st.write(f"**Reflective Summary:** {capsule['content'].split('1. ')[1].split('2. ')[0].strip()}")
                st.write(f"**Future Predictions:** {capsule['content'].split('2. ')[1].split('3. ')[0].strip()}")
                st.write(f"**Letter from Your Past Self:** {capsule['content'].split('3. ')[1].strip()}")
    else:
        st.info("You haven't created any time capsules yet. Go to the 'Create Capsule' tab to get started!")

# Tab 3: Unbox Capsule
elif selected_tab == "Unbox Capsule":
    st.header("๐ŸŽ Unbox Your Time Capsule")
    if st.session_state.capsules:
        selected_capsule = st.selectbox("Select a Capsule to Unbox", [capsule["name"] for capsule in st.session_state.capsules])
        capsule_index = [capsule["name"] for capsule in st.session_state.capsules].index(selected_capsule)
        capsule = st.session_state.capsules[capsule_index]

        st.write(f"Unboxing Capsule: **{capsule['name']}**")
        st.write(f"**Theme:** {capsule['theme']}")
        st.write(f"**Reflective Summary:** {capsule['content'].split('1. ')[1].split('2. ')[0].strip()}")
        st.write(f"**Future Predictions:** {capsule['content'].split('2. ')[1].split('3. ')[0].strip()}")
        st.write(f"**Letter from Your Past Self:** {capsule['content'].split('3. ')[1].strip()}")

        # Interactive Unboxing: Generate a new reflection
        if st.button("Generate New Reflection"):
            with st.spinner("๐Ÿช„ Generating a new reflection..."):
                prompt = f"""
                Past Reflection:
                {capsule['content'].split('1. ')[1].split('2. ')[0].strip()}

                Current Life:
                {st.session_state.get("current_life", "No current life details available.")}

                Generate:
                1. A comparison of the user's past and present.
                2. Insights on how the user has grown or changed.
                """
                new_reflection = generate_time_capsule_content(prompt)
                if new_reflection:
                    st.success("๐ŸŽ‰ New reflection generated!")
                    st.subheader("โœจ Past vs. Present Comparison")
                    st.write(new_reflection.split("1. ")[1].split("2. ")[0].strip())
                    st.subheader("๐Ÿ”ฎ Insights on Growth")
                    st.write(new_reflection.split("2. ")[1].strip())
    else:
        st.info("You haven't created any time capsules yet. Go to the 'Create Capsule' tab to get started!")

# Tab 4: Share
elif selected_tab == "Share":
    st.header("๐Ÿ“ค Share Your Time Capsule")
    if st.session_state.capsules:
        selected_capsule = st.selectbox("Select a Capsule to Share", [capsule["name"] for capsule in st.session_state.capsules])
        capsule_index = [capsule["name"] for capsule in st.session_state.capsules].index(selected_capsule)
        capsule = st.session_state.capsules[capsule_index]

        st.write(f"Sharing Capsule: **{capsule['name']}**")
        st.write(f"**Theme:** {capsule['theme']}")
        st.write(f"**Reflective Summary:** {capsule['content'].split('1. ')[1].split('2. ')[0].strip()}")
        st.write(f"**Future Predictions:** {capsule['content'].split('2. ')[1].split('3. ')[0].strip()}")
        st.write(f"**Letter from Your Past Self:** {capsule['content'].split('3. ')[1].strip()}")

        # Social Media Sharing Options
        st.subheader("Share on Social Media")
        share_text = f"Check out my Time Capsule: {capsule['name']} - {capsule['content'].split('1. ')[1].split('2. ')[0].strip()}"
        share_url = "https://huggingface.co/spaces/AamirMalik/Time_Capsule"  # Replace with your app's URL

        # Facebook Button
        facebook_url = f"https://www.facebook.com/sharer/sharer.php?u={share_url}"
        st.markdown(f"""
        <a href="{facebook_url}" target="_blank">
            <button style="
                width: 100%;
                margin: 10px 0;
                padding: 15px;
                font-size: 16px;
                border-radius: 8px;
                border: none;
                background-color: #1877F2;
                color: white;
                cursor: pointer;
                transition: all 0.3s;
                display: flex;
                align-items: center;
                justify-content: center;
            ">
                <img src="https://upload.wikimedia.org/wikipedia/commons/5/51/Facebook_f_logo_%282019%29.svg" alt="Facebook" style="width: 20px; height: 20px; margin-right: 10px;">
                Share on Facebook
            </button>
        </a>
        """, unsafe_allow_html=True)

        # WhatsApp Button
        whatsapp_url = f"https://wa.me/?text={share_text} {share_url}"
        st.markdown(f"""
        <a href="{whatsapp_url}" target="_blank">
            <button style="
                width: 100%;
                margin: 10px 0;
                padding: 15px;
                font-size: 16px;
                border-radius: 8px;
                border: none;
                background-color: #25D366;
                color: white;
                cursor: pointer;
                transition: all 0.3s;
                display: flex;
                align-items: center;
                justify-content: center;
            ">
                <img src="https://upload.wikimedia.org/wikipedia/commons/6/6b/WhatsApp.svg" alt="WhatsApp" style="width: 20px; height: 20px; margin-right: 10px;">
                Share on WhatsApp
            </button>
        </a>
        """, unsafe_allow_html=True)

        # Instagram Button
        st.markdown(f"""
        <button style="
            width: 100%;
            margin: 10px 0;
            padding: 15px;
            font-size: 16px;
            border-radius: 8px;
            border: none;
            background: linear-gradient(45deg, #405DE6, #5851DB, #833AB4, #C13584, #E1306C, #FD1D1D, #F56040, #F77737, #FCAF45, #FFDC80);
            color: white;
            cursor: pointer;
            transition: all 0.3s;
            display: flex;
            align-items: center;
            justify-content: center;
        " onclick="navigator.clipboard.writeText('{share_url}')">
            <img src="https://upload.wikimedia.org/wikipedia/commons/e/e7/Instagram_logo_2016.svg" alt="Instagram" style="width: 20px; height: 20px; margin-right: 10px;">
            Copy Instagram Link
        </button>
        """, unsafe_allow_html=True)
        st.caption("Paste this link in your Instagram bio or story.")

        # LinkedIn Button
        linkedin_url = f"https://www.linkedin.com/sharing/share-offsite/?url={share_url}"
        st.markdown(f"""
        <a href="{linkedin_url}" target="_blank">
            <button style="
                width: 100%;
                margin: 10px 0;
                padding: 15px;
                font-size: 16px;
                border-radius: 8px;
                border: none;
                background-color: #0A66C2;
                color: white;
                cursor: pointer;
                transition: all 0.3s;
                display: flex;
                align-items: center;
                justify-content: center;
            ">
                <img src="https://upload.wikimedia.org/wikipedia/commons/c/ca/LinkedIn_logo_initials.png" alt="LinkedIn" style="width: 20px; height: 20px; margin-right: 10px;">
                Share on LinkedIn
            </button>
        </a>
        """, unsafe_allow_html=True)
    else:
        st.info("You haven't created any time capsules yet. Go to the 'Create Capsule' tab to get started!")

# Footer
st.markdown("---")
st.markdown("Built with โค๏ธ using [DeepSeek](https://deepseek.com/.com) / [OpenAI](https://openai.com) and [Streamlit](https://streamlit.io).")