sankar12345 commited on
Commit
39a8a70
1 Parent(s): c055241

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -3,7 +3,7 @@ import pandas as pd
3
  import pickle
4
  import sklearn # Ensure scikit-learn is imported
5
 
6
- # Load Model with Error Handling
7
  try:
8
  with open('logreg_model.pkl', 'rb') as model_file:
9
  model = pickle.load(model_file)
@@ -14,31 +14,33 @@ except Exception as e:
14
 
15
  st.title('Iris Variety Prediction')
16
 
17
- # Form
18
  with st.form(key='form_parameters'):
19
- sepal_length = st.slider('Sepal Length', 4.0, 8.0, 4.0)
20
- sepal_width = st.slider('Sepal Width', 2.0, 4.5, 2.0)
21
- petal_length = st.slider('Petal Length', 1.0, 7.0, 1.0)
22
- petal_width = st.slider('Petal Width', 0.1, 2.5, 0.1)
23
  st.markdown('---')
24
 
25
  submitted = st.form_submit_button('Predict')
26
 
27
  # Data Inference
28
- data_inf = {
29
- 'sepal.length': sepal_length,
30
- 'sepal.width': sepal_width,
31
- 'petal.length': petal_length,
32
- 'petal.width': petal_width
33
- }
 
 
 
34
 
35
- data_inf = pd.DataFrame([data_inf])
36
 
37
- if submitted:
38
  try:
39
- # Predict using Logistic Regression
40
  y_pred_inf = model.predict(data_inf)
41
- st.write('## Iris Variety = ' + str(y_pred_inf[0]))
42
  except Exception as e:
43
  st.error("Prediction failed. Please ensure the input format is correct and compatible with the model.")
44
  st.error(f"Error Details: {e}")
 
3
  import pickle
4
  import sklearn # Ensure scikit-learn is imported
5
 
6
+ # Load the pre-trained model
7
  try:
8
  with open('logreg_model.pkl', 'rb') as model_file:
9
  model = pickle.load(model_file)
 
14
 
15
  st.title('Iris Variety Prediction')
16
 
17
+ # User Input Form
18
  with st.form(key='form_parameters'):
19
+ sepal_length = st.slider('Sepal Length (cm)', 4.0, 8.0, 5.0)
20
+ sepal_width = st.slider('Sepal Width (cm)', 2.0, 4.5, 3.0)
21
+ petal_length = st.slider('Petal Length (cm)', 1.0, 7.0, 1.5)
22
+ petal_width = st.slider('Petal Width (cm)', 0.1, 2.5, 0.2)
23
  st.markdown('---')
24
 
25
  submitted = st.form_submit_button('Predict')
26
 
27
  # Data Inference
28
+ if submitted:
29
+ # Create DataFrame for prediction
30
+ data_inf = {
31
+ 'Id': 0,
32
+ 'SepalLengthCm': sepal_length,
33
+ 'SepalWidthCm': sepal_width,
34
+ 'PetalLengthCm': petal_length,
35
+ 'PetalWidthCm': petal_width
36
+ }
37
 
38
+ data_inf = pd.DataFrame([data_inf])
39
 
40
+ # Predict using the model
41
  try:
 
42
  y_pred_inf = model.predict(data_inf)
43
+ st.write('## Iris Variety: **' + str(y_pred_inf[0]) + '**')
44
  except Exception as e:
45
  st.error("Prediction failed. Please ensure the input format is correct and compatible with the model.")
46
  st.error(f"Error Details: {e}")