JBond07 commited on
Commit
425c187
·
verified ·
1 Parent(s): 95319ab

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +49 -39
src/streamlit_app.py CHANGED
@@ -1,40 +1,50 @@
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 numpy as np
4
+ import joblib
5
+
6
+ st.set_page_config(page_title="Tip Prediction", layout="centered")
7
+ # Load the trained model
8
+ model = joblib.load('taximodel.pkl')
9
+
10
+ #Streamlit UI configuration - Must be the first Streamlit command in your script
11
+ #st.set_page_config(page_title="Tip Prediction, layout = 'centered')
12
+
13
+ # Title of the app
14
+ st.title("Tip Predictor")
15
+ st.write("Enter the details of your taxi ride to predict the tip amount.")
16
+
17
+ # Streamlit UI to take inputs
18
+ with st.form("tip_form"):
19
+ total_bill = st.slider("Total Bill ($)", min_value=0.0, max_value=500.0, value=20.0)
20
+ sex = st.selectbox("Sex", ["Male", "Female"])
21
+ smoker = st.selectbox("Smoker", ["Yes", "No"])
22
+ day = st.selectbox("Day of the Week", ["Thur", "Fri", "Sat", "Sun"])
23
+ time = st.selectbox("Time of Day", ["Lunch", "Dinner"])
24
+ size = st.number_input("Party Size", min_value=1, value=2)
25
+
26
+ # Submit button
27
+ submitted = st.form_submit_button("Predict Tip")
28
+
29
+ #Prediction on form submission
30
+ if submitted:
31
+ input_df = pd.DataFrame([{
32
+ 'total_bill': total_bill,
33
+ 'sex': sex,
34
+ 'smoker': smoker,
35
+ 'day': day,
36
+ 'time': time,
37
+ 'size': size
38
+ }])
39
+
40
+ try:
41
+ # predict the tip
42
+ prediction = model.predict(input_df)
43
+
44
+ #Ensure the output is a scaler value
45
+ predicted_tip = prediction[0] if isinstance(prediction,(list, np.ndarray)) else prediction
46
+
47
+ # Display the predicted tip
48
+ st.success(f"Predicted Tip Amount: **${predicted_tip:.2f}**")
49
+ except Exception as e:
50
+ st.error(f"Error: {str(e)}")