nniehaus commited on
Commit
1813aa1
·
verified ·
1 Parent(s): 44ea91a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -38
app.py CHANGED
@@ -1,48 +1,39 @@
1
  import streamlit as st
2
  import openai
3
 
4
- # Initializing Streamlit app
5
- st.title("AI Integration Assessment for Businesses")
6
 
7
- # Securely accessing the OpenAI API key
8
- openai.api_key = st.secrets["OPENAI_API_KEY"]
 
9
 
10
- # Function to call OpenAI API using GPT-4o
11
- def call_openai_api(prompt):
 
 
 
 
 
 
 
 
 
12
  try:
13
- response = openai.ChatCompletion.create(
14
- model="gpt-4o", # Specify GPT-4o as the model
15
- messages=[
16
- {"role": "system", "content": prompt['system']},
17
- {"role": "user", "content": prompt['user']}
18
- ]
 
 
19
  )
20
- return response.choices[0].message['content']
 
21
  except Exception as e:
22
- st.error(f"An error occurred: {str(e)}")
23
  return None
24
 
25
- # Streamlit UI for input
26
- business_type = st.text_input("Describe your business type and main activities:", "e.g., Manufacturing")
27
- current_tech_usage = st.text_input("Describe current technology usage in your business:", "e.g., Mostly manual processes with some Excel usage")
28
- ai_interest_areas = st.multiselect("Select potential areas for AI integration:",
29
- ["Customer Service", "Operations", "Marketing", "Risk Management", "Product Development"])
30
-
31
- generate_button = st.button('Generate AI Integration Report')
32
-
33
- # Handling the button click
34
- if generate_button:
35
- user_prompt = {
36
- "system": """
37
- You are an AI consultant tasked with evaluating a business to determine where AI can be effectively integrated. Provide a detailed report that assesses the current technology usage and recommends areas for AI implementation based on the business type and interests.""",
38
- "user": f"""
39
- Business Type: {business_type}
40
- Current Technology Usage: {current_tech_usage}
41
- Interest Areas: {', '.join(ai_interest_areas)}"""
42
- }
43
- report = call_openai_api(user_prompt)
44
- if report:
45
- st.markdown("### AI Integration Report")
46
- st.write(report)
47
- else:
48
- st.write("An error occurred while generating the report. Please try again.")
 
1
  import streamlit as st
2
  import openai
3
 
4
+ def main():
5
+ st.title("Email Subject Line Generator")
6
 
7
+ # Collect user input about the audience and message
8
+ audience_desc = st.text_input("Describe your audience (e.g., age, interests, profession):", "e.g., middle-aged professionals interested in sustainability")
9
+ message_content = st.text_area("What is the main message or offer of your email?", "e.g., Inviting you to join our sustainability webinar")
10
 
11
+ # Button to generate email subject lines
12
+ if st.button('Generate Email Subject Lines'):
13
+ subject_lines = generate_subject_lines(audience_desc, message_content)
14
+ if subject_lines:
15
+ st.subheader("Suggested Email Subject Lines and Preheaders:")
16
+ for idx, line in enumerate(subject_lines, 1):
17
+ st.text(f"{idx}. {line}")
18
+ else:
19
+ st.error("Failed to generate subject lines. Please try again.")
20
+
21
+ def generate_subject_lines(audience, message):
22
  try:
23
+ # OpenAI API call to generate subject lines
24
+ response = openai.Completion.create(
25
+ model="text-davinci-003",
26
+ prompt=f"Generate 10 compelling email subject lines and preheaders for an audience that includes {audience}, regarding the following message: {message}",
27
+ max_tokens=150,
28
+ n=10,
29
+ stop=None,
30
+ temperature=0.7
31
  )
32
+ # Extracting text from the responses
33
+ return [choice['text'].strip() for choice in response.choices]
34
  except Exception as e:
35
+ st.error(f"An error occurred while generating subject lines: {str(e)}")
36
  return None
37
 
38
+ if __name__ == "__main__":
39
+ main()