nniehaus commited on
Commit
1ac36dd
·
verified ·
1 Parent(s): b713e64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -50
app.py CHANGED
@@ -1,55 +1,44 @@
1
- import openai
2
  import streamlit as st
3
- from tenacity import retry, stop_after_attempt, wait_fixed
4
-
5
- # Set the OpenAI API key
6
- openai.api_key = st.secrets["YOUR_OPENAI_API_KEY"]
7
-
8
- initial_messages = [{
9
- "role": "system",
10
- "content": """You are an AI assistant that provides highly customized, detailed, and unique lead generation strategies
11
- for businesses. In this role you should envision yourself as a marketing innovator. You have theorized and tested countless unique marketing
12
- strategies and built a reputation for your innovative ideas. You'll receive information about the type of business, the kind of customer
13
- they'd like to attract, and any current assets they may have.
14
- After receiving this information, follow these steps:
15
- 1. Consider a wide range of 50 initial lead generation strategy ideas. Make sure you consider at least 10 fringe ideas. The kinds of lead gen strategies you wouldn't find
16
- in articles on the internet. These should be designed to fit any unique details the user gives you or simply very out of the box types of strategies.
17
- 2. Narrow it down to the top five best strategies based on the type of business, target customer, and current assets, including at least 2 very unique approaches.
18
- 3. Generate detailed paragraphs for each of the top five strategies. Make sure the fourth and fifth strategies are completely unique and original.
19
- 4. For each strategy, write a full paragraph suggestions the steps they should follow to implement that approach.
20
- 5. Range the strategies from most affordable to most expensive.
21
- 6. Reply to the user with the detailed list of recommended strategies. """
22
- }]
23
-
24
- @retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
25
- def call_openai_api(messages):
26
- return openai.ChatCompletion.create(
27
- model="gpt-4",
28
- messages=messages
29
- )
30
-
31
- def CustomMarketingStrategy(business_description, customer_profile, messages):
32
- messages.append({
33
- "role": "user",
34
- "content": f"My business is about {business_description}. My ideal customer is {customer_profile}."
35
- })
36
- response = call_openai_api(messages)
37
- ChatGPT_reply = response["choices"][0]["message"]["content"]
38
- messages.append({"role": "assistant", "content": ChatGPT_reply})
39
- return ChatGPT_reply, messages
40
-
41
- # Streamlit Interface
42
- st.set_page_config(layout="wide")
43
- st.title("Marketing Strategy Suggester")
44
 
45
- business_description = st.text_area("Describe Your Business", placeholder="Provide a brief description of your business, including the industry and main offerings.")
46
- customer_profile = st.text_area("Describe Your Ideal Customer", placeholder="Describe your ideal customer, including demographics, interests, and any other relevant details.")
47
 
48
- submit_button = st.button('Get Marketing Strategies')
 
 
 
 
 
 
49
 
50
- if submit_button:
 
51
  messages = initial_messages.copy()
52
- reply, _ = CustomMarketingStrategy(business_description, customer_profile, messages)
53
- st.write(reply)
54
- else:
55
- st.write("**Submit your business and customer descriptions to receive marketing strategy suggestions.**")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import openai
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
+ # Assuming your OpenAI API key is set correctly in your Hugging Face Secrets
5
+ openai.api_key = st.secrets["OPENAI_API_KEY"]
6
 
7
+ # Define the initial system message
8
+ initial_messages = [
9
+ {
10
+ "role": "system",
11
+ "content": """You are an AI assistant that provides home staging recommendations for real estate agents. Your guidance helps highlight a property's best features by suggesting specific furniture arrangements, decor choices, and overall aesthetic themes to make homes more appealing to potential buyers. Consider the home's style, size, and unique features in your recommendations, aiming to create a welcoming and attractive environment that can lead to a successful sale."""
12
+ }
13
+ ]
14
 
15
+ # Function to handle the chat interaction
16
+ def custom_chat_gpt(home_details, location):
17
  messages = initial_messages.copy()
18
+ user_input = f"I have a home for sale with these details: {home_details}. It's located in {location}. How should I stage it for potential buyers?"
19
+ messages.append({"role": "user", "content": user_input})
20
+
21
+ try:
22
+ response = openai.ChatCompletion.create(
23
+ model="gpt-4",
24
+ messages=messages
25
+ )
26
+ chat_gpt_reply = response.choices[0].message["content"]
27
+ return chat_gpt_reply
28
+ except Exception as e:
29
+ st.error(f"An error occurred: {str(e)}")
30
+ return None
31
+
32
+ # Streamlit UI
33
+ st.title("Home Staging Assistant")
34
+ home_details = st.text_area("Home Details", placeholder="Describe the home's features, size, style, etc.")
35
+ location = st.text_input("Location", placeholder="Enter the home's location or neighborhood.")
36
+ generate_button = st.button('Get Staging Recommendations')
37
+
38
+ if generate_button:
39
+ reply = custom_chat_gpt(home_details, location)
40
+ if reply:
41
+ st.markdown("### Staging Recommendations")
42
+ st.write(reply)
43
+ else:
44
+ st.write("An error occurred while generating recommendations. Please try again.")