Spaces:
Runtime error

Plot_Designer11 / app.py
Ai1996's picture
Create app.py
f8638f9 verified
Raw History Blame Contribute Delete
3.09 kB
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)