abdullahrehan commited on
Commit
7928d05
Β·
verified Β·
1 Parent(s): 403abd6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -0
app.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from groq import Groq
4
+
5
+ # Set up GROQ client using environment variable
6
+ if "GROQ_API_KEY" not in os.environ:
7
+ st.error("Please set your GROQ_API_KEY using st.secrets or os.environ in Colab.")
8
+ st.stop()
9
+
10
+ client = Groq(api_key=os.environ["GROQ_API_KEY"])
11
+
12
+ st.set_page_config(page_title="Reflector AI", page_icon="πŸͺž", layout="wide")
13
+
14
+ st.markdown("""
15
+ <style>
16
+ .main {
17
+ background: linear-gradient(to right, #0f2027, #203a43, #2c5364);
18
+ color: white;
19
+ }
20
+ .stTextInput > div > div > input {
21
+ background-color: #222;
22
+ color: white;
23
+ }
24
+ .stButton > button {
25
+ background-color: #FF4B2B;
26
+ color: white;
27
+ font-weight: bold;
28
+ }
29
+ .stMarkdown {
30
+ color: #f1f1f1;
31
+ }
32
+ </style>
33
+ """, unsafe_allow_html=True)
34
+
35
+ st.title("πŸͺž Reflector AI")
36
+ st.subheader("Chat with a reflection of yourself πŸ€–")
37
+
38
+ # Session states
39
+ if "step" not in st.session_state:
40
+ st.session_state.step = 1
41
+ if "personality_summary" not in st.session_state:
42
+ st.session_state.personality_summary = ""
43
+ if "chat_history" not in st.session_state:
44
+ st.session_state.chat_history = []
45
+
46
+ def groq_chat(prompt, history=[]):
47
+ messages = [{"role": "user", "content": prompt}]
48
+ for h in history:
49
+ messages.insert(0, h)
50
+ response = client.chat.completions.create(
51
+ messages=messages,
52
+ model="llama-3.3-70b-versatile"
53
+ )
54
+ return response.choices[0].message.content
55
+
56
+ if st.session_state.step == 1:
57
+ st.write("To personalize Reflector AI, answer a few quick questions.")
58
+ name = st.text_input("What's your name?")
59
+ vibe = st.selectbox("How would you describe your vibe?", ["Chill", "Funny", "Serious", "Curious", "Friendly"])
60
+ goal = st.text_input("What is your main goal in life?")
61
+ mood = st.select_slider("Current mood?", ["😒", "😐", "😊", "😎", "πŸ”₯"])
62
+
63
+ if st.button("Create My AI Reflection"):
64
+ prompt = f"My name is {name}. My vibe is {vibe}. My main goal is: {goal}. My mood now is {mood}. Summarize this personality in one paragraph."
65
+ summary = groq_chat(prompt)
66
+ st.session_state.personality_summary = summary
67
+ st.session_state.step = 2
68
+
69
+ elif st.session_state.step == 2:
70
+ st.success("Your AI reflection is ready!")
71
+ st.markdown(f"**Reflector AI's personality summary:**\n\n*{st.session_state.personality_summary}*")
72
+ if st.button("Talk to Myself"):
73
+ st.session_state.step = 3
74
+
75
+ elif st.session_state.step == 3:
76
+ st.subheader("Ask anything β€” Reflector AI responds like You!")
77
+ user_input = st.text_input("You:", key="chat_input")
78
+ if st.button("Send"):
79
+ user_personality = st.session_state.personality_summary
80
+ full_prompt = f"Personality: {user_personality}\nYou are now this person. Respond in their tone.\nUser asked: {user_input}"
81
+ reply = groq_chat(full_prompt, st.session_state.chat_history)
82
+ st.session_state.chat_history.append({"role": "user", "content": user_input})
83
+ st.session_state.chat_history.append({"role": "assistant", "content": reply})
84
+
85
+ for i in reversed(st.session_state.chat_history[-10:]):
86
+ if i["role"] == "user":
87
+ st.markdown(f"**You**: {i['content']}")
88
+ else:
89
+ st.markdown(f"**Reflector AI**: {i['content']}")
90
+