import gradio as gr from transformers import pipeline, AutoTokenizer # Load the model and tokenizer tokenizer = AutoTokenizer.from_pretrained("HuggingFaceH4/zephyr-1b-beta") pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-1b-beta", device_map="auto") # chatbot system def mental_health_chatbot(user_input): # Define the chatbot's system and user messages system_message = ( "You are a compassionate and empathetic mental health chatbot. " "Your goal is to listen carefully, provide comforting support, and offer " "helpful guidance to users who are feeling down, anxious, or stressed." ) # Format the prompt manually since 'apply_chat_template' is not available for text-generation prompt = f"System: {system_message}\nUser: {user_input}\nBot:" # Generate response outputs = pipe(prompt, max_new_tokens=100, do_sample=True, temperature=0.7, top_k=50, top_p=0.95) return outputs[0]["generated_text"] # Gradio interface setup interface = gr.Interface( fn=mental_health_chatbot, inputs="text", outputs="text", title="Mental Health Chatbot", description="A compassionate and empathetic chatbot to help you feel supported." ) # Launch the Gradio app interface.launch()