Amogha Y A commited on
Commit ·
1360774
1
Parent(s): e8f9e08
Init
Browse files- src/streamlit_app.py +60 -39
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,61 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
| 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 |
-
st.
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import joblib
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
import pandas as pd
|
| 5 |
+
from sklearn.linear_model import LinearRegression
|
| 6 |
+
from sklearn.feature_selection import RFE
|
| 7 |
+
|
| 8 |
+
# Constants
|
| 9 |
+
MODEL_REPO = "thatblackfox/civil"
|
| 10 |
+
MODEL_FILE = "model.joblib"
|
| 11 |
+
|
| 12 |
+
# ==== Load Model with Caching ====
|
| 13 |
+
@st.cache_resource
|
| 14 |
+
def load_model():
|
| 15 |
+
model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE)
|
| 16 |
+
model = joblib.load(model_path)
|
| 17 |
+
return model
|
| 18 |
+
|
| 19 |
+
# ==== Streamlit UI ====
|
| 20 |
+
st.set_page_config(page_title="Backward Linear Regression", layout="centered")
|
| 21 |
+
st.title("Backward Linear Regression")
|
| 22 |
+
st.markdown("Please enter the values of each feature")
|
| 23 |
+
|
| 24 |
+
radius = st.number_input('RADIUS: ')
|
| 25 |
+
sentry = st.number_input('Speed @ Entry: ')
|
| 26 |
+
sexit = st.number_input('Speed @ Exit : ')
|
| 27 |
+
ls = st.number_input('Ls: ')
|
| 28 |
+
tlength = st.number_input('Tan Length: ')
|
| 29 |
+
e = st.number_input('e: ')
|
| 30 |
+
sdistance = st.number_input('Sight distance: ')
|
| 31 |
+
dangle = st.number_input('D Angle: ')
|
| 32 |
+
total_width = st.number_input('Total width: ')
|
| 33 |
+
cw_width = st.number_input('CW Width: ')
|
| 34 |
+
lshoulder_width = st.number_input('Shoulder width (L) : ')
|
| 35 |
+
rshoulder_width = st.number_input('Shoulder width (R) : ')
|
| 36 |
+
long_chord = st.number_input('Long Chord (Lc): ')
|
| 37 |
+
appex_distance = st.number_input('Appex Distance (Es): ')
|
| 38 |
+
mid_speed = st.number_input('Mid Speed: ')
|
| 39 |
+
pcu = st.number_input('PCU: ')
|
| 40 |
+
|
| 41 |
+
if st.button("Generate"):
|
| 42 |
+
try:
|
| 43 |
+
model = load_model()
|
| 44 |
+
ins = { 'Speed @ Entry': [sentry],
|
| 45 |
+
'e': [e],
|
| 46 |
+
'Shoulder width (L) ': [lshoulder_width],
|
| 47 |
+
'Shoulder width (R) ': [rshoulder_width],
|
| 48 |
+
'Mid Speed': [mid_speed]}
|
| 49 |
+
in_df = pd.DataFrame.from_dict(ins)
|
| 50 |
+
predict = model.predict(in_df)
|
| 51 |
+
# ==== Display Output ====
|
| 52 |
+
st.success("✅ Prediction generated successfully!")
|
| 53 |
+
st.write("### **Predicted Value:**")
|
| 54 |
+
st.metric(label="Model Output", value=round(predict, 3))
|
| 55 |
+
|
| 56 |
+
# Optional: Show input summary
|
| 57 |
+
with st.expander("Show Input Data"):
|
| 58 |
+
st.dataframe(in_df)
|
| 59 |
+
|
| 60 |
+
except Exception as err:
|
| 61 |
+
st.error(f"⚠️ Error: {err}")
|