Spaces:
Runtime error

File size: 2,035 Bytes
bf736a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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["GROQ_API_KEY"]  # 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")