nniehaus commited on
Commit
623debf
·
verified ·
1 Parent(s): 6394bb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +153 -37
app.py CHANGED
@@ -11,15 +11,15 @@ MODEL_NAME = "gpt-4o" # Use the latest model with vision capabilities
11
 
12
  # Set API key from Hugging Face secrets
13
  try:
14
- API_KEY = st.secrets["OPENAI_API_KEY"]
15
  except:
16
- API_KEY = "" # Will be prompted to enter API key if not in secrets
17
 
18
  # Session state initialization
19
  if "uploaded_images" not in st.session_state:
20
  st.session_state["uploaded_images"] = []
21
  if "api_key" not in st.session_state:
22
- st.session_state["api_key"] = API_KEY
23
 
24
  # Function to encode image to base64
25
  def encode_image(image):
@@ -45,7 +45,11 @@ def analyze_home_photos(images, property_type, price_range, timeframe, additiona
45
 
46
  # Construct the message content
47
  content = [
48
- {"type": "text", "text": f"Analyze these home photos and recommend improvements to maximize value for a {property_type} in the {price_range} range. The owner plans to sell within {timeframe}. {additional_details}"}
 
 
 
 
49
  ]
50
 
51
  # Add images to the message with proper format for GPT-4o
@@ -59,34 +63,45 @@ def analyze_home_photos(images, property_type, price_range, timeframe, additiona
59
  }
60
  })
61
 
62
- # Create the API payload
63
  payload = {
64
  "model": MODEL_NAME,
65
  "messages": [
66
  {
67
  "role": "system",
68
- "content": """You are an AI assistant that helps homeowners maximize their property value before selling.
69
- You analyze home photos and provide customized recommendations for high-ROI improvements.
70
-
71
- Provide recommendations in these categories:
72
- 1. Quick Wins (1-2 days, low cost)
73
- 2. Weekend Projects (1 week, medium cost)
74
- 3. Major Improvements (if warranted, higher cost but higher ROI)
75
-
76
- For each recommendation, explain the potential value impact and approximate ROI.
77
- Be specific based on what you can see in the photos.
78
- Avoid generic advice - focus on what's visible in the images provided.
79
-
80
- Always add the following text to the beginning of your response:
81
- 'Here are your personalized home improvement recommendations! If you found this tool helpful, visit www.myeverydayai.com to see more AI tools like this that can help with your real estate needs!'
82
- """
 
 
 
 
 
 
 
 
 
 
 
83
  },
84
  {
85
  "role": "user",
86
  "content": content
87
  }
88
  ],
89
- "max_tokens": 1500
90
  }
91
 
92
  try:
@@ -119,7 +134,7 @@ def analyze_home_photos(images, property_type, price_range, timeframe, additiona
119
  # Main application
120
  st.title("Home Value Maximizer 🏡")
121
 
122
- # Custom CSS for better appearance
123
  st.markdown("""
124
  <style>
125
  .main .block-container {padding-bottom: 5rem !important; max-width: 100% !important;}
@@ -129,6 +144,47 @@ st.markdown("""
129
  h2, h3 {font-size: 1.2rem !important;}
130
  .stButton button {width: 100% !important; height: 3rem !important;}
131
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  </style>
133
  """, unsafe_allow_html=True)
134
 
@@ -181,6 +237,27 @@ with col1:
181
  placeholder="Describe specific areas you're considering renovating or any concerns.",
182
  height=80)
183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  # Analysis button
185
  analyze_button = st.button('🔍 Analyze My Home',
186
  use_container_width=True,
@@ -193,22 +270,56 @@ with col1:
193
  st.warning("Please enter your OpenAI API key to enable analysis.")
194
 
195
  with col2:
196
- st.subheader("💡 Improvement Recommendations")
197
- result_placeholder = st.empty()
198
-
199
- if analyze_button:
200
- with st.spinner("Analyzing your home and generating recommendations..."):
201
- result = analyze_home_photos(
202
- st.session_state["uploaded_images"],
203
- property_type,
204
- price_range,
205
- timeframe,
206
- additional_details,
207
- st.session_state["api_key"]
208
- )
209
- result_placeholder.markdown(result)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  else:
211
- result_placeholder.markdown("**Results will appear here after you submit your home photos and details**")
212
 
213
  # Disclaimer section
214
  st.markdown("---")
@@ -217,5 +328,10 @@ with st.expander("📜 **Disclaimer**"):
217
  **Disclaimer:**
218
  This Home Value Maximizer tool provides recommendations based on AI analysis of your home photos.
219
  Results are for **informational purposes only** and may not be accurate for your specific situation.
 
 
 
 
 
220
  Please consult with real estate professionals before making significant investments.
221
  """)
 
11
 
12
  # Set API key from Hugging Face secrets
13
  try:
14
+ OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]
15
  except:
