File size: 4,405 Bytes
7077f97
81379ec
7077f97
bd3a27a
7077f97
 
81379ec
7077f97
 
81379ec
7077f97
 
81379ec
7077f97
 
 
 
 
 
 
 
81379ec
7077f97
 
 
 
 
81379ec
7077f97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81379ec
7077f97
 
 
81379ec
7077f97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd3a27a
7077f97
 
 
81379ec
7077f97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# 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)