Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from sentence_transformers import SentenceTransformer
|
4 |
+
import os
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
import io
|
7 |
+
from PIL import Image
|
8 |
+
import base64
|
9 |
+
import requests # To fetch online data
|
10 |
+
|
11 |
+
# --- Configuration ---
|
12 |
+
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
|
13 |
+
LLAMA3_MODEL = "llama3-8b-8192"
|
14 |
+
EMBEDDING_MODEL = "all-mpnet-base-v2"
|
15 |
+
embedding_model = SentenceTransformer(EMBEDDING_MODEL)
|
16 |
+
|
17 |
+
# --- Function to Fetch Islamabad Construction Material Prices ---
|
18 |
+
@st.cache_data(ttl=3600) # Cache for 1 hour
|
19 |
+
def get_islamabad_material_prices():
|
20 |
+
"""
|
21 |
+
Fetches current construction material prices for Islamabad.
|
22 |
+
This is a placeholder; in a real application, you would:
|
23 |
+
1. Scrape data from reliable online sources.
|
24 |
+
2. Use a paid API for real-time pricing.
|
25 |
+
3. Maintain an internal database updated with local prices.
|
26 |
+
|
27 |
+
For this example, we'll return a static dictionary.
|
28 |
+
"""
|
29 |
+
# **IMPORTANT:** Replace this with actual data fetching logic.
|
30 |
+
prices = {
|
31 |
+
"Cement (per bag)": 1200,
|
32 |
+
"Steel (per ton)": 220000,
|
33 |
+
"Bricks (per 1000)": 15000,
|
34 |
+
"Sand (per cubic foot)": 50,
|
35 |
+
"Crush (per cubic foot)": 70,
|
36 |
+
"Labor (per day - skilled)": 2500,
|
37 |
+
"Labor (per day - unskilled)": 1200,
|
38 |
+
"Paint (per liter)": 800,
|
39 |
+
"Plumbing Fixtures (average cost per set)": 15000,
|
40 |
+
"Electrical Wiring (per point)": 3000,
|
41 |
+
}
|
42 |
+
return pd.DataFrame(list(prices.items()), columns=['Material', 'Price (PKR)'])
|
43 |
+
|
44 |
+
# --- Function to Generate Realistic Floor Plan using AI (Placeholder) ---
|
45 |
+
def generate_realistic_floor_plan(num_rooms, num_bathrooms, num_living_rooms, total_area, num_car_porches):
|
46 |
+
"""
|
47 |
+
This is a placeholder for an AI-powered floor plan generator.
|
48 |
+
In a real application, you would integrate with an AI model
|
49 |
+
specialized in architectural design or use libraries that can
|
50 |
+
generate more complex layouts.
|
51 |
+
|
52 |
+
For this example, we'll return a textual description.
|
53 |
+
"""
|
54 |
+
prompt = f"Generate a realistic floor plan for a house with {num_rooms} rooms, {num_bathrooms} bathrooms, {num_living_rooms} living rooms, approximately {total_area} sq ft, and {num_car_porches} car porches."
|
55 |
+
response = f"**Floor Plan Description:** A well-laid-out house with {num_rooms} rooms strategically placed for privacy and access. The {num_living_rooms} living rooms offer spacious areas for family and guests. {num_bathrooms} bathrooms are conveniently located. The design incorporates {num_car_porches} car porches. The total area of {total_area} sq ft allows for comfortable living spaces and efficient flow."
|
56 |
+
return response
|
57 |
+
|
58 |
+
# --- Streamlit App ---
|
59 |
+
st.title("Realistic Construction Cost Estimator & AI Floor Plan (Islamabad)")
|
60 |
+
|
61 |
+
# --- Input Parameters ---
|
62 |
+
st.subheader("Project Details")
|
63 |
+
num_rooms = st.number_input("Number of Rooms", min_value=1, value=3)
|
64 |
+
total_area = st.number_input("Total Covered Area (sq ft)", min_value=100, value=1500)
|
65 |
+
num_bathrooms = st.number_input("Number of Bathrooms", min_value=1, value=2)
|
66 |
+
num_living_rooms = st.number_input("Number of Living Rooms", min_value=0, value=1)
|
67 |
+
num_car_porches = st.number_input("Number of Car Porches", min_value=0, value=1)
|
68 |
+
|
69 |
+
# --- Fetch Material Prices ---
|
70 |
+
material_prices_df = get_islamabad_material_prices()
|
71 |
+
st.subheader("Current Construction Material Prices in Islamabad")
|
72 |
+
st.dataframe(material_prices_df)
|
73 |
+
|
74 |
+
if st.button("Generate Estimate and Floor Plan"):
|
75 |
+
if not GROQ_API_KEY:
|
76 |
+
st.error("Please set the GROQ_API_KEY environment variable.")
|
77 |
+
else:
|
78 |
+
st.subheader("Estimated Construction Cost (Conceptual)")
|
79 |
+
st.info("This is a simplified estimate based on the provided material prices and does not include all construction aspects.")
|
80 |
+
|
81 |
+
# Basic cost calculation (very simplified)
|
82 |
+
estimated_cost = (
|
83 |
+
material_prices_df[material_prices_df['Material'] == 'Cement (per bag)']['Price (PKR)'].iloc[0] * (total_area / 100) + # Rough cement estimate
|
84 |
+
material_prices_df[material_prices_df['Material'] == 'Steel (per ton)']['Price (PKR)'].iloc[0] * (total_area / 500) + # Rough steel estimate
|
85 |
+
material_prices_df[material_prices_df['Material'] == 'Bricks (per 1000)']['Price (PKR)'].iloc[0] * (total_area / 10) + # Rough brick estimate
|
86 |
+
material_prices_df[material_prices_df['Material'] == 'Labor (per day - skilled)']['Price (PKR)'].iloc[0] * (num_rooms * 10) # Very rough labor
|
87 |
+
)
|
88 |
+
st.write(f"**Estimated Total Cost (Conceptual):** {estimated_cost:,.2f} PKR")
|
89 |
+
st.warning("This is a highly simplified cost. A detailed BOQ requires a comprehensive understanding of the design and material quantities.")
|
90 |
+
|
91 |
+
# --- Generate Realistic Floor Plan (Placeholder) ---
|
92 |
+
st.subheader("Realistic Floor Plan (AI Generated - Conceptual)")
|
93 |
+
floor_plan_description = generate_realistic_floor_plan(num_rooms, num_bathrooms, num_living_rooms, total_area, num_car_porches)
|
94 |
+
st.write(floor_plan_description)
|
95 |
+
|
96 |
+
st.info("AI-powered realistic floor plan generation is a complex task. This output is a textual description as a placeholder. Integrating with advanced AI models or architectural design tools would be required for a visual and detailed floor plan.")
|