Spaces:
Sleeping
Sleeping
File size: 3,134 Bytes
5000cd9 4246afd 5000cd9 0c3fc34 5000cd9 0c3fc34 5000cd9 0c3fc34 4246afd 0c3fc34 4246afd 0c3fc34 5000cd9 0c3fc34 5000cd9 4246afd 0c3fc34 4246afd 0c3fc34 4246afd 0c3fc34 4246afd 0c3fc34 4246afd 5000cd9 0c3fc34 4246afd 5000cd9 4246afd 5000cd9 4246afd 5000cd9 4246afd 5000cd9 4246afd 5000cd9 4246afd 5000cd9 0c3fc34 5000cd9 0c3fc34 4246afd 5000cd9 4246afd 5000cd9 0c3fc34 92466dc 0c3fc34 92466dc 0c3fc34 | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | import streamlit as st
import requests
import csv
import io
# -------------------------------
# BuildSmart Estimator using Groq
# -------------------------------
# Page Configuration
st.set_page_config(page_title="BuildSmart Estimator", page_icon="๐๏ธ")
st.title("๐๏ธ BuildSmart Estimator")
st.subheader("Estimate construction materials based on your project details")
# Load Groq API Key securely from secrets
GROQ_API_KEY = st.secrets["GROQ_API_KEY"]
GROQ_MODEL = "llama3-70b-8192" # You can change this if Groq updates their models
# Form for user input
with st.form("estimator_form"):
total_area = st.number_input("Total Area (in square feet)", min_value=100, step=50)
floors = st.number_input("Number of Floors", min_value=1, step=1)
structure_type = st.selectbox("Structure Type", ["Residential", "Commercial", "Industrial"])
material_pref = st.selectbox("Material Preference", ["Cement & Bricks", "Steel & Concrete"])
location = st.text_input("Location", placeholder="e.g., Lahore, Karachi, etc.")
submitted = st.form_submit_button("Estimate Materials")
# Prompt builder for Groq
def build_prompt(area, floors, structure, material, loc):
return f"""
You are a construction estimator bot. Based on the following user inputs, estimate the quantity of construction materials needed.
Project:
- Total Area: {area} sq ft
- Floors: {floors}
- Structure: {structure}
- Material Preference: {material}
- Location: {loc}
Return the estimates in this format only:
Cement (bags):
Sand (cubic feet):
Bricks (units):
Steel (kg):
Crush (cubic feet):
Rori (cubic feet):
"""
# Call Groq API
def call_groq_api(prompt):
headers = {
"Authorization": f"Bearer {GROQ_API_KEY}",
"Content-Type": "application/json"
}
payload = {
"model": GROQ_MODEL,
"messages": [
{"role": "user", "content": prompt}
]
}
response = requests.post("https://api.groq.com/openai/v1/chat/completions", headers=headers, json=payload)
if response.status_code == 200:
return response.json()["choices"][0]["message"]["content"]
else:
return f"โ Error: {response.status_code} - {response.text}"
# When the form is submitted
if submitted:
prompt = build_prompt(total_area, floors, structure_type, material_pref, location)
with st.spinner("Generating estimate..."):
result = call_groq_api(prompt)
# Display result
st.markdown("### ๐ฆ Estimated Material Requirements")
st.text(result)
# CSV Download
csv_buffer = io.StringIO()
writer = csv.writer(csv_buffer)
writer.writerow(["Material", "Quantity"])
for line in result.strip().splitlines():
if ":" in line:
parts = line.split(":", 1)
writer.writerow([parts[0].strip(), parts[1].strip()])
st.download_button(
label="๐ฅ Download Estimate",
data=csv_buffer.getvalue(),
file_name="buildsmart_estimate.csv",
mime="text/csv"
)
# Footer
st.markdown("---")
st.caption("Built with โค๏ธ using Groq + Streamlit. Customize this app by editing `/streamlit_app.py`.")
|