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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -36
app.py CHANGED
@@ -1,44 +1,42 @@
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.")
 
 
1
  import openai
2
+ import streamlit as st
3
+ from tenacity import retry, stop_after_attempt, wait_fixed
4
 
5
+ # Assuming your OpenAI API key is set in Hugging Face Spaces secrets
6
  openai.api_key = st.secrets["OPENAI_API_KEY"]
7
 
8
+ initial_messages_marketing = [{
9
+ "role": "system",
10
+ "content": """
11
+ Your detailed system message goes here...
12
+ """
13
+ }]
 
14
 
15
+ @retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
16
+ def call_openai_api(messages):
17
+ return openai.ChatCompletion.create(
18
+ model="gpt-4",
19
+ messages=messages
20
+ )
21
+
22
+ def CustomMarketingGPT(user_input, messages):
23
  messages.append({"role": "user", "content": user_input})
24
+ response = call_openai_api(messages)
25
+ marketing_reply = response.choices[0].message["content"]
26
+ messages.append({"role": "assistant", "content": marketing_reply})
27
+ return marketing_reply, messages
28
+
29
+ def wrapped_marketing_gpt(area, home_details):
30
+ messages = initial_messages_marketing.copy()
31
+ user_input = f"I live in {area} and my home has these features: {home_details}. What are some creative marketing ideas to promote the sale of my home?"
32
+ reply, updated_messages = CustomMarketingGPT(user_input, messages)
33
+ return reply
 
34
 
35
+ # Streamlit Interface
36
+ st.title("Home Marketing Assistant")
37
+ area = st.text_input("Location")
38
+ home_details = st.text_area("Home Details", placeholder="E.g., 4 bedrooms, renovated kitchen, hardwood floors...")
 
39
 
40
+ if st.button('Generate Marketing Ideas'):
41
+ reply = wrapped_marketing_gpt(area, home_details)
42
+ st.text_area("Marketing Ideas", reply, height=300)