GH111 commited on
Commit
e36951d
1 Parent(s): c1aaacc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ from google.cloud import dialogflow
4
+ import kaleido
5
+ import cohere
6
+ import openai
7
+ import tiktoken
8
+ import tensorflow_probability as tfp
9
+
10
+ # Define model paths
11
+ dialogflow_agent_path = "path/to/dialogflow_agent.json"
12
+ journaling_model_path = "path/to/journaling_model.pt"
13
+ llm_model_name = "gpt-j-6B"
14
+
15
+ # Load models
16
+ dialogflow_agent = dialogflow.Agent.from_json(dialogflow_agent_path)
17
+ tokenizer = AutoTokenizer.from_pretrained(llm_model_name)
18
+ llm_model = AutoModelForCausalLM.from_pretrained(llm_model_name)
19
+
20
+ # Define emotion and topic choices
21
+ emotions = ["Grateful", "Happy", "Sad", "Angry", "Anxious"]
22
+ topics = ["Relationships", "Work", "Personal Growth", "Overall Wellbeing"]
23
+
24
+ # Define breathing exercises
25
+ breathing_exercises = {
26
+ "4-7-8 Breathing": [4, 7, 8],
27
+ "Box Breathing": [4, 4, 4, 4],
28
+ }
29
+
30
+ # Function to generate text with LLM
31
+ def generate_text(prompt, num_beams=5):
32
+ input_ids = tokenizer(prompt, return_tensors="pt").input_ids
33
+ output_ids = llm_model.generate(input_ids, num_beams=num_beams)
34
+ return tokenizer.decode(output_ids[0])
35
+
36
+ # Define individual page functions
37
+ def welcome_page():
38
+ user_input = st.text_input("Talk to the Therapist", placeholder="Start your conversation")
39
+ if user_input:
40
+ response = dialogflow_agent.text_query(user_input)
41
+ st.write(f"{welcome_message}\n\n{note}\n\n{response.query_result.fulfillment_text}")
42
+
43
+ def journaling_page():
44
+ emotion = st.radio("Choose your emotion", options=emotions)
45
+ topic = st.radio("Choose your topic", options=topics)
46
+ if emotion and topic:
47
+ prompt = f"Write about a time when you felt {emotion} about {topic}."
48
+ generated_text = generate_text(prompt)
49
+ st.write("Here are some personalized journaling prompts for you:")
50
+ for line in generated_text.split('\n'):
51
+ st.write(f"- {line}")
52
+
53
+ def breathing_page():
54
+ exercise_name = st.radio("Choose your breathing exercise", options=list(breathing_exercises.keys()))
55
+ if exercise_name:
56
+ exercise = breathing_exercises[exercise_name]
57
+ st.write(f"You selected the {exercise_name} exercise.")
58
+ for duration in exercise:
59
+ st.write(f"{duration} seconds...")
60
+ time.sleep(duration)
61
+ st.write("Breathing exercise complete!")
62
+
63
+ # Streamlit app layout
64
+ st.title("Flow: Self-Healing, Wellness, and Goal-Setting")
65
+ st.write("Welcome to your journey towards self-healing, wellness, and goal achievement.")
66
+
67
+ page_selection = st.sidebar.selectbox("Choose your page", options=["Welcome", "Journaling", "Breathing Exercises"])
68
+
69
+ if page_selection == "Welcome":
70
+ welcome_page()
71
+ elif page_selection == "Journaling":
72
+ journaling_page()
73
+ elif page_selection == "Breathing Exercises":
74
+ breathing_page()