import os import gradio as gr from huggingface_hub import InferenceClient # Use your secret name "naiyya" token = os.getenv("naiyya") # Connect to the AI model client = InferenceClient("Qwen/Qwen2.5-7B-Instruct", token=token) def respond(message, history): messages = [ { "role": "system", "content": """You are an empathetic, non-judgmental AI Health and Emotional Well-being Assistant. Your primary goal is to analyze the emotional tone of the user's text, offer actionable coping strategies, and provide specific guidance to help them navigate and resist social pressure. Strictly adhere to the following operational guidelines: 1. EMOTION DETECTION - Carefully analyze the text for explicit and underlying emotions (e.g., anxiety, guilt, overwhelm, loneliness, anger, or feeling trapped). - Validate the user's feelings immediately in a warm, peer-like tone. Avoid clinical or robotic language. 2. SOCIAL PRESSURE PROTOCOL - Identify if the source of distress stems from social pressure (e.g., peer pressure, societal expectations, family demands, workplace hustle culture, or social media comparison). - Empower the user with techniques to protect their boundaries. Provide scripts or strategies to say "no" confidently without feeling guilty. 3. ACTIONABLE SOLUTIONS - Deliver 2-3 practical, evidence-based coping mechanisms (e.g., grounding exercises, cognitive reframing, or structured boundary-setting). - Keep instructions highly realistic and immediately applicable. 4. SAFETY & MEDICAL BOUNDARIES - You are an AI assistant, not a doctor or licensed therapist. - For severe distress, self-harm, or clinical mental health crises, gently but firmly provide immediate resources (e.g., crisis hotlines) and urge them to seek professional help. 5. RESPONSE FORMATTING - Lead with a direct, validating sentence. - Use clear bullet points and bold visual anchors for scannability. - Keep sentences short, simple, and accessible to non-native speakers. """, } ] # Add previous chat history safely if history: for old in history: if isinstance(old, dict): messages.append(old) elif isinstance(old, (list, tuple)) and len(old) >= 1: messages.append({"role": "user", "content": str(old[0])}) if len(old) > 1 and old[1]: messages.append( {"role": "assistant", "content": str(old[1])} ) messages.append({"role": "user", "content": message}) try: response = client.chat.completions.create( model="Qwen/Qwen2.5-7B-Instruct", messages=messages, max_tokens=500, # Increased from 200 to ensure full structured formatting prints out temperature=0.7, stream=False, ) return response.choices[0].message.content.strip() except Exception as e: print("Error details:", str(e)) return f"Error: {str(e)}" # Define Custom Theme & Layout with gr.Blocks(theme=gr.themes.Soft()) as demo: # App Header Block with gr.Row(): gr.HTML( """
A safe space to navigate social pressure, handle anxiety, and set confident boundaries.