Lucasstranger1 commited on
Commit
1bbb83d
·
verified ·
1 Parent(s): ca211ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
app.py CHANGED
@@ -45,9 +45,13 @@ def generate_text_based_on_mood(emotion, response_type):
45
  try:
46
  if response_type == "Joke":
47
  prompt = f"Generate a light-hearted joke for someone who is feeling {emotion}."
48
- else: # Motivational Message
49
  prompt = f"Generate a motivational message for someone who is feeling {emotion}."
50
-
 
 
 
 
51
  # Call OpenAI's API using GPT-4.
52
  response = openai.ChatCompletion.create(
53
  model="gpt-4", # Specify the GPT-4 model
@@ -97,20 +101,26 @@ def main():
97
  st.write(f"Detected emotion: {emotion}")
98
 
99
  # Dropdown for selecting response type.
100
- response_type = st.selectbox("Select the type of response:", ["Joke", "Motivational Message"])
101
 
102
  # Generate text based on detected emotion and user preference.
103
  if st.button("Get Response"):
104
  message = generate_text_based_on_mood(emotion, response_type)
 
 
105
  st.write("Here's your response:")
106
  st.write(message)
107
 
108
- # Convert the generated message to audio.
109
- audio_file = text_to_speech(message)
 
 
110
 
111
- # Provide an audio player in the Streamlit app if audio file exists.
112
- if audio_file:
113
- st.audio(audio_file) # Streamlit will handle playback.
 
 
114
 
115
  #############################################################################################################################
116
  # Run the application.
 
45
  try:
46
  if response_type == "Joke":
47
  prompt = f"Generate a light-hearted joke for someone who is feeling {emotion}."
48
+ elif response_type == "Motivational Message":
49
  prompt = f"Generate a motivational message for someone who is feeling {emotion}."
50
+ elif response_type == "Compliment":
51
+ prompt = f"Generate a heartfelt compliment for someone who is feeling {emotion}."
52
+ elif response_type == "Song Recommendation":
53
+ prompt = f"Recommend a song that would suit someone who is feeling {emotion}. Include the song title and artist."
54
+
55
  # Call OpenAI's API using GPT-4.
56
  response = openai.ChatCompletion.create(
57
  model="gpt-4", # Specify the GPT-4 model
 
101
  st.write(f"Detected emotion: {emotion}")
102
 
103
  # Dropdown for selecting response type.
104
+ response_type = st.selectbox("Select the type of response:", ["Joke", "Motivational Message", "Compliment", "Song Recommendation"])
105
 
106
  # Generate text based on detected emotion and user preference.
107
  if st.button("Get Response"):
108
  message = generate_text_based_on_mood(emotion, response_type)
109
+
110
+ # Display the generated message (song recommendation or other response)
111
  st.write("Here's your response:")
112
  st.write(message)
113
 
114
+ # If the response is a song recommendation, provide extra formatting if desired.
115
+ if response_type == "Song Recommendation":
116
+ st.write("Song Recommendation:")
117
+ st.write(message)
118
 
119
+ # Convert the generated message to audio if it's not a song recommendation (optional)
120
+ if response_type != "Song Recommendation":
121
+ audio_file = text_to_speech(message)
122
+ if audio_file:
123
+ st.audio(audio_file) # Streamlit will handle playback.
124
 
125
  #############################################################################################################################
126
  # Run the application.