Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,49 +2,34 @@ import openai
|
|
| 2 |
import streamlit as st
|
| 3 |
from tenacity import retry, stop_after_attempt, wait_fixed
|
| 4 |
|
| 5 |
-
# Streamlit
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
-
# Otherwise, replace "your_actual_openai_api_key_here" with your actual OpenAI API key
|
| 10 |
-
openai.api_key = st.secrets.get("OPENAI_API_KEY", "your_actual_openai_api_key_here")
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
"
|
| 15 |
-
"
|
| 16 |
-
|
| 17 |
-
1. They are actionable and specific to the home's features and the target buyer demographic.
|
| 18 |
-
2. You include low-cost, DIY options for agents working with limited budgets.
|
| 19 |
-
3. You suggest staging strategies that can make the space appear larger and more inviting.
|
| 20 |
-
4. You consider current home decor trends and advise on how they can be applied effectively.
|
| 21 |
-
5. You offer ideas for both indoor and outdoor spaces.
|
| 22 |
-
Always conclude your response with a suggestion for professional staging services for agents who prefer expert assistance.
|
| 23 |
-
"""
|
| 24 |
-
}]
|
| 25 |
|
| 26 |
-
# Add retry logic to the OpenAI API call
|
| 27 |
@retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
|
| 28 |
-
def call_openai_api(
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
# Streamlit UI elements for user input
|
| 43 |
-
home_details = st.text_area("Home Details", placeholder="Describe the home's features, size, style, etc.")
|
| 44 |
-
location = st.text_input("Location", placeholder="Enter the home's location or neighborhood.")
|
| 45 |
-
generate_button = st.button('Get Staging Recommendations')
|
| 46 |
-
|
| 47 |
-
# Handling the button click to generate staging advice
|
| 48 |
-
if generate_button:
|
| 49 |
-
staging_advice = generate_staging_advice(home_details, location)
|
| 50 |
-
st.text_area("Staging Recommendations", staging_advice, height=300)
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
from tenacity import retry, stop_after_attempt, wait_fixed
|
| 4 |
|
| 5 |
+
# Assuming the OpenAI API key is stored in Streamlit's secrets
|
| 6 |
+
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
| 7 |
|
| 8 |
+
st.title("Website Feature Code Generator")
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# User inputs for the feature they want to add
|
| 11 |
+
feature_description = st.text_area(
|
| 12 |
+
"Describe the website feature you'd like to implement:",
|
| 13 |
+
"E.g., A contact form with name, email, and message fields that emails the site owner."
|
| 14 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
|
|
|
| 16 |
@retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
|
| 17 |
+
def call_openai_api(prompt):
|
| 18 |
+
try:
|
| 19 |
+
response = openai.Completion.create(
|
| 20 |
+
model="gpt-4",
|
| 21 |
+
prompt=prompt,
|
| 22 |
+
max_tokens=150
|
| 23 |
+
)
|
| 24 |
+
return response.choices[0].text
|
| 25 |
+
except Exception as e:
|
| 26 |
+
st.error(f"An error occurred: {str(e)}")
|
| 27 |
+
return None
|
| 28 |
|
| 29 |
+
if st.button("Generate Code"):
|
| 30 |
+
prompt = f"Write the HTML, CSS, and JavaScript code for a website feature described as follows: {feature_description}"
|
| 31 |
+
code = call_openai_api(prompt)
|
| 32 |
+
if code:
|
| 33 |
+
st.code(code, language="html")
|
| 34 |
+
else:
|
| 35 |
+
st.write("Could not generate the code. Please check the feature description and try again.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|