File size: 2,756 Bytes
cfc20b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import datetime
import requests

# ========================
# CONFIG
# ========================
st.set_page_config(page_title="πŸŽ‚ Birthday Reminder AI", layout="wide")

# ========================
# Function to Get AI Response from Groq
# ========================
def get_ai_response(prompt):
    url = "https://api.groq.com/openai/v1/chat/completions"
    headers = {
        "Authorization": "Bearer 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",  # Replace with your actual Groq API key
        "Content-Type": "application/json"
    }
    payload = {
        "model": "llama3-70b-8192",  # You can try "llama3-8b-8192" for smaller model
        "messages": [
            {"role": "system", "content": "You are a helpful assistant for birthday ideas, gift suggestions, and messages."},
            {"role": "user", "content": prompt}
        ],
        "temperature": 0.7
    }

    try:
        response = requests.post(url, headers=headers, json=payload)
        result = response.json()
        return result["choices"][0]["message"]["content"]
    except Exception as e:
        return f"⚠️ Error getting response: {e}"

# ========================
# Birthday Input Section
# ========================
st.title("πŸŽ‰ Birthday Reminder + AI Assistant")

st.markdown("Add birthdays of your loved ones and get AI help with gift ideas or messages!")

# Sidebar to add birthdays
with st.sidebar:
    st.header("Add a Birthday πŸŽ‚")
    name = st.text_input("Name")
    bday = st.date_input("Birthday")

    if st.button("Save Birthday"):
        if "birthdays" not in st.session_state:
            st.session_state.birthdays = []
        st.session_state.birthdays.append((name, bday))
        st.success(f"Saved birthday for {name}!")

# ========================
# Display Upcoming Birthdays
# ========================
st.subheader("πŸ“… Upcoming Birthdays")

if "birthdays" in st.session_state and st.session_state.birthdays:
    today = datetime.date.today()
    upcoming = [entry for entry in st.session_state.birthdays if entry[1] >= today]
    upcoming.sort(key=lambda x: x[1])

    if upcoming:
        for name, date in upcoming:
            st.write(f"🎈 **{name}**: {date.strftime('%B %d')}")
    else:
        st.info("No upcoming birthdays.")
else:
    st.info("No birthdays saved yet!")

# ========================
# AI Assistant Section
# ========================
with st.expander("πŸ’¬ AI Assistant (powered by LLaMA via Groq)", expanded=False):
    st.markdown("Ask the AI for birthday wishes, gift suggestions, or party ideas!")

    user_input = st.text_input("You:", key="user_input")
    if user_input:
        response = get_ai_response(user_input)
        st.markdown(f"**AI:** {response}")