Spaces:
Sleeping
Sleeping
| import openai | |
| import gradio as gr | |
| import random | |
| # entering the OpenAI API key | |
| openai.apikey = "your-open-ai-key" | |
| # block 1: Emotional Check-In Function | |
| def emotional_check_in(happy, anxious, excited, sad, hungry, tired, lonely, bored, overwhelmed, explanation): | |
| prompt = f"Today I am feeling: Happy: {happy}, Anxious: {anxious}, Excited: {excited}, Sad: {sad}, Hungry: {hungry}, Tired: {tired}, Lonely: {lonely}, Bored: {bored}, Overwhelmed: {overwhelmed}. Explanation: '{explanation}'. Provide a supportive response." | |
| response = openai.Completion.create( | |
| model='text-davinci-003', | |
| prompt=prompt, | |
| max_tokens=300 | |
| ) | |
| return response.choices[0].text | |
| # block 2: Mental Health Post Advice Function | |
| def mental_health_advice(post_input): | |
| prompt = f"Provide some positive encouragement or advice for this mental health-related post: {post_input}" | |
| response = openai.Completion.create( | |
| model='text-davinci-003', | |
| prompt=prompt, | |
| max_tokens=300 | |
| ) | |
| return response.choices[0].text | |
| # block 3: Social Media Posts for Wellness Function | |
| def wellness_posts(): | |
| posts = [ | |
| "Remember, reaching out for help is a sign of strength, not weakness. It's okay to ask for support. You're not alone. MentalHealthMatters #EndTheStigma", | |
| "Take a moment for yourself today. Whether it's a walk in nature, a warm bath, or just a few deep breaths, prioritize self-care. Your well-being matters.", | |
| "Mental health is a journey, not a destination. Let's support each other on this path. #RealTalk #MentalHealthJourney", | |
| "You are strong. You are resilient. You are enough. Don't forget to be kind to yourself. #PositiveVibes #YouMatter", | |
| "Practice mindfulness today. Take a moment to focus on your breath, be present in the now. It can make a world of difference. #Mindfulness", | |
| "Did you know that taking breaks during work can boost productivity and reduce stress? Remember to give yourself time to recharge. #WorkLifeBalance #MentalHealthTip", | |
| "Our community is here for you. If you're struggling, feel free to share or reach out. Together, we can create a space of understanding and support. ", | |
| "Gratitude can shift your focus from what's lacking to what you have. Today, I'm grateful for the small moments of joy. What are you thankful for? ", | |
| "When things get tough, try focusing on what you can control. Break big tasks into smaller ones and take it one step at a time. #CopingSkills #MentalHealthAwareness", | |
| "Let's break the silence around mental health. Share your thoughts, experiences, or resources that have helped you. Together, we can create a supportive dialogue."] | |
| return random.choice(posts) | |
| with gr.Blocks() as suidetect: | |
| with gr.Tab("Emotional Check-In"): | |
| with gr.Row(): | |
| with gr.Column(): | |
| happy = gr.Radio(choices=[1, 2, 3, 4, 5, 6, 7], label="Happy (1=Low, 7=High)") | |
| anxious = gr.Radio(choices=[1, 2, 3, 4, 5, 6, 7], label="Anxious (1=Low, 7=High)") | |
| excited = gr.Radio(choices=[1, 2, 3, 4, 5, 6, 7], label="Excited (1=Low, 7=High)") | |
| sad = gr.Radio(choices=[1, 2, 3, 4, 5, 6, 7], label="Sad (1=Low, 7=High)") | |
| hungry = gr.Radio(choices=[1, 2, 3, 4, 5, 6, 7], label="Hungry (1=Low, 7=High)") | |
| tired = gr.Radio(choices=[1, 2, 3, 4, 5, 6, 7], label="Tired (1=Low, 7=High)") | |
| lonely = gr.Radio(choices=[1, 2, 3, 4, 5, 6, 7], label="Lonely (1=Low, 7=High)") | |
| bored = gr.Radio(choices=[1, 2, 3, 4, 5, 6, 7], label="Bored (1=Low, 7=High)") | |
| overwhelmed = gr.Radio(choices=[1, 2, 3, 4, 5, 6, 7], label="Overwhelmed (1=Low, 7=High)") | |
| explanation = gr.Textbox(label="Why do you feel this way?", | |
| placeholder="Example 1: 'I'm super excited because I just found out I'm going on a surprise trip this weekend!' Example 2: 'Feeling a bit down today because I had a disagreement with a close friend.' Example 3: 'Long day at work, and now I'm just exhausted. Ready for a good night's sleep.'") | |
| check_in_btn = gr.Button("Let's Generate Some Supportive Responses") | |
| with gr.Column(): | |
| check_in_output = gr.Textbox(label="Supportive Response", lines=10) | |
| check_in_btn.click( | |
| emotional_check_in, | |
| inputs=[happy, anxious, excited, sad, hungry, tired, lonely, bored, overwhelmed, explanation], | |
| outputs=check_in_output | |
| ) | |
| with gr.Tabs(): | |
| with gr.Tab("Example 1"): | |
| gr.Markdown("I'm super excited because I just found out I'm going on a surprise trip this weekend!") | |
| with gr.Tab("Example 2"): | |
| gr.Markdown("Feeling a bit down today because I had a disagreement with a close friend.") | |
| with gr.Tab("Example 3"): | |
| gr.Markdown("Long day at work, and now I'm just exhausted. Ready for a good night's sleep.") | |
| with gr.Tab("Mental Health Post Advice"): | |
| with gr.Row(): | |
| with gr.Column(): | |
| post_input = gr.Textbox(label="Share a Mental-Health Related Post", placeholder="Example 1: 'Feeling a knot in my stomach that just won't go away. Anxiety is tough #AnxietyStruggles' Example 2: 'Today feels heavy, and the world seems a bit gray. Depression is a tough companion. Trying to take it one moment at a time. #DepressionFeels #OneStepAtATime' Example 3: 'Feeling overwhelmed with the responsibilities piling up. It's hard to find a balance, and the stress is taking a toll. #Overwhelmed #BalancingAct'") | |
| advice_btn = gr.Button("Generate Advice") | |
| with gr.Column(): | |
| advice_output = gr.Textbox(label="Advice", lines=10) | |
| advice_btn.click( | |
| mental_health_advice, | |
| inputs=post_input, | |
| outputs=advice_output | |
| ) | |
| with gr.Tabs(): | |
| with gr.Tab("Example 1"): | |
| gr.Markdown("Feeling a knot in my stomach that just won't go away. Anxiety is tough #AnxietyStruggles") | |
| with gr.Tab("Example 2"): | |
| gr.Markdown("Today feels heavy, and the world seems a bit gray. Depression is a tough companion. Trying to take it one moment at a time. #DepressionFeels #OneStepAtATime") | |
| with gr.Tab("Example 3"): | |
| gr.Markdown("Feeling overwhelmed with the responsibilities piling up. It's hard to find a balance, and the stress is taking a toll. #Overwhelmed #BalancingAct") | |
| with gr.Tab("Wellness Posts"): | |
| with gr.Row(): | |
| with gr.Column(): | |
| wellness_btn = gr.Button("Show Me Some Wellness Posts") | |
| with gr.Column(): | |
| wellness_output = gr.Textbox(label="Wellness Posts", lines=10) | |
| wellness_btn.click( | |
| wellness_posts, | |
| outputs=wellness_output | |
| ) | |
| # Launch the Gradio interface | |
| suidetect.launch(share=True) | |