16
+ OPENAI_API_KEY = "" # Will be prompted to enter API key if not in secrets
17
 
18
  # Session state initialization
19
  if "uploaded_images" not in st.session_state:
20
  st.session_state["uploaded_images"] = []
21
  if "api_key" not in st.session_state:
22
+ st.session_state["api_key"] = OPENAI_API_KEY
23
 
24
  # Function to encode image to base64
25
  def encode_image(image):
 
45
 
46
  # Construct the message content
47
  content = [
48
+ {"type": "text", "text": f"""Analyze these home photos and recommend improvements to maximize value for a {property_type} in the {price_range} range.
49
+ The owner plans to sell within {timeframe}. {additional_details}
50
+
51
+ Be highly specific about what you see in the images and provide detailed analysis.
52
+ """}
53
  ]
54
 
55
  # Add images to the message with proper format for GPT-4o
 
63
  }
64
  })
65
 
66
+ # Create the API payload with enhanced system prompt
67
  payload = {
68
  "model": MODEL_NAME,
69
  "messages": [
70
  {
71
  "role": "system",
72
+ "content": """You are an expert real estate advisor and home improvement specialist who helps homeowners maximize their property value before selling. You analyze home photos and provide customized, detailed recommendations.
73
+
74
+ For each recommendation, provide:
75
+ 1. Detailed description of what to improve based specifically on what you see in the photos
76
+ 2. Estimated timeline (in days/weeks) to complete each project
77
+ 3. Expected ROI percentage and dollar value increase
78
+ 4. Approximate cost range for each improvement
79
+ 5. Priority level (High/Medium/Low)
80
+ 6. Whether this is DIY-friendly or requires professionals
81
+
82
+ Organize recommendations into these categories:
83
+ 1. Quick Wins (1-3 days, low cost): Focus on immediate visual impact
84
+ 2. Weekend Projects (1-2 weeks, medium cost): Higher impact improvements
85
+ 3. Major Improvements (2+ weeks, higher cost but higher ROI): Significant value-adding projects
86
+
87
+ Also include:
88
+ - A suggested implementation schedule based on the owner's selling timeframe
89
+ - Specific improvements to AVOID that would NOT provide good ROI for this property type
90
+ - Tailored advice about which improvements are most important given the selling timeline
91
+ - Visual staging recommendations to showcase the home's best features
92
+
93
+ Be extremely specific based on what you can actually see in the photos provided. Avoid generic advice.
94
+
95
+ Always add the following text to the beginning of your response:
96
+ 'Here are your personalized home improvement recommendations! If you found this tool helpful, visit www.myeverydayai.com to see more AI tools like this that can help with your real estate needs!'
97
+ """
98
  },
99
  {
100
  "role": "user",
101
  "content": content
102
  }
103
  ],
104
+ "max_tokens": 2000
105
  }
106
 
107
  try:
 
134
  # Main application
135
  st.title("Home Value Maximizer 🏡")
136
 
137
+ # Custom CSS for better appearance and readability
138
  st.markdown("""
139
  <style>
140
  .main .block-container {padding-bottom: 5rem !important; max-width: 100% !important;}
 
144
  h2, h3 {font-size: 1.2rem !important;}
145
  .stButton button {width: 100% !important; height: 3rem !important;}
146
  }
147
+
148
+ /* Custom styling for recommendation sections */
149
+ .recommendation-section {
150
+ margin-top: 1.5rem;
151
+ padding: 1rem;
152
+ border-radius: 0.5rem;
153
+ background-color: #f8f9fa;
154
+ }
155
+
156
+ .quick-wins {
157
+ border-left: 4px solid #28a745;
158
+ }
159
+
160
+ .weekend-projects {
161
+ border-left: 4px solid #fd7e14;
162
+ }
163
+
164
+ .major-improvements {
165
+ border-left: 4px solid #dc3545;
166
+ }
167
+
168
+ .avoid-section {
169
+ border-left: 4px solid #6c757d;
170
+ }
171
+
172
+ .schedule-section {
173
+ border-left: 4px solid #007bff;
174
+ }
175
+
176
+ /* For better readability of recommendations */
177
+ .stMarkdown {
178
+ line-height: 1.6;
179
+ }
180
+
181
+ /* Better readability for the analysis results */
182
+ .results-container {
183
+ padding: 1.5rem;
184
+ background-color: white;
185
+ border-radius: 0.5rem;
186
+ box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
187
+ }
188
  </style>
189
  """, unsafe_allow_html=True)
