Spaces:
Runtime error
Runtime error
Download app.py from starting123/mentlly: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/starting123/mentlly/resolve/d03f995569067de2ed032e6ef8669894de35ae35/app.py
- Command line
-
hf download hf://spaces/starting123/mentlly@d03f995569067de2ed032e6ef8669894de35ae35/app.py
-
curl -L -o app.py https://huggingface.co/spaces/starting123/mentlly/resolve/d03f995569067de2ed032e6ef8669894de35ae35/app.py
1.27 kB
| 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() | |