Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the model
|
| 5 |
+
# Use an Instruct-style model like 'flan-t5' or 'gpt-3.5-turbo' (if API key is required)
|
| 6 |
+
chatbot = pipeline("text-generation", model="google/flan-t5-large")
|
| 7 |
+
|
| 8 |
+
# Set up the Streamlit page configuration
|
| 9 |
+
st.set_page_config(page_title="AI Therapy Chatbot", layout="centered")
|
| 10 |
+
|
| 11 |
+
# Title of the application
|
| 12 |
+
st.title("AI Therapy Chatbot")
|
| 13 |
+
|
| 14 |
+
# Add a brief description
|
| 15 |
+
st.markdown("""
|
| 16 |
+
Welcome to the AI Therapy Chatbot! This chatbot is designed to offer therapeutic conversations,
|
| 17 |
+
providing a safe and empathetic space for you to express your feelings.
|
| 18 |
+
""")
|
| 19 |
+
|
| 20 |
+
# Create a text input box for user input
|
| 21 |
+
user_input = st.text_area("How are you feeling today?", "")
|
| 22 |
+
|
| 23 |
+
# Display chatbot's response
|
| 24 |
+
if st.button("Send"):
|
| 25 |
+
if user_input:
|
| 26 |
+
# Construct the message to instruct the model to behave like a therapist
|
| 27 |
+
prompt = f"Imagine you are a therapist. Respond in a supportive, empathetic, and non-judgmental manner to: {user_input}"
|
| 28 |
+
|
| 29 |
+
# Get the response from the model
|
| 30 |
+
response = chatbot(prompt, max_length=150, num_return_sequences=1)[0]['generated_text']
|
| 31 |
+
|
| 32 |
+
# Show the response
|
| 33 |
+
st.text_area("Therapist's Response:", response, height=200)
|
| 34 |
+
else:
|
| 35 |
+
st.warning("Please enter something to continue the conversation.")
|