Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,42 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
import openai
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
# Assuming your OpenAI API key is set
|
| 5 |
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
]
|
| 14 |
|
| 15 |
-
|
| 16 |
-
def
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
messages.append({"role": "user", "content": user_input})
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
return None
|
| 31 |
|
| 32 |
-
# Streamlit
|
| 33 |
-
st.title("Home
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
generate_button = st.button('Get Staging Recommendations')
|
| 37 |
|
| 38 |
-
if
|
| 39 |
-
reply =
|
| 40 |
-
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|