Update app.py
Browse files
app.py
CHANGED
@@ -1,48 +1,50 @@
|
|
1 |
-
import streamlit as st
|
2 |
import openai
|
3 |
import os
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
def call_openai_api(messages):
|
11 |
-
|
12 |
model="gpt-4",
|
13 |
messages=messages
|
14 |
)
|
|
|
15 |
|
16 |
-
|
|
|
|
|
17 |
messages.append({"role": "user", "content": user_input})
|
18 |
response = call_openai_api(messages)
|
19 |
-
|
20 |
-
messages.append({"role": "assistant", "content":
|
21 |
-
return
|
22 |
|
23 |
# Streamlit UI
|
24 |
-
st.title("
|
25 |
-
st.write("This tool generates a personalized video marketing roadmap for real estate professionals. Fill in the details about your business, video experience, resources, and goals.")
|
26 |
-
|
27 |
-
# Collecting user inputs
|
28 |
-
business_type = st.text_input("Type of Real Estate Business", placeholder="e.g., Residential, Commercial, Rental")
|
29 |
-
target_audience = st.text_input("Target Audience Demographics", placeholder="e.g., First-time Homebuyers, Luxury Clients")
|
30 |
-
current_marketing = st.text_input("Current Marketing Strategies", placeholder="e.g., Social Media, Email Campaigns")
|
31 |
-
|
32 |
-
video_experience = st.selectbox("Video Production Skills Level", ["Beginner", "Intermediate", "Advanced"])
|
33 |
-
video_marketing_experience = st.selectbox("Experience with Video Marketing", ["None", "Some", "Extensive"])
|
34 |
-
|
35 |
-
budget = st.text_input("Budget for Video Production", placeholder="Enter your budget")
|
36 |
-
time_availability = st.text_input("Time Availability for Video Creation", placeholder="e.g., 5 hours a week")
|
37 |
-
equipment = st.text_input("Available Equipment for Video Production", placeholder="e.g., Smartphone, DSLR Camera")
|
38 |
-
|
39 |
-
goals = st.text_area("Video Marketing Goals", placeholder="Enter your specific objectives for using video in your business")
|
40 |
-
desired_timeline = st.text_input("Desired Timeline for Achieving Goals", placeholder="e.g., 6 months")
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
if
|
45 |
messages = initial_messages.copy()
|
46 |
-
|
47 |
-
reply, _ = CustomChatGPT(user_input, messages)
|
48 |
st.write(reply)
|
|
|
1 |
+
import streamlit as st
|
2 |
import openai
|
3 |
import os
|
4 |
+
from tenacity import retry, wait_fixed, stop_after_attempt
|
5 |
+
|
6 |
+
# Set the OpenAI API key
|
7 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
8 |
+
|
9 |
+
# Define the initial system message
|
10 |
+
initial_messages = [
|
11 |
+
{
|
12 |
+
"role": "system",
|
13 |
+
"content": """You are an AI assistant that provides highly specific investment property recommendations in Breckenridge and
|
14 |
+
Blue River, CO. Consider the user's maximum price, selected amenities, and area preferences to recommend specific neighborhoods
|
15 |
+
or intersections that would be a good fit for investment. Importantly, only recommend areas where short-term rentals are allowed
|
16 |
+
under the new law."""
|
17 |
+
}
|
18 |
+
]
|
19 |
+
|
20 |
+
# Add retry logic to the API call
|
21 |
+
@retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
|
22 |
def call_openai_api(messages):
|
23 |
+
response = openai.ChatCompletion.create(
|
24 |
model="gpt-4",
|
25 |
messages=messages
|
26 |
)
|
27 |
+
return response
|
28 |
|
29 |
+
# Function to handle the chat interaction
|
30 |
+
def InvestmentPropertyFinder(max_price, amenities, bedrooms, bathrooms, square_footage, messages):
|
31 |
+
user_input = f"I'm considering buying an investment property in Breckenridge and Blue River, CO. My maximum price is {max_price}. I'm looking for these amenities: {', '.join(amenities)}. Bedrooms: {bedrooms}, Bathrooms: {bathrooms}, Square Footage: {square_footage if square_footage else 'No preference'}."
|
32 |
messages.append({"role": "user", "content": user_input})
|
33 |
response = call_openai_api(messages)
|
34 |
+
finder_reply = response.choices[0].message.content
|
35 |
+
messages.append({"role": "assistant", "content": finder_reply})
|
36 |
+
return finder_reply, messages
|
37 |
|
38 |
# Streamlit UI
|
39 |
+
st.title("Investment Property Finder in Breckenridge and Blue River, CO")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
max_price = st.text_input("Maximum Price", "Enter your maximum price for the property.")
|
42 |
+
amenities = st.multiselect("Amenities", ["Close to Skiing", "Hot Tub", "Bus Route", "Parking"], "Select Amenities")
|
43 |
+
bedrooms = st.selectbox("Bedrooms", ["1", "2", "3", "4", "5+"])
|
44 |
+
bathrooms = st.selectbox("Bathrooms", ["1", "2", "3", "4", "5+"])
|
45 |
+
square_footage = st.selectbox("Square Footage", ["<1000 sqft", "1000-2000 sqft", "2000-3000 sqft", "3000-4000 sqft", "4000+ sqft"])
|
46 |
|
47 |
+
if st.button('Find Properties'):
|
48 |
messages = initial_messages.copy()
|
49 |
+
reply, updated_messages = InvestmentPropertyFinder(max_price, amenities, bedrooms, bathrooms, square_footage, messages)
|
|
|
50 |
st.write(reply)
|