|
import streamlit as st |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
from google.cloud import dialogflow |
|
import kaleido |
|
import cohere |
|
import openai |
|
import tiktoken |
|
import tensorflow_probability as tfp |
|
|
|
|
|
dialogflow_agent_path = "path/to/dialogflow_agent.json" |
|
journaling_model_path = "path/to/journaling_model.pt" |
|
llm_model_name = "gpt-j-6B" |
|
|
|
|
|
dialogflow_agent = dialogflow.Agent.from_json(dialogflow_agent_path) |
|
tokenizer = AutoTokenizer.from_pretrained(llm_model_name) |
|
llm_model = AutoModelForCausalLM.from_pretrained(llm_model_name) |
|
|
|
|
|
emotions = ["Grateful", "Happy", "Sad", "Angry", "Anxious"] |
|
topics = ["Relationships", "Work", "Personal Growth", "Overall Wellbeing"] |
|
|
|
|
|
breathing_exercises = { |
|
"4-7-8 Breathing": [4, 7, 8], |
|
"Box Breathing": [4, 4, 4, 4], |
|
} |
|
|
|
|
|
def generate_text(prompt, num_beams=5): |
|
input_ids = tokenizer(prompt, return_tensors="pt").input_ids |
|
output_ids = llm_model.generate(input_ids, num_beams=num_beams) |
|
return tokenizer.decode(output_ids[0]) |
|
|
|
|
|
def welcome_page(): |
|
user_input = st.text_input("Talk to the Therapist", placeholder="Start your conversation") |
|
if user_input: |
|
response = dialogflow_agent.text_query(user_input) |
|
st.write(f"{welcome_message}\n\n{note}\n\n{response.query_result.fulfillment_text}") |
|
|
|
def journaling_page(): |
|
emotion = st.radio("Choose your emotion", options=emotions) |
|
topic = st.radio("Choose your topic", options=topics) |
|
if emotion and topic: |
|
prompt = f"Write about a time when you felt {emotion} about {topic}." |
|
generated_text = generate_text(prompt) |
|
st.write("Here are some personalized journaling prompts for you:") |
|
for line in generated_text.split('\n'): |
|
st.write(f"- {line}") |
|
|
|
def breathing_page(): |
|
exercise_name = st.radio("Choose your breathing exercise", options=list(breathing_exercises.keys())) |
|
if exercise_name: |
|
exercise = breathing_exercises[exercise_name] |
|
st.write(f"You selected the {exercise_name} exercise.") |
|
for duration in exercise: |
|
st.write(f"{duration} seconds...") |
|
time.sleep(duration) |
|
st.write("Breathing exercise complete!") |
|
|
|
|
|
st.title("Flow: Self-Healing, Wellness, and Goal-Setting") |
|
st.write("Welcome to your journey towards self-healing, wellness, and goal achievement.") |
|
|
|
page_selection = st.sidebar.selectbox("Choose your page", options=["Welcome", "Journaling", "Breathing Exercises"]) |
|
|
|
if page_selection == "Welcome": |
|
welcome_page() |
|
elif page_selection == "Journaling": |
|
journaling_page() |
|
elif page_selection == "Breathing Exercises": |
|
breathing_page() |
|
|