Spaces:
Runtime error
Runtime error
Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475import streamlit as stimport plotly.graph_objects as gofrom fpdf import FPDFimport openai
# Configure Groq APIopenai.api_key = "your-groq-api-key"
# Page setupst.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)
# Inputsplot_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)app.pyAdded+75