Update app.py
Browse files
app.py
CHANGED
|
@@ -1,74 +1,53 @@
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
import tiktoken
|
| 8 |
-
import tensorflow_probability as tfp
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
| 15 |
-
# Load
|
| 16 |
-
|
| 17 |
-
tokenizer = AutoTokenizer.from_pretrained(llm_model_name)
|
| 18 |
-
llm_model = AutoModelForCausalLM.from_pretrained(llm_model_name)
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
"
|
| 27 |
-
"
|
| 28 |
-
}
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
| 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 |
-
#
|
| 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 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 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 |
-
|
| 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 |
-
#
|
| 64 |
-
|
| 65 |
-
st.
|
|
|
|
| 66 |
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
if
|
| 70 |
-
|
| 71 |
-
elif page_selection == "Journaling":
|
| 72 |
-
journaling_page()
|
| 73 |
-
elif page_selection == "Breathing Exercises":
|
| 74 |
-
breathing_page()
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
|
| 3 |
import streamlit as st
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
# Function to load Hugging Face models
|
| 7 |
+
def load_model(model_name):
|
| 8 |
+
return pipeline("text-generation", model=model_name, device=0) # Adjust the model type accordingly
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# Page 1: Welcome and Chatbot
|
| 11 |
+
def page_welcome():
|
| 12 |
+
st.title("Welcome to Your Virtual Therapist")
|
| 13 |
+
st.write("Feel free to chat with our virtual therapist!")
|
| 14 |
|
| 15 |
+
# Load your preferred Hugging Face chatbot model
|
| 16 |
+
chatbot_model = load_model("your-chatbot-model-name")
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
user_input = st.text_input("You: ")
|
| 19 |
+
if user_input:
|
| 20 |
+
response = chatbot_model(user_input, max_length=50, num_return_sequences=1)[0]['generated_text']
|
| 21 |
+
st.text_area("Therapist:", response, height=100)
|
| 22 |
|
| 23 |
+
# Page 2: Journaling
|
| 24 |
+
def page_journaling():
|
| 25 |
+
st.title("Journaling Session")
|
| 26 |
+
st.write("Answer the following questions based on your preferences:")
|
|
|
|
| 27 |
|
| 28 |
+
# Add your journaling questions here
|
| 29 |
+
journaling_question = st.text_area("Question:", "How was your day?")
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
# Process the user's response as needed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
# Page 3: Breathing Exercises
|
| 34 |
+
def page_breathing_exercises():
|
| 35 |
+
st.title("Breathing Exercises")
|
| 36 |
+
st.write("Start your meditation with the breathing exercise timer:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
# Add a timer or interactive element for breathing exercises
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
# Main App
|
| 41 |
+
def main():
|
| 42 |
+
st.sidebar.title("Navigation")
|
| 43 |
+
selection = st.sidebar.radio("Go to", ["Welcome & Chatbot", "Journaling", "Breathing Exercises"])
|
| 44 |
|
| 45 |
+
if selection == "Welcome & Chatbot":
|
| 46 |
+
page_welcome()
|
| 47 |
+
elif selection == "Journaling":
|
| 48 |
+
page_journaling()
|
| 49 |
+
elif selection == "Breathing Exercises":
|
| 50 |
+
page_breathing_exercises()
|
| 51 |
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|