Sathwikchowdary commited on
Commit
e4fdc97
Β·
verified Β·
1 Parent(s): f07c23e

Update home.py

Browse files
Files changed (1) hide show
  1. home.py +34 -37
home.py CHANGED
@@ -3,51 +3,57 @@ import pickle
3
  import numpy as np
4
  import os
5
 
6
- # Load the trained model
7
- MODEL_PATH = "/home/user/app/wine_quality_model.pkl" # Update with your actual model path
 
 
 
 
 
 
8
 
9
- # Streamlit UI
10
  st.set_page_config(page_title="🍷 Wine Quality Predictor", layout="centered")
11
 
12
- # Custom Styling for Background and Text
13
  st.markdown(
14
  """
15
  <style>
16
  .stApp {
17
- background-color: #003366;
18
  color: white;
19
  }
20
  .title {
21
  font-size: 36px !important;
22
  font-weight: bold;
23
- color: white;
24
  text-align: center;
25
  }
26
  .subtitle {
27
  font-size: 24px !important;
28
  font-weight: bold;
29
- color: #ffcc00;
30
  }
31
- .stSlider label, .stNumberInput label {
32
- font-size: 20px !important;
33
  font-weight: bold;
34
  color: white;
35
  }
36
  .stButton>button {
37
- background-color: #ffcc00;
38
- color: #003366;
39
  font-size: 18px;
40
  font-weight: bold;
41
  border-radius: 10px;
42
  }
43
  .stButton>button:hover {
44
- background-color: #ff9900;
45
  color: white;
46
  }
47
  .prediction {
48
  font-size: 26px;
49
  font-weight: bold;
50
- color: #32CD32;
51
  text-align: center;
52
  }
53
  </style>
@@ -55,34 +61,25 @@ st.markdown(
55
  unsafe_allow_html=True,
56
  )
57
 
 
58
  st.markdown('<h1 class="title">🍷 Wine Quality Prediction</h1>', unsafe_allow_html=True)
59
- st.write("Predict the quality of wine based on its properties.")
 
 
 
 
60
 
61
- # Check if model file exists
62
- if os.path.exists(MODEL_PATH):
63
- with open(MODEL_PATH, "rb") as f:
 
64
  model = pickle.load(f)
65
  model_loaded = True
66
  else:
67
  model_loaded = False
68
- st.error(f"Model file '{MODEL_PATH}' not found. Please check your uploaded files.")
69
-
70
- # User Inputs
71
- alcohol = st.slider("Alcohol Content", 8.0, 15.0, 10.0)
72
- volatile_acidity = st.slider("Volatile Acidity", 0.1, 1.5, 0.5)
73
- citric_acid = st.slider("Citric Acid", 0.0, 1.0, 0.3)
74
- sulphates = st.slider("Sulphates", 0.3, 2.0, 0.8)
75
- pH = st.slider("pH Level", 2.5, 4.0, 3.2)
76
-
77
- # Prepare input for model
78
- input_data = np.array([[alcohol, volatile_acidity, citric_acid, sulphates, pH]])
79
-
80
- # Prediction
81
- if st.button("Predict Quality"):
82
- if model_loaded:
83
- prediction = model.predict(input_data)
84
- st.markdown(f'<p class="prediction">Predicted Wine Quality Score: {prediction[0]:.1f}</p>', unsafe_allow_html=True)
85
- else:
86
- st.error(f"Model file '{MODEL_PATH}' not found. Please upload the model file and try again.")
87
 
88
- st.write("*Powered by Machine Learning*")
 
 
 
 
3
  import numpy as np
4
  import os
5
 
6
+ # Load all trained models
7
+ MODEL_FILES = {
8
+ "KNN": "knn_model.pkl",
9
+ "Random Forest": "random_forest_model.pkl",
10
+ "Decision Tree": "decision_tree_model.pkl",
11
+ "Bagging": "bagging_model.pkl",
12
+ "Voting": "voting_model.pkl",
13
+ }
14
 
15
+ # Streamlit UI Config
16
  st.set_page_config(page_title="🍷 Wine Quality Predictor", layout="centered")
17
 
18
+ # Custom Styling for Background & UI
19
  st.markdown(
20
  """
21
  <style>
22
  .stApp {
23
+ background: linear-gradient(to right, #4B0101, #800020);
24
  color: white;
25
  }
26
  .title {
27
  font-size: 36px !important;
28
  font-weight: bold;
29
+ color: #FFD700; /* Gold */
30
  text-align: center;
31
  }
32
  .subtitle {
33
  font-size: 24px !important;
34
  font-weight: bold;
35
+ color: #FFA500; /* Orange */
36
  }
37
+ .stSelectbox label, .stSlider label, .stNumberInput label {
38
+ font-size: 18px !important;
39
  font-weight: bold;
40
  color: white;
41
  }
42
  .stButton>button {
43
+ background-color: #FFD700; /* Gold */
44
+ color: #4B0101; /* Wine Red */
45
  font-size: 18px;
46
  font-weight: bold;
47
  border-radius: 10px;
48
  }
49
  .stButton>button:hover {
50
+ background-color: #FFA500; /* Orange */
51
  color: white;
52
  }
53
  .prediction {
54
  font-size: 26px;
55
  font-weight: bold;
56
+ color: #32CD32; /* Bright Green */
57
  text-align: center;
58
  }
59
  </style>
 
61
  unsafe_allow_html=True,
62
  )
63
 
64
+ # Title and Description
65
  st.markdown('<h1 class="title">🍷 Wine Quality Prediction</h1>', unsafe_allow_html=True)
66
+ st.write("Predict the quality of wine based on its chemical properties.")
67
+
68
+ # Select Model
69
+ st.markdown('<h2 class="subtitle">πŸ” Select Prediction Model</h2>', unsafe_allow_html=True)
70
+ selected_model = st.selectbox("Choose a Model", list(MODEL_FILES.keys()))
71
 
72
+ # Load Selected Model
73
+ model_path = MODEL_FILES[selected_model]
74
+ if os.path.exists(model_path):
75
+ with open(model_path, "rb") as f:
76
  model = pickle.load(f)
77
  model_loaded = True
78
  else:
79
  model_loaded = False
80
+ st.error(f"Model file '{model_path}' not found. Please upload the correct model file.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
+ # User Inputs for Wine Features
83
+ st.markdown('<h2 class="subtitle">🍷 Enter Wine Properties</h2>', unsafe_allow_html=True)
84
+ fixed_acidity = st.number_input("Fixed Acidity", min_value=3.0, max_value=15.0, value=7.0)
85
+ volatile_acidity = st.number_input("