ocd-cbt-assistant / src /streamlit_app.py
manar54's picture
Update src/streamlit_app.py
b1449ee verified
import streamlit as st
from openai import OpenAI
import os
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def get_therapy_response(user_input):
prompt = f"""
You are a kind and professional OCD CBT therapist. The patient said: '{user_input}'
Always respond with warmth and calm.
Gently validate their feeling.
Explain briefly how thoughts affect emotions and behaviors in OCD.
Give one helpful CBT-based reflection or tip.
End by encouraging them to keep practicing through their OCD game.
"""
response = client.responses.create(
model="gpt-4.1",
input=prompt,
temperature=1,
max_output_tokens=1024,
top_p=1
)
return response.output[0].content[0].text.strip()
st.title("🧠 OCD CBT Assistant")
st.write("This assistant uses CBT techniques to gently help with OCD thoughts.")
user_input = st.text_input("πŸ’¬ What thoughts are coming to your mind right now?")
if user_input:
with st.spinner("🧠 Thinking..."):
answer = get_therapy_response(user_input)
st.markdown(f"**πŸ‘¨β€βš•οΈ Therapist:** {answer}")