nniehaus commited on
Commit
5ebf920
·
verified ·
1 Parent(s): 3ef8d9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -15
app.py CHANGED
@@ -10,33 +10,25 @@ def main():
10
  tone = st.selectbox("Choose the tone for your email subject lines:", ['Friendly', 'Professional', 'Urgent', 'Curious'])
11
 
12
  if st.button('Generate Email Subject Lines and Preheaders'):
13
- subject_lines, preheaders = generate_subject_lines_and_preheaders(audience_desc, message_content, tone)
14
- if subject_lines:
15
  st.subheader("Suggested Email Subject Lines and Preheaders:")
16
- for idx, (line, preheader) in enumerate(zip(subject_lines, preheaders), 1):
17
- st.markdown(f"- **Subject Line {idx}**: {line}")
18
- st.markdown(f" - **Preheader {idx}**: {preheader}")
19
  else:
20
  st.error("Failed to generate subject lines and preheaders. Please check the inputs and try again.")
21
 
22
  def generate_subject_lines_and_preheaders(audience, message, tone):
23
  try:
24
- prompt_text = f"""...Your existing prompt..."""
25
  response = openai.ChatCompletion.create(
26
  model="gpt-4o",
27
  messages=[{"role": "system", "content": prompt_text}],
28
  max_tokens=500
29
  )
30
- # Debug print to check response structure
31
- print("Debug: Full API Response:", response)
32
- # Extracting subject lines and preheaders using newline split
33
- pairs = response.choices[0].message['content'].split('\n\n')[1:] # Skipping the first line which is usually an introductory line
34
- subject_lines = [pair.split('\n')[0] for pair in pairs]
35
- preheaders = [pair.split('\n')[1] for pair in pairs]
36
- return subject_lines, preheaders
37
  except Exception as e:
38
  st.error(f"An error occurred: {str(e)}")
39
- return None, None
40
 
41
  if __name__ == "__main__":
42
- main()
 
10
  tone = st.selectbox("Choose the tone for your email subject lines:", ['Friendly', 'Professional', 'Urgent', 'Curious'])
11
 
12
  if st.button('Generate Email Subject Lines and Preheaders'):
13
+ response = generate_subject_lines_and_preheaders(audience_desc, message_content, tone)
14
+ if response:
15
  st.subheader("Suggested Email Subject Lines and Preheaders:")
16
+ st.write(response) # Directly display the response
 
 
17
  else:
18
  st.error("Failed to generate subject lines and preheaders. Please check the inputs and try again.")
19
 
20
  def generate_subject_lines_and_preheaders(audience, message, tone):
21
  try:
22
+ prompt_text = f"""Generate 10 pairs of compelling email subject lines and preheaders for an audience interested in {audience} about '{message}', in a {tone.lower()} tone. Each subject line should be under 7 words, and each preheader should complement the subject line. Display them as a list."""
23
  response = openai.ChatCompletion.create(
24
  model="gpt-4o",
25
  messages=[{"role": "system", "content": prompt_text}],
26
  max_tokens=500
27
  )
28
+ return response.choices[0].message['content']
 
 
 
 
 
 
29
  except Exception as e:
30
  st.error(f"An error occurred: {str(e)}")
31
+ return None
32
 
33
  if __name__ == "__main__":
34
+ main()