Aizaz96 commited on
Commit
5a6a4b8
Β·
verified Β·
1 Parent(s): b9f7ed7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +103 -29
app.py CHANGED
@@ -2,6 +2,9 @@ import streamlit as st
2
  from groq import Groq
3
  import json
4
  import os
 
 
 
5
  from dotenv import load_dotenv
6
 
7
  # Load environment variables
@@ -15,7 +18,7 @@ except Exception as e:
15
 
16
  # App title
17
  st.title("🏠 AI Architect: Home Planner")
18
- st.markdown("Get a professionally designed house plan in seconds!")
19
 
20
  # --- USER INPUTS ---
21
  st.header("πŸ“ Step 1: Plot Details")
@@ -43,51 +46,122 @@ lawn = st.checkbox("Lawn/Garden 🌳")
43
  # --- AI GENERATION ---
44
  if st.button("Generate Professional Plan"):
45
  prompt = f"""
46
- Design a house plan for a {plot_length}x{plot_width} ft plot following architectural best practices:
47
- - Space Efficiency: Minimize wasted space, use standard dimensions
48
- - Room Requirements:
49
- - {master_bed} master bedroom(s) (min 12x14 ft)
50
- - {bedrooms} standard bedroom(s) (min 10x12 ft)
51
- - {kitchens} kitchen(s) (min 8x10 ft)
52
- - {study_rooms} study room(s) (min 8x8 ft)
53
- - {lounges} lounge(s) (min 12x16 ft)
54
- - Washrooms:
55
- - {attached_washrooms} attached (min 6x8 ft)
56
- - {common_washrooms} common (min 5x7 ft)
57
- - Extras: {"Parking (min 12x20 ft)" if parking else ""}, {"Lawn" if lawn else ""}
58
-
59
- Respond in JSON with:
60
- 1. '2d_layout': Scaled room placements with dimensions
61
- 2. '3d_tips': How to visualize flow
62
- 3. 'materials': Cost-effective material suggestions
63
- 4. 'warnings': Violations of standard dimensions
64
  """
65
 
66
  try:
67
  response = client.chat.completions.create(
68
  messages=[{"role": "user", "content": prompt}],
69
- model="llama3-70b-8192", # Updated to currently supported model
70
  response_format={"type": "json_object"}
71
  )
72
  plan = json.loads(response.choices[0].message.content)
73
 
74
  st.success("βœ… Professionally Designed Plan Generated!")
75
 
