Samantha Hipple commited on
Commit
ad1bdd3
1 Parent(s): 3bd9cbf

added session state check

Browse files
Files changed (1) hide show
  1. app.py +20 -11
app.py CHANGED
@@ -8,15 +8,16 @@ from emodeepface import check_image_rotation, process_photo
8
  def load_cached_model():
9
  return load_model()
10
 
11
- # display loading message when app is accessed/refreshed
12
- loading_message = st.empty()
13
- loading_message.text("Loading model... Please wait.")
 
 
 
 
14
 
15
- # begin loading beluga model and tokenizer
16
- model, tokenizer = load_cached_model()
17
-
18
- # clear loading message
19
- loading_message.empty()
20
 
21
  # title webpage
22
  st.title("Affective Journaling Assistant")
@@ -42,12 +43,20 @@ file_name = st.file_uploader("Please upload your photo.")
42
  if file_name is not None:
43
  # capture image with intended rotation
44
  image = check_image_rotation(file_name)
45
- # display the image directly
46
- st.image(image, use_column_width=True)
 
 
 
 
 
47
  # process uploaded image
48
  emotion_predictions = process_photo(file_name)
49
  # process emotion predictions
50
- result = process_emotions(model, tokenizer, emotion_predictions)
 
 
 
51
  # generate affective journaling prompt based on emotion predictions
52
  prompt = generate_prompt(result)
53
  # display journal prompt
 
8
  def load_cached_model():
9
  return load_model()
10
 
11
+ # If the model and tokenizer aren't already in session state, load them
12
+ if 'model' not in st.session_state:
13
+ loading_message = st.empty()
14
+ loading_message.text("Loading model... Please wait.")
15
+
16
+ # begin loading beluga model and tokenizer
17
+ st.session_state.model, st.session_state.tokenizer = load_cached_model()
18
 
19
+ # clear loading message
20
+ loading_message.empty()
 
 
 
21
 
22
  # title webpage
23
  st.title("Affective Journaling Assistant")
 
43
  if file_name is not None:
44
  # capture image with intended rotation
45
  image = check_image_rotation(file_name)
46
+
47
+ # display the image directly with adjusted width
48
+ st.image(image, width=300) # Adjust width as needed
49
+
50
+ processing_message = st.empty()
51
+ processing_message.text("Analyzing your image... Please wait.")
52
+
53
  # process uploaded image
54
  emotion_predictions = process_photo(file_name)
55
  # process emotion predictions
56
+ result = process_emotions(st.session_state.model, st.session_state.tokenizer, emotion_predictions)
57
+
58
+ processing_message.empty()
59
+
60
  # generate affective journaling prompt based on emotion predictions
61
  prompt = generate_prompt(result)
62
  # display journal prompt