BeyzaTopbas commited on
Commit
323718e
·
verified ·
1 Parent(s): e63b4b0

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +58 -30
src/streamlit_app.py CHANGED
@@ -1,40 +1,68 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
 
 
 
8
 
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
 
 
 
 
 
12
 
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
 
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
 
 
18
 
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
 
 
 
22
 
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
 
 
 
 
 
25
 
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
 
 
 
 
 
 
31
  })
32
 
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+ import os
5
 
6
+ # ======================
7
+ # LOAD MODEL
8
+ # ======================
9
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
10
+ model = joblib.load(os.path.join(BASE_DIR, "house_price_model.pkl"))
11
 
12
+ # ======================
13
+ # PAGE CONFIG
14
+ # ======================
15
+ st.set_page_config(
16
+ page_title="House Price Prediction",
17
+ page_icon="🏡",
18
+ layout="centered"
19
+ )
20
 
21
+ st.title("🏡 House Price Prediction")
22
+ st.write("Predict the house price based on key features")
23
 
24
+ # ======================
25
+ # SIDEBAR INPUTS
26
+ # ======================
27
+ st.sidebar.header("House Features")
28
 
29
+ OverallQual = st.sidebar.slider("Overall Quality", 1, 10, 5)
30
+ GrLivArea = st.sidebar.number_input("Above Ground Living Area (sq ft)", 300, 5000, 1500)
31
+ GarageCars = st.sidebar.slider("Garage Capacity (cars)", 0, 4, 2)
32
+ TotalBsmtSF = st.sidebar.number_input("Total Basement Area (sq ft)", 0, 3000, 800)
33
+ FullBath = st.sidebar.slider("Full Bathrooms", 0, 4, 2)
34
+ YearBuilt = st.sidebar.slider("Year Built", 1900, 2024, 2000)
35
 
36
+ Neighborhood = st.sidebar.selectbox(
37
+ "Neighborhood",
38
+ [
39
+ "NAmes", "CollgCr", "OldTown", "Edwards", "Somerst",
40
+ "Gilbert", "NridgHt", "Sawyer", "NWAmes", "SawyerW"
41
+ ]
42
+ )
43
 
44
+ # ======================
45
+ # DATAFRAME
46
+ # ======================
47
+ input_df = pd.DataFrame({
48
+ "OverallQual": [OverallQual],
49
+ "GrLivArea": [GrLivArea],
50
+ "GarageCars": [GarageCars],
51
+ "TotalBsmtSF": [TotalBsmtSF],
52
+ "FullBath": [FullBath],
53
+ "YearBuilt": [YearBuilt],
54
+ "Neighborhood": [Neighborhood]
55
  })
56
 
57
+ st.subheader("Input Data")
58
+ st.write(input_df)
59
+
60
+ # ======================
61
+ # PREDICTION
62
+ # ======================
63
+ if st.button("Predict Price"):
64
+
65
+ prediction = model.predict(input_df)[0]
66
+
67
+ st.subheader("Estimated House Price 💰")
68
+ st.success(f"${prediction:,.0f}")