import streamlit as st from groq import Groq import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from reportlab.pdfgen import canvas import os # --- Groq Setup --- GROQ_API_KEY = st.secrets["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"] # Store in HuggingFace secrets client = Groq(api_key=GROQ_API_KEY) def generate_estimate(area): prompt = f"Estimate the construction materials required for a {area} square feet residential plot. Include bricks, cement, sand, steel, and wood." chat_completion = client.chat.completions.create( messages=[{"role": "user", "content": prompt}], model="mixtral-8x7b-32768", ) return chat_completion.choices[0].message.content def create_3d_plot(area): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') l = int(area ** 0.5) ax.bar3d(1, 1, 0, l, l, 5, shade=True) plt.title("3D Layout (Conceptual)") plt.axis('off') return fig def generate_pdf(estimate_text, filename): c = canvas.Canvas(filename) c.setFont("Helvetica-Bold", 14) c.drawString(100, 800, "Construction Materials Estimate") text_obj = c.beginText(50, 770) text_obj.setFont("Helvetica", 12) for line in estimate_text.split('\n'): text_obj.textLine(line) c.drawText(text_obj) c.save() # --- UI --- st.set_page_config(page_title="SmartPlot Designer", layout="centered") st.title("SmartPlot Designer") st.markdown("Enter your plot area to generate a 3D layout and material estimation.") area = st.number_input("Enter total area (sq ft):", min_value=100) if st.button("Generate Plan"): with st.spinner("Generating 3D map and estimation..."): estimate = generate_estimate(area) fig = create_3d_plot(area) st.pyplot(fig) pdf_path = "estimate_report.pdf" generate_pdf(estimate, pdf_path) st.subheader("Material Estimation") st.text(estimate) with open(pdf_path, "rb") as f: st.download_button("Download PDF Report", f, file_name="plot_estimate.pdf")