import gradio as gr import numpy as np import plotly.graph_objects as go from math import ceil def generate_building(plot_length, plot_width, floors, rooms, room_width, room_length, layout_style): total_area = plot_length * plot_width room_area = room_width * room_length feasible_rooms = min(rooms, int(total_area / room_area)) concrete = total_area * floors * 0.3 steel = total_area * floors * 40 bricks = total_area * floors * 60 fig = create_3d_model(plot_length, plot_width, floors, feasible_rooms, layout_style) report = f""" ### 🏗️ Construction Summary **Total Area**: {total_area:.1f} m² **Floors**: {floors} **Estimated Rooms**: {feasible_rooms} **Material Estimates:** - Concrete: {concrete:.1f} m³ - Steel: {steel:.1f} kg - Bricks: {bricks} units **Estimated Cost**: **${(concrete*120 + steel*1.5 + bricks*0.5):,.2f} USD** """ return fig, report def create_3d_model(length, width, floors, rooms, layout): fig = go.Figure() for floor in range(floors): fig.add_trace(go.Mesh3d( x=[0, length, length, 0], y=[0, 0, width, width], z=[floor*3]*4, i=[0], j=[1], k=[2], color='lightblue', opacity=0.5 )) fig.add_trace(go.Scatter3d( x=[0, 0, length, length, 0], y=[0, width, width, 0, 0], z=[0]*5, mode='lines', line=dict(width=5, color='darkred') )) fig.update_layout( scene=dict(aspectmode='manual', aspectratio=dict(x=1, y=width/length, z=0.4)), margin=dict(l=0, r=0, b=0, t=0) ) return fig with gr.Blocks(theme=gr.themes.Soft()) as app: gr.Markdown("## 🏡 **AI Architecture Designer**") gr.Markdown("Design smarter buildings with real-time 3D models and cost breakdowns.") with gr.Row(): with gr.Column(scale=1): with gr.Group(): gr.Markdown("### 📐 Building Parameters") plot_length = gr.Slider(5, 100, value=20, label="Plot Length (m)") plot_width = gr.Slider(5, 100, value=15, label="Plot Width (m)") floors = gr.Number(value=2, label="Number of Floors") rooms = gr.Number(value=4, label="Total Rooms") room_length = gr.Slider(3, 10, value=5, label="Room Length (m)") room_width = gr.Slider(3, 10, value=4, label="Room Width (m)") layout = gr.Radio(["Grid", "Open Plan", "L-Shaped"], label="Layout Style") submit = gr.Button("✨ Generate Design", variant="primary") with gr.Column(scale=1): with gr.Group(): gr.Markdown("### 🖼️ 3D Building Model") model = gr.Plot() with gr.Group(): gr.Markdown("### 📊 Materials & Cost Report") report = gr.Markdown() submit.click( generate_building, inputs=[plot_length, plot_width, floors, rooms, room_width, room_length, layout], outputs=[model, report] ) app.launch()