Spaces:
Sleeping
Sleeping
| import openai | |
| import streamlit as st | |
| from tenacity import retry, stop_after_attempt, wait_fixed | |
| # Assuming your OpenAI API key is set in Hugging Face Spaces secrets | |
| openai.api_key = st.secrets["YOUR_OPENAI_API_KEY"] | |
| initial_messages_staging = [ | |
| { | |
| "role": "system", | |
| "content": """ | |
| You are an AI assistant that provides home staging recommendations for real estate agents. Your role is to help agents visualize and execute staging setups that highlight the best features of the homes they're selling. When providing recommendations, ensure: | |
| 1. They are actionable and specific to the home's features and the target buyer demographic. | |
| 2. You include low-cost, DIY options for agents working with limited budgets. | |
| 3. You suggest staging strategies that can make the space appear larger and more inviting. | |
| 4. You consider current home decor trends and advise on how they can be applied effectively. | |
| 5. You offer ideas for both indoor and outdoor spaces. | |
| Always conclude your response with a suggestion for professional staging services for agents who prefer expert assistance.""" | |
| } | |
| ] | |
| def call_openai_api(messages): | |
| return openai.ChatCompletion.create( | |
| model="gpt-4", # Make sure to use the correct model you have access to | |
| messages=messages | |
| ) | |
| def CustomChatGPT(user_input, messages): | |
| messages.append({"role": "user", "content": user_input}) | |
| response = call_openai_api(messages) | |
| ChatGPT_reply = response.choices[0].message["content"] | |
| messages.append({"role": "assistant", "content": ChatGPT_reply}) | |
| return ChatGPT_reply, messages | |
| def wrapped_chat_gpt(home_details, location): | |
| messages = initial_messages_staging.copy() | |
| 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?" | |
| reply, updated_messages = CustomChatGPT(user_input, messages) | |
| return reply | |
| # Streamlit Interface | |
| st.title("Home Staging Assistant") | |
| home_details = st.text_area("Home Details", placeholder="Describe the home's features, size, style, etc.") | |
| location = st.text_input("Location", placeholder="Enter the home's location or neighborhood.") | |
| generate_button = st.button('Get Staging Recommendations') | |
| if generate_button: | |
| reply = wrapped_chat_gpt(home_details, location) | |
| st.text(reply) | |