Spaces:
Runtime error
Runtime error
Download src/streamlit_app.py from thatblackfox/Backward-Linear-Regression: direct link, hf CLI and curl.
- Browser
- Download file 2.13 kB
-
https://huggingface.co/spaces/thatblackfox/Backward-Linear-Regression/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/thatblackfox/Backward-Linear-Regression/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/thatblackfox/Backward-Linear-Regression/resolve/main/src/streamlit_app.py
2.13 kB
| import streamlit as st | |
| import joblib | |
| from huggingface_hub import hf_hub_download | |
| import pandas as pd | |
| from sklearn.linear_model import LinearRegression | |
| from sklearn.feature_selection import RFE | |
| # Constants | |
| MODEL_REPO = "thatblackfox/civil" | |
| MODEL_FILE = "model.joblib" | |
| # ==== Load Model with Caching ==== | |
| def load_model(): | |
| model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE) | |
| model = joblib.load(model_path) | |
| return model | |
| # ==== Streamlit UI ==== | |
| st.set_page_config(page_title="Backward Linear Regression", layout="centered") | |
| st.title("Backward Linear Regression") | |
| st.markdown("Please enter the values of each feature") | |
| radius = st.number_input('RADIUS: ') | |
| sentry = st.number_input('Speed @ Entry: ') | |
| sexit = st.number_input('Speed @ Exit : ') | |
| ls = st.number_input('Ls: ') | |
| tlength = st.number_input('Tan Length: ') | |
| e = st.number_input('e: ') | |
| sdistance = st.number_input('Sight distance: ') | |
| dangle = st.number_input('D Angle: ') | |
| total_width = st.number_input('Total width: ') | |
| cw_width = st.number_input('CW Width: ') | |
| lshoulder_width = st.number_input('Shoulder width (L) : ') | |
| rshoulder_width = st.number_input('Shoulder width (R) : ') | |
| long_chord = st.number_input('Long Chord (Lc): ') | |
| appex_distance = st.number_input('Appex Distance (Es): ') | |
| mid_speed = st.number_input('Mid Speed: ') | |
| pcu = st.number_input('PCU: ') | |
| if st.button("Generate"): | |
| try: | |
| model = load_model() | |
| ins = { 'Speed @ Entry': [sentry], | |
| 'e': [e], | |
| 'Shoulder width (L) ': [lshoulder_width], | |
| 'Shoulder width (R) ': [rshoulder_width], | |
| 'Mid Speed': [mid_speed]} | |
| in_df = pd.DataFrame.from_dict(ins) | |
| predict = model.predict(in_df) | |
| # ==== Display Output ==== | |
| st.success("✅ Prediction generated successfully!") | |
| st.write("### **Predicted Value:**") | |
| st.metric(label="Model Output", value=round(predict[0], 3)) | |
| # # Optional: Show input summary | |
| # with st.expander("Show Input Data"): | |
| # st.dataframe(in_df) | |
| except Exception as err: | |
| st.error(f"⚠️ Error: {err}") |