Spaces:
Sleeping
Sleeping
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}") | |