Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,32 @@
|
|
| 1 |
-
import openai
|
| 2 |
import streamlit as st
|
| 3 |
-
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
openai.api_key = st.secrets["
|
| 7 |
|
| 8 |
-
|
| 9 |
-
{
|
| 10 |
-
"role": "system",
|
| 11 |
-
"content": """
|
| 12 |
-
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:
|
| 13 |
-
1. They are actionable and specific to the home's features and the target buyer demographic.
|
| 14 |
-
2. You include low-cost, DIY options for agents working with limited budgets.
|
| 15 |
-
3. You suggest staging strategies that can make the space appear larger and more inviting.
|
| 16 |
-
4. You consider current home decor trends and advise on how they can be applied effectively.
|
| 17 |
-
5. You offer ideas for both indoor and outdoor spaces.
|
| 18 |
-
Always conclude your response with a suggestion for professional staging services for agents who prefer expert assistance."""
|
| 19 |
-
}
|
| 20 |
-
]
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
return openai.ChatCompletion.create(
|
| 25 |
-
model="gpt-4", # Make sure to use the correct model you have access to
|
| 26 |
-
messages=messages
|
| 27 |
-
)
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
ChatGPT_reply = response.choices[0].message["content"]
|
| 33 |
-
messages.append({"role": "assistant", "content": ChatGPT_reply})
|
| 34 |
-
return ChatGPT_reply, messages
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
st.
|
| 44 |
-
|
| 45 |
-
location = st.text_input("Location", placeholder="Enter the home's location or neighborhood.")
|
| 46 |
-
generate_button = st.button('Get Staging Recommendations')
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
st.text(reply)
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import openai
|
| 3 |
|
| 4 |
+
# Set up the OpenAI API key from Streamlit's secrets
|
| 5 |
+
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
| 6 |
|
| 7 |
+
st.title("Website Feature Code Generator")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# User inputs for the feature they want to add to their website
|
| 10 |
+
feature_description = st.text_area("Describe the website feature you need code for", placeholder="e.g., A contact form with name, email, and message fields")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
if st.button('Generate Code'):
|
| 13 |
+
# Construct the prompt for code generation
|
| 14 |
+
prompt_text = f"Write HTML and CSS code for a website feature described as follows: {feature_description}."
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
# Call the OpenAI API for code generation
|
| 17 |
+
try:
|
| 18 |
+
response = openai.Completion.create(
|
| 19 |
+
model="code-davinci-002", # Use a model suitable for code generation
|
| 20 |
+
prompt=prompt_text,
|
| 21 |
+
max_tokens=150 # Adjust max tokens as necessary
|
| 22 |
+
)
|
| 23 |
+
generated_code = response.choices[0].text
|
| 24 |
+
except Exception as e:
|
| 25 |
+
generated_code = f"Error in generating code: {e}"
|
| 26 |
|
| 27 |
+
# Display the generated code
|
| 28 |
+
st.subheader("Generated Code")
|
| 29 |
+
st.code(generated_code, language='html')
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
# Disclaimer for users
|
| 32 |
+
st.write("Disclaimer: This tool provides AI-generated code suggestions. The generated code may require further testing and modification to be used in a production environment.")
|
|
|