Spaces:
Runtime error

File size: 3,091 Bytes
f8638f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import streamlit as st
import plotly.graph_objects as go
from fpdf import FPDF
import openai

# Configure Groq API
openai.api_key = "your-groq-api-key"

# Page setup
st.set_page_config(page_title="Smart Construction Estimator", layout="centered")
st.markdown("<h1 style='text-align:center; color:#2e86de;'>🏗️ Smart Construction Estimator</h1>", unsafe_allow_html=True)
st.markdown("<p style='text-align:center;'>Enter plot and building details to generate 3D layout and material estimate.</p>", unsafe_allow_html=True)

# Inputs
plot_area = st.number_input("Enter Plot Area (sq ft):", min_value=100)
room_length = st.number_input("Room Length (ft):", min_value=5)
room_width = st.number_input("Room Width (ft):", min_value=5)
num_rooms = st.number_input("Total Number of Rooms:", min_value=1, step=1)
num_floors = st.number_input("Total Number of Floors:", min_value=1, step=1)

if st.button("Estimate"):
    with st.spinner("Generating 3D layout and material estimates..."):

        # 1. Ask Groq AI for construction estimate
        prompt = f"""
        Estimate construction materials for a plot of {plot_area} sq ft, with each room sized {room_length}x{room_width} ft,
        {num_rooms} total rooms, and {num_floors} floors. Provide quantities for bricks, cement, sand, steel, and any other major materials.
        """

        response = openai.ChatCompletion.create(
            model="mixtral-8x7b-32768",
            messages=[
                {"role": "system", "content": "You are a civil engineer estimating materials."},
                {"role": "user", "content": prompt}
            ]
        )
        ai_output = response['choices'][0]['message']['content']

        # 2. Generate 3D building map
        st.subheader("3D Building Layout")
        fig = go.Figure()

        room_height = 10  # ft
        for f in range(num_floors):
            z_base = f * room_height
            for r in range(num_rooms):
                x0 = (r % 5) * (room_length + 2)
                y0 = (r // 5) * (room_width + 2)
                fig.add_trace(go.Mesh3d(
                    x=[x0, x0+room_length, x0+room_length, x0, x0, x0+room_length, x0+room_length, x0],
                    y=[y0, y0, y0+room_width, y0+room_width, y0, y0, y0+room_width, y0+room_width],
                    z=[z_base]*4 + [z_base + room_height]*4,
                    color='skyblue', opacity=0.5
                ))

        fig.update_layout(scene=dict(
            xaxis_title='X (ft)',
            yaxis_title='Y (ft)',
            zaxis_title='Height (ft)'
        ))
        st.plotly_chart(fig, use_container_width=True)

        # 3. Generate PDF report
        pdf = FPDF()
        pdf.add_page()
        pdf.set_font("Arial", size=12)
        pdf.cell(200, 10, txt="Construction Material Estimation", ln=True, align='C')
        pdf.multi_cell(0, 10, txt=ai_output)

        pdf_file = "construction_report.pdf"
        pdf.output(pdf_file)

        # 4. Download link
        with open(pdf_file, "rb") as f:
            st.download_button("📄 Download PDF Report", f, file_name=pdf_file)