Amogha Y A commited on
Commit
1360774
·
1 Parent(s): e8f9e08
Files changed (1) hide show
  1. 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
- # 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 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}")