Spaces:
Sleeping
Sleeping
File size: 3,362 Bytes
81379ec bd3a27a 81379ec bd3a27a 81379ec bd3a27a 81379ec bd3a27a 81379ec bd3a27a 81379ec bd3a27a 81379ec bd3a27a 81379ec bd3a27a 81379ec bd3a27a |
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 |
import streamlit as st
from textblob import TextBlob
# The transformers import is here in case you want to integrate a pre-trained model later.
# from transformers import pipeline
def get_roast(user_text):
"""
Generates a roast based on the user's input.
(You can replace or extend this logic by integrating a model like Mixtral-8x7B.)
"""
if "procrastinate" in user_text.lower():
return "Ah, the art of doing nothing! Do you charge Netflix for your couch imprint? 🛋️"
elif "always" in user_text.lower() or "never" in user_text.lower():
return "Wow, painting your world in extremes? Maybe it's time to add some shades of gray!"
else:
return "Is that a problem or a lifestyle choice? Time to get serious... or maybe not."
def analyze_text(user_text):
"""
Analyzes the input text for sentiment and detects basic cognitive distortions.
For now, it counts occurrences of words like 'always' or 'never'.
"""
blob = TextBlob(user_text)
sentiment = blob.sentiment.polarity # Ranges from -1 (negative) to 1 (positive)
distortions = sum(word in user_text.lower() for word in ["always", "never"])
return sentiment, distortions
def calculate_resilience_score(sentiment, distortions):
"""
Calculates a resilience score based on sentiment and the number of detected distortions.
The score is capped between 0 and 100.
"""
score = 100
# Adjust score by sentiment (scaled)
score += int(sentiment * 20)
# Penalize for cognitive distortions
score -= distortions * 10
# Ensure score stays within bounds
score = max(0, min(score, 100))
return score
def get_reframe_tips(score):
"""
Provides reframe tips based on the resilience score.
"""
if score < 50:
return "Remember: small steps lead to big changes. Try breaking tasks into manageable chunks and celebrate every little victory!"
elif score < 75:
return "You're on your way! Consider setting specific goals and challenge those negative thoughts with evidence."
else:
return "Keep up the great work! Your resilience is inspiring – maybe share some of that energy with someone who needs it!"
def main():
st.title("🤖 Roast Master Therapist Bot")
st.write("Share your problem, and let the roast and resilience tips begin!")
# User input
user_input = st.text_area("What's troubling you?", placeholder="e.g., I procrastinate on everything...")
if st.button("Get Roast and Tips"):
if user_input.strip():
# Generate roast response
roast = get_roast(user_input)
st.markdown("### Roast:")
st.write(roast)
# Analyze user input
sentiment, distortions = analyze_text(user_input)
resilience_score = calculate_resilience_score(sentiment, distortions)
tips = get_reframe_tips(resilience_score)
# Display analysis and tips
st.markdown("### Resilience Analysis:")
st.write(f"**Resilience Score:** {resilience_score}/100")
st.write(tips)
# Fun Streamlit animation!
st.balloons()
else:
st.warning("Please share something so we can get roasting!")
if __name__ == '__main__':
main()
|