File size: 5,786 Bytes
bef578a
5fa1da8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406bd71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import streamlit  as st
import requests
import json

# ------------------- CONFIGURATION ------------------- #
API_URL = "https://api-inference.huggingface.co/models/HuggingFaceTB/SmolVLM-256M-Instruct"
API_TOKEN = "YOUR_HUGGINGFACE_API_TOKEN"  # Replace with your actual Hugging Face API token

headers = {"Authorization": f"Bearer {API_TOKEN}"}

# ------------------- FUNCTION TO QUERY MODEL ------------------- #
def query_huggingface_api(prompt):
    payload = {
        "inputs": prompt,
        "parameters": {
            "max_new_tokens": 200,
            "temperature": 0.7
        }
    }
    response = requests.post(API_URL, headers=headers, json=payload)
    if response.status_code != 200:
        st.error(f"API Error {response.status_code}: {response.text}")
        return None
    return response.json()

# ------------------- STREAMLIT APP ------------------- #
st.set_page_config(page_title="Build Smart Estimator", page_icon="πŸ—οΈ")

# App title
st.title("πŸ—οΈ Build Smart Estimator")
st.markdown("""
Welcome to **Build Smart Estimator** β€” an intelligent tool to help you estimate construction materials based on your project details!
""")

# Input Fields
st.header("Enter Your Project Details")

col1, col2 = st.columns(2)

with col1:
    total_area = st.number_input("🏠 Total Area (in square meters)", min_value=10.0, step=10.0)
    num_floors = st.number_input("🏒 Number of Floors", min_value=1, step=1)

with col2:
    structure_type = st.selectbox("πŸ—οΈ Structure Type", options=[
        "Residential", "Commercial", "Industrial", "Warehouse"
    ])
    material_pref = st.multiselect(
        "🧱 Material Preference (Select one or more)",
        options=["Cement", "Bricks", "Steel", "Concrete"]
    )

# Submit button
if st.button("Estimate Materials πŸš€"):
    if total_area <= 0 or num_floors <= 0:
        st.warning("Please enter valid Total Area and Number of Floors.")
    elif not material_pref:
        st.warning("Please select at least one Material Preference.")
    else:
        # Prepare input prompt for the model
        prompt = (
            f"Estimate the required quantities of {', '.join(material_pref)} "
            f"for a {structure_type.lower()} building with a total area of {total_area} square meters "
            f"and {num_floors} floors. Provide the estimates in a clear and concise manner."
        )

        st.info("Sending your inputs to the smart estimator...")

        # Call Hugging Face model
        response = query_huggingface_api(prompt)

        if response:
            st.subheader("πŸ“Š Estimated Material Requirements")
            # Assuming the model returns a list with a 'generated_text' field
            if isinstance(response, list) and 'generated_text' in response[0]:
                st.write(response[0]['generated_text'])
            else:
                st.write(response)

# Footer
st.markdown("---")
st.caption("Β© 2025 Build Smart Estimator | Powered by Streamlit & Hugging Face")

import math

st.title("Scientific Calculator")

# All operations
operations = [
    "+", "-", "*", "/", "^ (power)", "% (modulus)", "// (floor division)",
    "√ (square root)", "log10", "ln (natural log)", "n! (factorial)",
    "sin", "cos", "tan", "exp (e^x)"
]

operation = st.selectbox("Select operation", operations)

# Input fields
num1 = st.number_input("Enter first number", format="%.4f")

# Only show num2 for operations that need two inputs
if operation in ["+", "-", "*", "/", "^ (power)", "% (modulus)", "// (floor division)"]:
    num2 = st.number_input("Enter second number", format="%.4f")
else:
    num2 = None

result = None
error = None

if st.button("Calculate"):
    try:
        if operation == "+":
            result = num1 + num2
        elif operation == "-":
            result = num1 - num2
        elif operation == "*":
            result = num1 * num2
        elif operation == "/":
            if num2 != 0:
                result = num1 / num2
            else:
                error = "Cannot divide by zero"
        elif operation == "^ (power)":
            result = num1 ** num2
        elif operation == "% (modulus)":
            if num2 != 0:
                result = num1 % num2
            else:
                error = "Cannot perform modulus by zero"
        elif operation == "// (floor division)":
            if num2 != 0:
                result = num1 // num2
            else:
                error = "Cannot perform floor division by zero"
        elif operation == "√ (square root)":
            if num1 >= 0:
                result = math.sqrt(num1)
            else:
                error = "Cannot take square root of a negative number"
        elif operation == "log10":
            if num1 > 0:
                result = math.log10(num1)
            else:
                error = "Log10 undefined for non-positive numbers"
        elif operation == "ln (natural log)":
            if num1 > 0:
                result = math.log(num1)
            else:
                error = "Natural log undefined for non-positive numbers"
        elif operation == "n! (factorial)":
            if num1 >= 0 and num1 == int(num1):
                result = math.factorial(int(num1))
            else:
                error = "Factorial only defined for non-negative integers"
        elif operation == "sin":
            result = math.sin(math.radians(num1))
        elif operation == "cos":
            result = math.cos(math.radians(num1))
        elif operation == "tan":
            result = math.tan(math.radians(num1))
        elif operation == "exp (e^x)":
            result = math.exp(num1)
    except Exception as e:
        error = str(e)

    if error:
        st.error(error)
    else:
        st.success(f"Result: {result:.6f}")