Spaces:
Runtime error
Runtime error
Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import streamlit as stfrom groq import Groqimport matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3Dfrom reportlab.pdfgen import canvasimport os
# --- Groq Setup ---GROQ_API_KEY = st.secrets["GROQ_API_KEY"] # Store in HuggingFace secretsclient = 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")app.pyAdded+60