Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import os | |
| from dotenv import load_dotenv | |
| import plotly.express as px | |
| from utils.text_analysis import analyze_text | |
| from utils.resources import get_resources, filter_resources | |
| # Load environment variables | |
| load_dotenv() | |
| # Page configuration | |
| st.set_page_config( | |
| page_title="MindGuard - Mental Health Support", | |
| page_icon="🛡️", | |
| layout="wide", | |
| initial_sidebar_state="expanded" | |
| ) | |
| # Custom CSS for better styling | |
| st.markdown(""" | |
| <style> | |
| .main-header { | |
| font-size: 2.5rem; | |
| color: #4f8bf9; | |
| margin-bottom: 1rem; | |
| } | |
| .sub-header { | |
| font-size: 1.5rem; | |
| color: #6c757d; | |
| margin-bottom: 1rem; | |
| } | |
| .disclaimer { | |
| background-color: #f8f9fa; | |
| padding: 1rem; | |
| border-radius: 0.5rem; | |
| margin: 1rem 0; | |
| border-left: 5px solid #4f8bf9; | |
| } | |
| .resource-card { | |
| background-color: #f8f9fa; | |
| padding: 1rem; | |
| border-radius: 0.5rem; | |
| margin-bottom: 1rem; | |
| border-left: 5px solid #28a745; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # App header | |
| st.markdown("<h1 class='main-header'>MindGuard 🛡️</h1>", unsafe_allow_html=True) | |
| st.markdown("<p class='sub-header'>A privacy-focused, AI-driven mental health support tool</p>", unsafe_allow_html=True) | |
| # Sidebar for navigation | |
| st.sidebar.title("Navigation") | |
| page = st.sidebar.radio("Go to", ["Text Analysis", "Resource Hub", "About & Ethics"]) | |
| # Text Analysis Page | |
| if page == "Text Analysis": | |
| st.header("Text Analysis & Risk Detection") | |
| # Privacy notice | |
| st.markdown(""" | |
| <div class="disclaimer"> | |
| <strong>Privacy Notice:</strong> Your text is not stored. We use AI to analyze your text for potential | |
| mental health concerns and provide supportive resources. This is not a diagnostic tool. | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Text input options | |
| input_type = st.radio("Select input type:", ["Direct Text Entry", "Social Media Post", "Journal Entry"]) | |
| # Text input with appropriate placeholder based on selection | |
| placeholder_text = { | |
| "Direct Text Entry": "Type or paste your text here...", | |
| "Social Media Post": "Paste your social media post here...", | |
| "Journal Entry": "Paste your journal entry here..." | |
| } | |
| user_text = st.text_area("Enter your text:", height=200, placeholder=placeholder_text[input_type]) | |
| # Analysis button | |
| if st.button("Analyze Text"): | |
| if not user_text: | |
| st.warning("Please enter some text to analyze.") | |
| else: | |
| with st.spinner("Analyzing your text..."): | |
| # Call the analyze_text function from utils | |
| analysis_result = analyze_text(user_text) | |
| # Display analysis results | |
| st.subheader("Analysis Results") | |
| # Display supportive message | |
| st.markdown(f"<div class='disclaimer'>{analysis_result['supportive_message']}</div>", | |
| unsafe_allow_html=True) | |
| # Display recommended resources | |
| st.subheader("Recommended Resources") | |
| for resource in analysis_result['recommended_resources']: | |
| st.markdown(f""" | |
| <div class="resource-card"> | |
| <strong>{resource['name']}</strong><br> | |
| {resource['description']}<br> | |
| <a href="{resource['link']}" target="_blank">{resource['link']}</a> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Explain the analysis (transparency) | |
| with st.expander("How was this analysis performed?"): | |
| st.write(analysis_result['explanation']) | |
| # Disclaimer at bottom of page | |
| st.markdown(""" | |
| <div class="disclaimer" style="margin-top: 2rem;"> | |
| <strong>Important:</strong> If you're experiencing an emergency or crisis, please call your local | |
| emergency services or a crisis hotline immediately. MindGuard is not a substitute for professional help. | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Resource Hub Page | |
| elif page == "Resource Hub": | |
| st.header("Mental Health Resource Hub") | |
| st.write("Find resources tailored to specific mental health concerns.") | |
| # Filter options | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| issue_type = st.multiselect( | |
| "Filter by issue:", | |
| ["Anxiety", "Depression", "Eating Disorders", "Substance Use", "Self-harm", | |
| "Suicidal Thoughts", "Grief", "PTSD", "OCD", "General Mental Health"] | |
| ) | |
| with col2: | |
| location = st.selectbox( | |
| "Filter by location:", | |
| ["All Locations", "United States", "Canada", "United Kingdom", "Australia", "Global"] | |
| ) | |
| # Resource type filter | |
| resource_type = st.multiselect( | |
| "Filter by resource type:", | |
| ["Hotlines", "Online Communities", "Apps", "Therapy Services", "Educational Resources"] | |
| ) | |
| # Get filtered resources | |
| resources = filter_resources(issue_type, location, resource_type) | |
| # Display resources | |
| if resources: | |
| for resource in resources: | |
| st.markdown(f""" | |
| <div class="resource-card"> | |
| <strong>{resource['name']}</strong><br> | |
| <strong>Type:</strong> {resource['type']}<br> | |
| <strong>Focus:</strong> {', '.join(resource['issues'])}<br> | |
| <strong>Location:</strong> {resource['location']}<br> | |
| {resource['description']}<br> | |
| <a href="{resource['link']}" target="_blank">{resource['link']}</a> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| else: | |
| st.info("No resources found matching your filters. Try adjusting your criteria.") | |
| # Add resource suggestion form | |
| with st.expander("Suggest a Resource"): | |
| st.write("Help us improve our resource database by suggesting additional resources.") | |
| resource_name = st.text_input("Resource Name") | |
| resource_link = st.text_input("Resource Link") | |
| resource_description = st.text_area("Brief Description") | |
| resource_issues = st.multiselect( | |
| "Related Issues", | |
| ["Anxiety", "Depression", "Eating Disorders", "Substance Use", "Self-harm", | |
| "Suicidal Thoughts", "Grief", "PTSD", "OCD", "General Mental Health"] | |
| ) | |
| if st.button("Submit Suggestion"): | |
| if resource_name and resource_link and resource_description: | |
| st.success("Thank you for your suggestion! We'll review it soon.") | |
| # Here you would typically save this to a database | |
| else: | |
| st.warning("Please fill in all required fields.") | |
| # About & Ethics Page | |
| else: | |
| st.header("About MindGuard & Our Ethical Approach") | |
| st.subheader("Our Mission") | |
| st.write(""" | |
| MindGuard is designed to provide supportive resources and guidance for individuals who may be | |
| experiencing mental health challenges. We aim to connect people with appropriate resources while | |
| maintaining the highest standards of privacy, ethics, and care. | |
| """) | |
| st.subheader("How MindGuard Works") | |
| st.write(""" | |
| MindGuard uses natural language processing and artificial intelligence to analyze text for potential | |
| signs of mental health concerns. Our system is designed to be supportive rather than diagnostic, | |
| and focuses on connecting users with appropriate resources. | |
| """) | |
| # Diagram of how it works | |
| st.image("https://via.placeholder.com/800x400?text=How+MindGuard+Works+(Diagram)", | |
| caption="Diagram of MindGuard's analysis process") | |
| st.subheader("Our Ethical Principles") | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.markdown(""" | |
| **Privacy First** | |
| - Your text is not stored | |
| - No personal data collection | |
| - Transparent processing | |
| **Non-Diagnostic Approach** | |
| - We do not diagnose conditions | |
| - Focus on supportive resources | |
| - Encourage professional help | |
| """) | |
| with col2: | |
| st.markdown(""" | |
| **Bias Mitigation** | |
| - Regular testing for biases | |
| - Diverse training data | |
| - Continuous improvement | |
| **Accessibility** | |
| - Simple language | |
| - Mobile-friendly design | |
| - Free to use | |
| """) | |
| st.subheader("Data & Privacy") | |
| st.write(""" | |
| MindGuard does not store any of the text you submit for analysis. All processing is done in real-time, | |
| and no personal data is retained. We use anonymized feedback only to improve the system's helpfulness. | |
| """) | |
| st.subheader("Limitations") | |
| st.write(""" | |
| MindGuard is not a substitute for professional mental health care. Our AI-based analysis has limitations | |
| and should not be used as a diagnostic tool. Always consult with qualified mental health professionals | |
| for proper evaluation and treatment. | |
| """) | |
| # Feedback form | |
| st.subheader("Help Us Improve") | |
| with st.form("feedback_form"): | |
| st.write("We value your feedback to improve MindGuard.") | |
| feedback_rating = st.slider("How helpful was MindGuard?", 1, 5, 3) | |
| feedback_text = st.text_area("Any suggestions for improvement?") | |
| feedback_submitted = st.form_submit_button("Submit Feedback") | |
| if feedback_submitted: | |
| st.success("Thank you for your feedback!") |