sunbal7's picture
Update app.py
7077f97 verified
raw
history blame
4.41 kB
# app.py
import streamlit as st
from groq import Groq
from textblob import TextBlob
import re
import time
# Initialize Groq client
client = Groq(api_key=st.secrets["GROQ_API_KEY"])
# Configure Streamlit
st.set_page_config(page_title="🀣 Roast Master Therapist", layout="wide")
# Custom CSS for animations
st.markdown("""
<style>
@keyframes laugh {
0% { transform: scale(1); }
50% { transform: scale(1.2); }
100% { transform: scale(1); }
}
.laugh-emoji {
animation: laugh 0.5s ease-in-out infinite;
font-size: 3em;
text-align: center;
}
.progress-bar {
height: 20px;
border-radius: 10px;
background: #ff4b4b;
transition: width 0.5s ease-in-out;
}
</style>
""", unsafe_allow_html=True)
def analyze_cbt(text):
"""Analyze text for cognitive distortions using CBT principles"""
analysis = {
'absolutes': len(re.findall(r'\b(always|never|everyone|nobody)\b', text, re.I)),
'negative_words': TextBlob(text).sentiment.polarity,
'resilience_score': 100 # Start with perfect score
}
# Deduct points for cognitive distortions
analysis['resilience_score'] -= analysis['absolutes'] * 5
analysis['resilience_score'] = max(analysis['resilience_score'], 0)
return analysis
def generate_roast(prompt):
"""Generate a humorous roast using Groq/Mixtral"""
system_prompt = """You are a sarcastic therapist who roasts bad habits in a funny way.
Respond with 1-2 short sentences including emojis. Example: "Ah, the art of doing nothing!
Do you charge Netflix for your couch imprint? πŸ›‹οΈ" """
response = client.chat.completions.create(
model="mixtral-8x7b-32768",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": prompt}
],
temperature=0.9,
max_tokens=100
)
return response.choices[0].message.content
def get_cbt_tips(analysis):
"""Generate personalized CBT tips"""
tips = []
if analysis['absolutes'] > 0:
tips.append("πŸ” Notice absolute words like 'always/never' - reality is usually more nuanced!")
if analysis['negative_words'] < -0.2:
tips.append("🌈 Try reframing negative statements: 'I sometimes...' instead of 'I never...'")
if analysis['resilience_score'] < 70:
tips.append("πŸ’ͺ Practice thought challenging: 'Is this truly catastrophic or just inconvenient?'")
return tips
# Main app interface
st.title("🀣 Roast Master Therapist")
st.markdown("### Your hilarious path to emotional resilience!")
user_input = st.text_input("Share your problem or bad habit:",
placeholder="e.g., 'I always procrastinate...'")
if user_input:
with st.spinner("Consulting the comedy gods..."):
# Show laughing animation
st.markdown('<div class="laugh-emoji">πŸ˜‚</div>', unsafe_allow_html=True)
time.sleep(1.5)
# Generate and display roast
roast = generate_roast(user_input)
st.subheader("πŸ”₯ Your Roast:")
st.write(roast)
# Analyze and show results
analysis = analyze_cbt(user_input)
st.divider()
# Resilience score visualization
st.subheader("🧠 Resilience Analysis")
score = analysis['resilience_score']
st.markdown(f"""
<div style="background: #f0f2f6; border-radius: 10px; padding: 10px;">
<div class="progress-bar" style="width: {score}%;"></div>
</div>
<br>Current Resilience Score: {score}/100
""", unsafe_allow_html=True)
# Display CBT tips
st.subheader("πŸ’‘ Growth Tips")
for tip in get_cbt_tips(analysis):
st.markdown(f"- {tip}")
# Add disclaimer
st.divider()
st.caption("Disclaimer: This is not real therapy - it's therapy with jokes! Always consult a professional for serious concerns.")
# Sidebar information
with st.sidebar:
st.header("How It Works")
st.markdown("""
1. Share your bad habit/problem
2. Get hilariously roasted 🀣
3. Receive psychological insights
4. Get personalized growth tips
**Psychological Basis:**
- Cognitive Behavioral Therapy (CBT)
- Humor as emotional distancing
- Positive reframing techniques
""")
st.image("https://i.imgur.com/7Q4X4yN.png", width=200)