Reflector_Ai / app.py
abdullahrehan's picture
Create app.py
7928d05 verified
import streamlit as st
import os
from groq import Groq
# Set up GROQ client using environment variable
if "GROQ_API_KEY" not in os.environ:
st.error("Please set your GROQ_API_KEY using st.secrets or os.environ in Colab.")
st.stop()
client = Groq(api_key=os.environ["GROQ_API_KEY"])
st.set_page_config(page_title="Reflector AI", page_icon="πŸͺž", layout="wide")
st.markdown("""
<style>
.main {
background: linear-gradient(to right, #0f2027, #203a43, #2c5364);
color: white;
}
.stTextInput > div > div > input {
background-color: #222;
color: white;
}
.stButton > button {
background-color: #FF4B2B;
color: white;
font-weight: bold;
}
.stMarkdown {
color: #f1f1f1;
}
</style>
""", unsafe_allow_html=True)
st.title("πŸͺž Reflector AI")
st.subheader("Chat with a reflection of yourself πŸ€–")
# Session states
if "step" not in st.session_state:
st.session_state.step = 1
if "personality_summary" not in st.session_state:
st.session_state.personality_summary = ""
if "chat_history" not in st.session_state:
st.session_state.chat_history = []
def groq_chat(prompt, history=[]):
messages = [{"role": "user", "content": prompt}]
for h in history:
messages.insert(0, h)
response = client.chat.completions.create(
messages=messages,
model="llama-3.3-70b-versatile"
)
return response.choices[0].message.content
if st.session_state.step == 1:
st.write("To personalize Reflector AI, answer a few quick questions.")
name = st.text_input("What's your name?")
vibe = st.selectbox("How would you describe your vibe?", ["Chill", "Funny", "Serious", "Curious", "Friendly"])
goal = st.text_input("What is your main goal in life?")
mood = st.select_slider("Current mood?", ["😒", "😐", "😊", "😎", "πŸ”₯"])
if st.button("Create My AI Reflection"):
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."
summary = groq_chat(prompt)
st.session_state.personality_summary = summary
st.session_state.step = 2
elif st.session_state.step == 2:
st.success("Your AI reflection is ready!")
st.markdown(f"**Reflector AI's personality summary:**\n\n*{st.session_state.personality_summary}*")
if st.button("Talk to Myself"):
st.session_state.step = 3
elif st.session_state.step == 3:
st.subheader("Ask anything β€” Reflector AI responds like You!")
user_input = st.text_input("You:", key="chat_input")
if st.button("Send"):
user_personality = st.session_state.personality_summary
full_prompt = f"Personality: {user_personality}\nYou are now this person. Respond in their tone.\nUser asked: {user_input}"
reply = groq_chat(full_prompt, st.session_state.chat_history)
st.session_state.chat_history.append({"role": "user", "content": user_input})
st.session_state.chat_history.append({"role": "assistant", "content": reply})
for i in reversed(st.session_state.chat_history[-10:]):
if i["role"] == "user":
st.markdown(f"**You**: {i['content']}")
else:
st.markdown(f"**Reflector AI**: {i['content']}")