Gulzaib4 commited on
Commit
cfc20b2
Β·
verified Β·
1 Parent(s): aa872a7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -0
app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import datetime
3
+ import requests
4
+
5
+ # ========================
6
+ # CONFIG
7
+ # ========================
8
+ st.set_page_config(page_title="πŸŽ‚ Birthday Reminder AI", layout="wide")
9
+
10
+ # ========================
11
+ # Function to Get AI Response from Groq
12
+ # ========================
13
+ def get_ai_response(prompt):
14
+ url = "https://api.groq.com/openai/v1/chat/completions"
15
+ headers = {
16
+ "Authorization": "Bearer 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", # Replace with your actual Groq API key
17
+ "Content-Type": "application/json"
18
+ }
19
+ payload = {
20
+ "model": "llama3-70b-8192", # You can try "llama3-8b-8192" for smaller model
21
+ "messages": [
22
+ {"role": "system", "content": "You are a helpful assistant for birthday ideas, gift suggestions, and messages."},
23
+ {"role": "user", "content": prompt}
24
+ ],
25
+ "temperature": 0.7
26
+ }
27
+
28
+ try:
29
+ response = requests.post(url, headers=headers, json=payload)
30
+ result = response.json()
31
+ return result["choices"][0]["message"]["content"]
32
+ except Exception as e:
33
+ return f"⚠️ Error getting response: {e}"
34
+
35
+ # ========================
36
+ # Birthday Input Section
37
+ # ========================
38
+ st.title("πŸŽ‰ Birthday Reminder + AI Assistant")
39
+
40
+ st.markdown("Add birthdays of your loved ones and get AI help with gift ideas or messages!")
41
+
42
+ # Sidebar to add birthdays
43
+ with st.sidebar:
44
+ st.header("Add a Birthday πŸŽ‚")
45
+ name = st.text_input("Name")
46
+ bday = st.date_input("Birthday")
47
+
48
+ if st.button("Save Birthday"):
49
+ if "birthdays" not in st.session_state:
50
+ st.session_state.birthdays = []
51
+ st.session_state.birthdays.append((name, bday))
52
+ st.success(f"Saved birthday for {name}!")
53
+
54
+ # ========================
55
+ # Display Upcoming Birthdays
56
+ # ========================
57
+ st.subheader("πŸ“… Upcoming Birthdays")
58
+
59
+ if "birthdays" in st.session_state and st.session_state.birthdays:
60
+ today = datetime.date.today()
61
+ upcoming = [entry for entry in st.session_state.birthdays if entry[1] >= today]
62
+ upcoming.sort(key=lambda x: x[1])
63
+
64
+ if upcoming:
65
+ for name, date in upcoming:
66
+ st.write(f"🎈 **{name}**: {date.strftime('%B %d')}")
67
+ else:
68
+ st.info("No upcoming birthdays.")
69
+ else:
70
+ st.info("No birthdays saved yet!")
71
+
72
+ # ========================
73
+ # AI Assistant Section
74
+ # ========================
75
+ with st.expander("πŸ’¬ AI Assistant (powered by LLaMA via Groq)", expanded=False):
76
+ st.markdown("Ask the AI for birthday wishes, gift suggestions, or party ideas!")
77
+
78
+ user_input = st.text_input("You:", key="user_input")
79
+ if user_input:
80
+ response = get_ai_response(user_input)
81
+ st.markdown(f"**AI:** {response}")