190
 
 
237
  placeholder="Describe specific areas you're considering renovating or any concerns.",
238
  height=80)
239
 
240
+ # Additional preferences
241
+ st.subheader("💰 Budget & Preferences")
242
+
243
+ max_budget = st.slider("Maximum budget for improvements ($)",
244
+ min_value=1000,
245
+ max_value=50000,
246
+ value=10000,
247
+ step=1000)
248
+
249
+ improvement_focus = st.multiselect(
250
+ "Areas to focus on (optional)",
251
+ ["Curb appeal", "Kitchen", "Bathroom", "Living spaces", "Outdoor areas", "Storage solutions", "Energy efficiency"],
252
+ default=["Curb appeal", "Kitchen", "Bathroom"]
253
+ )
254
+
255
+ diy_preference = st.select_slider(
256
+ "DIY Preference",
257
+ options=["Professional work only", "Mix of DIY and professional", "Mostly DIY if possible"],
258
+ value="Mix of DIY and professional"
259
+ )
260
+
261
  # Analysis button
262
  analyze_button = st.button('🔍 Analyze My Home',
263
  use_container_width=True,
 
270
  st.warning("Please enter your OpenAI API key to enable analysis.")
271
 
272
  with col2:
273
+ st.subheader("💡 Detailed Improvement Recommendations")
274
+
275
+ # Add tabs for different sections of recommendations
276
+ if analyze_button or "analysis_result" in st.session_state:
277
+ tabs = st.tabs(["All Recommendations", "Quick Wins", "Weekend Projects", "Major Improvements", "Implementation Schedule", "What to Avoid"])
278
+
279
+ # Process analysis if button pressed
280
+ if analyze_button:
281
+ with st.spinner("Analyzing your home and generating detailed recommendations..."):
282
+ analysis_text = analyze_home_photos(
283
+ st.session_state["uploaded_images"],
284
+ property_type,
285
+ price_range,
286
+ timeframe,
287
+ f"Budget: ${max_budget}. Focus areas: {', '.join(improvement_focus)}. DIY preference: {diy_preference}. {additional_details}",
288
+ st.session_state["api_key"]
289
+ )
290
+ st.session_state["analysis_result"] = analysis_text
291
+
292
+ # Display results in tabs
293
+ if "analysis_result" in st.session_state:
294
+ result = st.session_state["analysis_result"]
295
+
296
+ # Display full analysis in first tab
297
+ with tabs[0]:
298
+ st.markdown(f'<div class="results-container">{result}</div>', unsafe_allow_html=True)
299
+
300
+ # You can add code here to parse the result and display in other tabs
301
+ # For now we'll just put placeholder text
302
+ with tabs[1]:
303
+ st.markdown("### Quick Wins (1-3 days)")
304
+ st.info("Quick wins section from the analysis above")
305
+
306
+ with tabs[2]:
307
+ st.markdown("### Weekend Projects (1-2 weeks)")
308
+ st.info("Weekend projects section from the analysis above")
309
+
310
+ with tabs[3]:
311
+ st.markdown("### Major Improvements (2+ weeks)")
312
+ st.info("Major improvements section from the analysis above")
313
+
314
+ with tabs[4]:
315
+ st.markdown("### Implementation Schedule")
316
+ st.info("Schedule section from the analysis above")
317
+
318
+ with tabs[5]:
319
+ st.markdown("### What to Avoid")
320
+ st.info("Improvements to avoid section from the analysis above")
321
  else:
322
+ st.markdown('<div class="results-container">**Recommendations will appear here after you submit your home photos and details**</div>', unsafe_allow_html=True)
323
 
324
  # Disclaimer section
325
  st.markdown("---")
 
328
  **Disclaimer:**
329
  This Home Value Maximizer tool provides recommendations based on AI analysis of your home photos.
330
  Results are for **informational purposes only** and may not be accurate for your specific situation.
331
+
332
+ - **Cost estimates** are approximate and can vary based on your location, materials chosen, and contractor rates
333
+ - **ROI estimates** are based on general real estate trends and may differ in your specific market
334
+ - **Timeline estimates** assume standard work schedules and availability of materials
335
+
336
  Please consult with real estate professionals before making significant investments.
337
  """)