76
- st.header("πŸ“ 2D Layout")
77
- st.write(plan["2d_layout"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
- st.header("✨ 3D Flow Tips")
80
- st.write(plan["3d_tips"])
 
 
81
 
82
- st.header("πŸ—οΈ Material Recommendations")
83
- st.write(plan["materials"])
 
84
 
85
- st.header("⚠️ Professional Warnings")
86
- st.write(plan.get("warnings", "No violations detected."))
 
87
 
88
  except Exception as e:
89
  st.error(f"Error: {e}. Check your API key or try again later.")
90
 
91
  # Footer
92
  st.markdown("---")
93
- st.caption("βœ… Follows standard architectural dimensions | Powered by Groq API")
 
2
  from groq import Groq
3
  import json
4
  import os
5
+ import matplotlib.pyplot as plt
6
+ import numpy as np
7
+ import plotly.graph_objects as go
8
  from dotenv import load_dotenv
9
 
10
  # Load environment variables
 
18
 
19
  # App title
20
  st.title("🏠 AI Architect: Home Planner")
21
+ st.markdown("Get an easy-to-understand house plan with 2D/3D visualization!")
22
 
23
  # --- USER INPUTS ---
24
  st.header("πŸ“ Step 1: Plot Details")
 
46
  # --- AI GENERATION ---
47
  if st.button("Generate Professional Plan"):
48
  prompt = f"""
49
+ Design a house plan for a {plot_length}x{plot_width} ft plot following architectural best practices.
50
+ Return response in JSON format with:
51
+ 1. 'floor_plan': 2D layout with room dimensions and positions
52
+ 2. 'visualization_tips': Simple tips for visualizing the space
53
+ 3. 'material_suggestions': Recommended materials
54
+ 4. 'warnings': Any size violations
 
 
 
 
 
 
 
 
 
 
 
 
55
  """
56
 
57
  try:
58
  response = client.chat.completions.create(
59
  messages=[{"role": "user", "content": prompt}],
60
+ model="llama3-70b-8192",
61
  response_format={"type": "json_object"}
62
  )
63
  plan = json.loads(response.choices[0].message.content)
64
 
65
  st.success("βœ… Professionally Designed Plan Generated!")
66
 
67
+ # --- 2D Visualization ---
68
+ st.header("πŸ“ 2D Floor Plan")
69
+
70
+ # Create figure
71
+ fig, ax = plt.subplots(figsize=(10, 8))
72
+
73
+ # Plot rooms
74
+ for room in plan['floor_plan']['rooms']:
75
+ rect = plt.Rectangle(
76
+ (room['x'], room['y']),
77
+ room['width'],
78
+ room['height'],
79
+ linewidth=2,
80
+ edgecolor='black',
81
+ facecolor=np.random.rand(3,))
82
+ ax.add_patch(rect)
83
+
84
+ # Add room label
85
+ center_x = room['x'] + room['width']/2
86
+ center_y = room['y'] + room['height']/2
87
+ ax.text(center_x, center_y,
88
+ f"{room['width']}x{room['height']}ft",
89
+ ha='center', va='center', fontsize=8)
90
+
91
+ # Plot washrooms
92
+ for washroom in plan['floor_plan']['washrooms']:
93
+ rect = plt.Rectangle(
94
+ (washroom['x'], washroom['y']),
95
+ washroom['width'],
96
+ washroom['height'],
97
+ linewidth=2,
98
+ edgecolor='black',
99
+ facecolor='lightblue',
100
+ hatch='/')
101
+ ax.add_patch(rect)
102
+
103
+ # Set plot limits and labels
104
+ ax.set_xlim(0, plot_length)
105
+ ax.set_ylim(0, plot_width)
106
+ ax.set_aspect('equal')
107
+ ax.set_xlabel('Length (ft)')
108
+ ax.set_ylabel('Width (ft)')
109
+ ax.set_title('2D Floor Plan')
110
+ st.pyplot(fig)
111
+
112
+ # --- 3D Visualization ---
113
+ st.header("✨ 3D Visualization")
114
+
115
+ # Create simple 3D representation
116
+ fig_3d = go.Figure()
117
+
118
+ # Add rooms as 3D boxes
119
+ for room in plan['floor_plan']['rooms']:
120
+ fig_3d.add_trace(go.Mesh3d(
121
+ x=[room['x'], room['x'], room['x']+room['width'], room['x']+room['width'], room['x']],
122
+ y=[room['y'], room['y']+room['height'], room['y']+room['height'], room['y'], room['y']],
123
+ z=[0, 0, 0, 0, 0],
124
+ opacity=0.8,
125
+ color='lightgray',
126
+ showscale=False
127
+ ))
128
+ fig_3d.add_trace(go.Mesh3d(
129
+ x=[room['x'], room['x'], room['x']+room['width'], room['x']+room['width'], room['x']],
130
+ y=[room['y'], room['y']+room['height'], room['y']+room['height'], room['y'], room['y']],
131
+ z=[10, 10, 10, 10, 10],
132
+ opacity=0.8,
133
+ color='lightgray',
134
+ showscale=False
135
+ ))
136
+
137
+ fig_3d.update_layout(
138
+ scene=dict(
139
+ xaxis=dict(title='Length (ft)'),
140
+ yaxis=dict(title='Width (ft)'),
141
+ zaxis=dict(title='Height (ft)'),
142
+ aspectmode='manual',
143
+ aspectratio=dict(x=1, y=plot_width/plot_length, z=0.2)
144
+ ),
145
+ margin=dict(r=20, l=10, b=10, t=30)
146
+ )
147
+ st.plotly_chart(fig_3d)
148
 
149
+ # --- Additional Information ---
150
+ st.header("πŸ’‘ Visualization Tips")
151
+ for tip in plan['visualization_tips']:
152
+ st.markdown(f"- {tip}")
153
 
154
+ st.header("πŸ—οΈ Material Suggestions")
155
+ for material in plan['material_suggestions']:
156
+ st.markdown(f"- {material}")
157
 
158
+ st.header("⚠️ Warnings")
159
+ for warning in plan['warnings']:
160
+ st.markdown(f"- ⚠️ {warning}")
161
 
162
  except Exception as e:
163
  st.error(f"Error: {e}. Check your API key or try again later.")
164
 
165
  # Footer
166
  st.markdown("---")
167
+ st.caption("βœ… Easy-to-understand visualizations | Powered by Groq API")