| import gradio as gr |
| import google.generativeai as genai |
| import os |
|
|
| |
| API_KEY = os.getenv("GOOGLE_API_KEY") |
| genai.configure(api_key=API_KEY) |
| model = genai.GenerativeModel("gemini-2.0-flash") |
| chat = model.start_chat() |
|
|
| |
| initial_message = ( |
| "Hey, I'm using you as a therapist to help people who are feeling sad feel better. " |
| "I want you to improve the user's mental health and make them feel good about themselves, " |
| "sort of like a supportive friend. Keep your responses short, concise, and make them feel like they matter. " |
| "Do not directly guide them to a suicide prevention hotline, as it will be mentioned on my website already. " |
| "Just be there to listen. Start the conversation by saying 'Hi, how are you doing today?'" |
| ) |
| chat.send_message(initial_message) |
|
|
| |
| def chat_function(message, history): |
| |
| if history: |
| for msg in history: |
| chat.send_message(msg["content"]) |
| |
| |
| response = chat.send_message(message) |
| return response.text |
|
|
| |
| with gr.Blocks() as demo: |
| gr.Markdown("# VoiceAI: Your Supportive Chatbot") |
| gr.Markdown("I'm here to listen and help you feel better. You matter! If you're having suicidal thoughts or feelings please call: 988") |
| chatbot = gr.ChatInterface( |
| fn=chat_function, |
| chatbot=gr.Chatbot(height=500, show_copy_button=True, type="messages"), |
| title="Chat with VoiceAI", |
| description="A supportive chatbot to lift your spirits. Type 'exit' to close the chat.", |
| submit_btn="Send" |
| ) |
|
|
| |
| if __name__ == "__main__": |
| demo.launch(share=True) |