Spaces:
Sleeping
Sleeping
judebebo32
commited on
Commit
•
4e3d592
1
Parent(s):
1084a16
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import pickle
|
4 |
+
|
5 |
+
# Load the pre-trained model
|
6 |
+
with open('best_model.pkl', 'rb') as model_file:
|
7 |
+
model = pickle.load(model_file)
|
8 |
+
|
9 |
+
# Load the label encoder
|
10 |
+
with open('label_encoder.pkl', 'rb') as label_encoder_file:
|
11 |
+
label_encoder = pickle.load(label_encoder_file)
|
12 |
+
|
13 |
+
# Title of the app
|
14 |
+
st.title("Coffee Type Prediction")
|
15 |
+
|
16 |
+
# Sidebar inputs for user preferences
|
17 |
+
st.sidebar.header("User Preferences")
|
18 |
+
|
19 |
+
time_of_day = st.sidebar.selectbox("Time of Day", ['morning', 'afternoon', 'evening'])
|
20 |
+
coffee_strength = st.sidebar.selectbox("Coffee Strength", ['mild', 'regular', 'strong'])
|
21 |
+
sweetness_level = st.sidebar.selectbox("Sweetness Level", ['unsweetened', 'lightly sweetened', 'sweet'])
|
22 |
+
milk_type = st.sidebar.selectbox("Milk Type", ['none', 'regular', 'skim', 'almond'])
|
23 |
+
coffee_temperature = st.sidebar.selectbox("Coffee Temperature", ['hot', 'iced', 'cold brew'])
|
24 |
+
flavored_coffee = st.sidebar.selectbox("Flavored Coffee", ['yes', 'no'])
|
25 |
+
caffeine_tolerance = st.sidebar.selectbox("Caffeine Tolerance", ['low', 'medium', 'high'])
|
26 |
+
coffee_bean = st.sidebar.selectbox("Coffee Bean", ['Arabica', 'Robusta', 'blend'])
|
27 |
+
coffee_size = st.sidebar.selectbox("Coffee Size", ['small', 'medium', 'large'])
|
28 |
+
dietary_preferences = st.sidebar.selectbox("Dietary Preferences", ['none', 'vegan', 'lactose-intolerant'])
|
29 |
+
|
30 |
+
# Encoding the inputs manually (same encoding as in your training data)
|
31 |
+
input_data = pd.DataFrame({
|
32 |
+
'Token_0': [time_of_day],
|
33 |
+
'Token_1': [coffee_strength],
|
34 |
+
'Token_2': [sweetness_level],
|
35 |
+
'Token_3': [milk_type],
|
36 |
+
'Token_4': [coffee_temperature],
|
37 |
+
'Token_5': [flavored_coffee],
|
38 |
+
'Token_6': [caffeine_tolerance],
|
39 |
+
'Token_7': [coffee_bean],
|
40 |
+
'Token_8': [coffee_size],
|
41 |
+
'Token_9': [dietary_preferences]
|
42 |
+
})
|
43 |
+
|
44 |
+
# One-hot encode the input data (ensure it matches the training data)
|
45 |
+
input_encoded = pd.get_dummies(input_data)
|
46 |
+
|
47 |
+
# Align columns with the training data (required columns)
|
48 |
+
required_columns = [...] # Include all columns from the original model training data
|
49 |
+
for col in required_columns:
|
50 |
+
if col not in input_encoded.columns:
|
51 |
+
input_encoded[col] = 0
|
52 |
+
input_encoded = input_encoded[required_columns]
|
53 |
+
|
54 |
+
# Make the prediction
|
55 |
+
prediction = model.predict(input_encoded)[0]
|
56 |
+
|
57 |
+
# Reverse the label encoding (map the prediction back to the coffee type)
|
58 |
+
coffee_type = label_encoder.inverse_transform([prediction])[0]
|
59 |
+
|
60 |
+
# Display the prediction
|
61 |
+
st.subheader(f"Recommended Coffee: {coffee_type}")
|