Syed200 commited on
Commit
5fa1da8
Β·
verified Β·
1 Parent(s): b7792f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -1
app.py CHANGED
@@ -1,4 +1,86 @@
1
- import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import math
3
 
4
  st.title("Scientific Calculator")
 
1
+ import streamlit as stimport streamlit as st
2
+ import requests
3
+ import json
4
+
5
+ # ------------------- CONFIGURATION ------------------- #
6
+ API_URL = "https://api-inference.huggingface.co/models/HuggingFaceTB/SmolVLM-256M-Instruct"
7
+ API_TOKEN = "YOUR_HUGGINGFACE_API_TOKEN" # Replace with your actual Hugging Face API token
8
+
9
+ headers = {"Authorization": f"Bearer {API_TOKEN}"}
10
+
11
+ # ------------------- FUNCTION TO QUERY MODEL ------------------- #
12
+ def query_huggingface_api(prompt):
13
+ payload = {
14
+ "inputs": prompt,
15
+ "parameters": {
16
+ "max_new_tokens": 200,
17
+ "temperature": 0.7
18
+ }
19
+ }
20
+ response = requests.post(API_URL, headers=headers, json=payload)
21
+ if response.status_code != 200:
22
+ st.error(f"API Error {response.status_code}: {response.text}")
23
+ return None
24
+ return response.json()
25
+
26
+ # ------------------- STREAMLIT APP ------------------- #
27
+ st.set_page_config(page_title="Build Smart Estimator", page_icon="πŸ—οΈ")
28
+
29
+ # App title
30
+ st.title("πŸ—οΈ Build Smart Estimator")
31
+ st.markdown("""
32
+ Welcome to **Build Smart Estimator** β€” an intelligent tool to help you estimate construction materials based on your project details!
33
+ """)
34
+
35
+ # Input Fields
36
+ st.header("Enter Your Project Details")
37
+
38
+ col1, col2 = st.columns(2)
39
+
40
+ with col1:
41
+ total_area = st.number_input("🏠 Total Area (in square meters)", min_value=10.0, step=10.0)
42
+ num_floors = st.number_input("🏒 Number of Floors", min_value=1, step=1)
43
+
44
+ with col2:
45
+ structure_type = st.selectbox("πŸ—οΈ Structure Type", options=[
46
+ "Residential", "Commercial", "Industrial", "Warehouse"
47
+ ])
48
+ material_pref = st.multiselect(
49
+ "🧱 Material Preference (Select one or more)",
50
+ options=["Cement", "Bricks", "Steel", "Concrete"]
51
+ )
52
+
53
+ # Submit button
54
+ if st.button("Estimate Materials πŸš€"):
55
+ if total_area <= 0 or num_floors <= 0:
56
+ st.warning("Please enter valid Total Area and Number of Floors.")
57
+ elif not material_pref:
58
+ st.warning("Please select at least one Material Preference.")
59
+ else:
60
+ # Prepare input prompt for the model
61
+ prompt = (
62
+ f"Estimate the required quantities of {', '.join(material_pref)} "
63
+ f"for a {structure_type.lower()} building with a total area of {total_area} square meters "
64
+ f"and {num_floors} floors. Provide the estimates in a clear and concise manner."
65
+ )
66
+
67
+ st.info("Sending your inputs to the smart estimator...")
68
+
69
+ # Call Hugging Face model
70
+ response = query_huggingface_api(prompt)
71
+
72
+ if response:
73
+ st.subheader("πŸ“Š Estimated Material Requirements")
74
+ # Assuming the model returns a list with a 'generated_text' field
75
+ if isinstance(response, list) and 'generated_text' in response[0]:
76
+ st.write(response[0]['generated_text'])
77
+ else:
78
+ st.write(response)
79
+
80
+ # Footer
81
+ st.markdown("---")
82
+ st.caption("Β© 2025 Build Smart Estimator | Powered by Streamlit & Hugging Face")
83
+
84
  import math
85
 
86
  st.title("Scientific Calculator")