File size: 1,201 Bytes
cf1a784
321694e
cf1a784
321694e
 
cf1a784
e91229a
321694e
cf1a784
321694e
 
cf1a784
321694e
cf1a784
 
 
 
 
321694e
cf1a784
 
 
 
 
 
 
321694e
cf1a784
 
 
 
 
 
 
 
 
 
321694e
cf1a784
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import gradio as gr
import numpy as np
import pickle
import sklearn

# Load your trained model
model_file = "model-3.pkl"
try:
    with open(model_file, 'rb') as file:
        model = pickle.load(file)
except FileNotFoundError:
    raise FileNotFoundError("Model file 'model-3.pkl' not found in the directory.")

# Define prediction function
def predict_flower(sepal_length, sepal_width, petal_length, petal_width):
    features = np.array([[sepal_length, sepal_width, petal_length, petal_width]])
    prediction = model.predict(features)[0]
    return f"The predicted flower class is: {prediction}"

# Define input and output components
inputs = [
    gr.Number(label="Sepal Length"),
    gr.Number(label="Sepal Width"),
    gr.Number(label="Petal Length"),
    gr.Number(label="Petal Width")
]

output = gr.Textbox(label="Prediction Result")

# Create the Gradio interface
demo = gr.Interface(
    fn=predict_flower,
    inputs=inputs,
    outputs=output,
    title="🌸 Flower Classification on IRIS Dataset",
    description="Enter the flower's sepal and petal measurements to predict its species using a trained ML model."
)

# Launch the Gradio app
if __name__ == "__main__":
    demo.launch()