Lucasstranger1 commited on
Commit
ceb1369
1 Parent(s): d78bf26
Files changed (1) hide show
  1. app.py +4 -8
app.py CHANGED
@@ -29,9 +29,9 @@ def query_emotion(filename):
29
  # Function to generate a joke or uplifting text based on the mood
30
  def generate_text_based_on_mood(emotion):
31
  try:
32
- # Define a clear and directive prompt
33
- prompt = f"Please tell a funny joke that would cheer someone up who is feeling {emotion}. Make it light-hearted and fun."
34
 
 
35
  for attempt in range(5): # Retry up to 5 times
36
  response = requests.post(text_model_url, headers=headers, json={"inputs": prompt})
37
  if response.status_code == 200:
@@ -63,12 +63,8 @@ def text_to_speech(text):
63
  tts.save(audio_file) # Save the audio file
64
  return audio_file
65
  except Exception as e:
66
- if "429" in str(e):
67
- st.error("Too many requests to the TTS service. Please try again later.")
68
- return None
69
- else:
70
- st.error(f"Error with TTS: {e}")
71
- return None
72
 
73
  # Streamlit UI
74
  st.title("Facial Expression Mood Detector")
 
29
  # Function to generate a joke or uplifting text based on the mood
30
  def generate_text_based_on_mood(emotion):
31
  try:
32
+ prompt = f"Generate a light-hearted joke or uplifting message for someone who is feeling {emotion}."
 
33
 
34
+ # Retry mechanism for text generation
35
  for attempt in range(5): # Retry up to 5 times
36
  response = requests.post(text_model_url, headers=headers, json={"inputs": prompt})
37
  if response.status_code == 200:
 
63
  tts.save(audio_file) # Save the audio file
64
  return audio_file
65
  except Exception as e:
66
+ st.error(f"Error with TTS: {e}")
67
+ return None
 
 
 
 
68
 
69
  # Streamlit UI
70
  st.title("Facial Expression Mood Detector")