DataWizard9742 commited on
Commit
cf1a784
·
verified ·
1 Parent(s): 0e160e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -16
app.py CHANGED
@@ -1,27 +1,41 @@
1
- import pickle
2
- import pandas as pd
3
  import numpy as np
4
- import streamlit as st
5
  import sklearn
6
 
 
7
  model_file = "model-3.pkl"
8
  try:
9
- with open(model_file,'rb') as file:
10
  model = pickle.load(file)
11
  except FileNotFoundError:
12
- st.error("The file was not found in the directory")
13
 
14
- st.title("FLower Classification using Streamlit on IRIS DATASET")
15
- st.header("Enter your flower features to get the classification prediction")
 
 
 
16
 
17
- sepal_length = st.number_input("Enter yuour sepal length")
18
- sepal_width = st.number_input("Enter yuour sepal width")
19
- petal_length = st.number_input("Enter yuour petal length")
20
- petal_width = st.number_input("Enter yuour petal width")
 
 
 
21
 
22
- if st.button("PREDICT"):
23
- features = np.array([[sepal_length,sepal_width,petal_length,petal_width]])
24
- prediction = model.predict(features)[0]
 
 
 
 
 
 
 
25
 
26
- st.subheader("Prediction has been made")
27
- st.write("Theprediction for your features is",predicton)
 
 
1
+ import gradio as gr
 
2
  import numpy as np
3
+ import pickle
4
  import sklearn
5
 
6
+ # Load your trained model
7
  model_file = "model-3.pkl"
8
  try:
9
+ with open(model_file, 'rb') as file:
10
  model = pickle.load(file)
11
  except FileNotFoundError:
12
+ raise FileNotFoundError("Model file 'model-3.pkl' not found in the directory.")
13
 
14
+ # Define prediction function
15
+ def predict_flower(sepal_length, sepal_width, petal_length, petal_width):
16
+ features = np.array([[sepal_length, sepal_width, petal_length, petal_width]])
17
+ prediction = model.predict(features)[0]
18
+ return f"The predicted flower class is: {prediction}"
19
 
20
+ # Define input and output components
21
+ inputs = [
22
+ gr.Number(label="Sepal Length"),
23
+ gr.Number(label="Sepal Width"),
24
+ gr.Number(label="Petal Length"),
25
+ gr.Number(label="Petal Width")
26
+ ]
27
 
28
+ output = gr.Textbox(label="Prediction Result")
29
+
30
+ # Create the Gradio interface
31
+ demo = gr.Interface(
32
+ fn=predict_flower,
33
+ inputs=inputs,
34
+ outputs=output,
35
+ title="🌸 Flower Classification on IRIS Dataset",
36
+ description="Enter the flower's sepal and petal measurements to predict its species using a trained ML model."
37
+ )
38
 
39
+ # Launch the Gradio app
40
+ if __name__ == "__main__":
41
+ demo.launch()