nniehaus commited on
Commit
b00f915
·
verified ·
1 Parent(s): 776b8a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -2
app.py CHANGED
@@ -3,10 +3,19 @@ import openai
3
  import os
4
  import folium
5
  from streamlit_folium import st_folium
 
 
6
 
7
  # Ensure your OpenAI API key is set in your environment variables
8
  openai.api_key = os.environ["OPENAI_API_KEY"]
9
 
 
 
 
 
 
 
 
10
  initial_messages = [{
11
  "role": "system",
12
  "content": """
@@ -23,8 +32,11 @@ def call_openai_api(messages):
23
  def CustomChatGPT(preferences, messages):
24
  query = f"User preferences: {preferences}. Suggest suitable neighborhoods."
25
  messages.append({"role": "user", "content": query})
26
- response = call_openai_api(messages)
27
- ChatGPT_reply = response["choices"][0]["message"]["content"]
 
 
 
28
  messages.append({"role": "assistant", "content": ChatGPT_reply})
29
  return ChatGPT_reply, messages
30
 
@@ -70,6 +82,13 @@ with col2:
70
 
71
  st_folium(m, width=700, height=500)
72
 
 
 
 
 
 
 
 
73
  # Contact capture form
74
  st.markdown("<h2 style='text-align: center; color: black;'>Get in Touch for More Details ⬇️</h2>", unsafe_allow_html=True)
75
  with st.form(key='contact_form'):
 
3
  import os
4
  import folium
5
  from streamlit_folium import st_folium
6
+ import urllib.parse
7
+ import subprocess
8
 
9
  # Ensure your OpenAI API key is set in your environment variables
10
  openai.api_key = os.environ["OPENAI_API_KEY"]
11
 
12
+ # Ensure folium is installed
13
+ try:
14
+ import folium
15
+ except ModuleNotFoundError:
16
+ subprocess.check_call(["python", "-m", "pip", "install", "folium"])
17
+ import folium
18
+
19
  initial_messages = [{
20
  "role": "system",
21
  "content": """
 
32
  def CustomChatGPT(preferences, messages):
33
  query = f"User preferences: {preferences}. Suggest suitable neighborhoods."
34
  messages.append({"role": "user", "content": query})
35
+ response = openai.ChatCompletion.create(
36
+ model="gpt-3.5-turbo",
37
+ messages=messages
38
+ )
39
+ ChatGPT_reply = response.choices[0].message.content
40
  messages.append({"role": "assistant", "content": ChatGPT_reply})
41
  return ChatGPT_reply, messages
42
 
 
82
 
83
  st_folium(m, width=700, height=500)
84
 
85
+ # Add Zillow search links for neighborhoods
86
+ st.markdown("<h2 style='text-align: center; color: black;'>Search for Homes in Suggested Neighborhoods ⬇️</h2>", unsafe_allow_html=True)
87
+ for neighborhood in neighborhoods:
88
+ query = urllib.parse.quote(neighborhood["name"])
89
+ zillow_url = f"https://www.zillow.com/homes/{query}_rb/"
90
+ st.markdown(f"[Search for homes in {neighborhood['name']} on Zillow]({zillow_url})")
91
+
92
  # Contact capture form
93
  st.markdown("<h2 style='text-align: center; color: black;'>Get in Touch for More Details ⬇️</h2>", unsafe_allow_html=True)
94
  with st.form(key='contact_form'):