Download app.py from Syeda2026/chatbot: direct link, hf CLI and curl.
- Browser
- Download file 3.79 kB
-
https://huggingface.co/spaces/Syeda2026/chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/Syeda2026/chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Syeda2026/chatbot/resolve/main/app.py
3.79 kB
| import gradio as gr | |
| # 🧠 Responses (UNCHANGED) | |
| responses = { | |
| "exam": "Stay calm and focus on what you can still do. Even if time was wasted before, the present moment is still in your control. Prioritize important topics and revise smartly. Small focused effort can still make a difference.", | |
| "quarrel": "Conflicts happen when we try to control others or expect agreement. Every person has their own perspective. Try to understand their point of view and communicate calmly. Most issues can be solved through patience and conversation.", | |
| "fight": "Fights with friends or family usually come from misunderstandings. Take a step back before reacting. Talk calmly and try to understand each other instead of winning the argument. Relationships matter more than arguments.", | |
| "understand": "If someone doesn’t understand you, it doesn’t mean you are wrong. Trust yourself. Self-belief is more important than approval from others. Misunderstandings are part of life.", | |
| "useless": "You are not useless. You have potential and purpose. Sometimes we feel lost, but that does not define your value. You can build a meaningful life step by step.", | |
| "overthinking": "Instead of repeating thoughts, try to solve them. Identify triggers and ask yourself if this matters in the long term. Write it down and focus only on what you can control.", | |
| "night": "Overthinking at night is common. Try deep breathing, avoid phone use, and relax your mind. Not every thought needs attention.", | |
| "bore": """Boredom is normal. You can use it productively: | |
| - Read a book 📚 | |
| - Play sports ⚽ | |
| - Learn a skill 🎯 | |
| - Solve puzzles 🧩 | |
| - Try something creative 🌱""", | |
| "confidence": "Confidence comes from self-belief. People may judge, but they forget quickly. Focus on your growth instead of others' opinions. Do your best and trust yourself.", | |
| "dont know": "It's okay to be confused. Think about outcomes before deciding. Once you choose, stay strong and avoid regret. Every decision teaches something.", | |
| "time": """Try Pomodoro technique: | |
| - 25 min work | |
| - 5 min break | |
| Repeat 4 times, then take a longer break. It improves focus and reduces stress.""", | |
| "workload": "Write all tasks on paper. Break them into small steps. Start with easy tasks first. Don’t try to do everything at once—progress step by step.", | |
| "purpose": "Purpose gives direction to life. Ask yourself why you are doing something. Even small goals can build a meaningful path over time.", | |
| "happy": "I'm really glad you're happy 😊. Life should be lived with gratitude and positivity. Try to spread that positivity to others.", | |
| "sad": "It's okay to feel sad. Life has ups and downs, and no situation lasts forever. Things will change with time. Be patient with yourself.", | |
| "anxious": "When you feel anxious, slow down and focus on breathing. Write your thoughts and understand what is causing them. You are safe in this moment." | |
| } | |
| def get_response(text): | |
| text = text.lower() | |
| for key in responses: | |
| if key in text: | |
| return responses[key] | |
| return "Please use one of the suggested keywords 💙" | |
| # 💬 SIMPLE SAFE CHAT FUNCTION (NO ROLE FORMAT) | |
| def chat(message, history): | |
| reply = get_response(message) | |
| history = history + [(message, reply)] | |
| return "", history | |
| # 🎨 UI | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Mental Health Assistant 💙") | |
| gr.Markdown(""" | |
| 👉 Keywords: | |
| exam, quarrel, fight, understand, useless, overthinking, night, bore, | |
| confidence, dont know, time, workload, purpose, happy, sad, anxious | |
| """) | |
| chatbot = gr.Chatbot() | |
| msg = gr.Textbox(placeholder="Type your message...") | |
| state = gr.State([]) | |
| msg.submit(chat, [msg, state], [msg, chatbot]) | |
| demo.launch() |