File size: 1,536 Bytes
6be5713
 
 
 
 
 
 
 
 
 
 
 
 
13a551e
 
 
 
 
 
 
6be5713
 
 
 
 
 
 
13a551e
6be5713
 
13a551e
 
6be5713
 
 
 
 
 
 
 
 
13a551e
 
 
 
 
6be5713
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
43
44
45
46
47
import gradio as gr
import pandas as pd
import joblib
from sklearn.datasets import load_iris

# Load model and scaler
model = joblib.load('models/iris_model.joblib')
scaler = joblib.load('models/scaler.joblib')
iris = load_iris()

# Feature names
features = iris.feature_names

# Image paths for each species
image_paths = {
    'setosa': 'setosa.jpeg',
    'versicolor': 'versicolor.jpg',
    'virginica': 'virginica.jpg'
}

# Prediction function
def predict_iris(sepal_length, sepal_width, petal_length, petal_width):
    input_data = pd.DataFrame([[sepal_length, sepal_width, petal_length, petal_width]], columns=features)
    input_data_scaled = scaler.transform(input_data)
    prediction = model.predict(input_data_scaled)
    probabilities = model.predict_proba(input_data_scaled)[0]
    species = iris.target_names[prediction[0]]
    image = image_paths.get(species.lower(), None)
    return (
        f"Predicted Species: {species}",
        {iris.target_names[i]: f"{prob:.2f}" for i, prob in enumerate(probabilities)},
        image
    )

# Gradio interface
inputs = [
    gr.Slider(0, 10, 5.0, label="Sepal Length (cm)"),
    gr.Slider(0, 10, 3.5, label="Sepal Width (cm)"),
    gr.Slider(0, 10, 1.4, label="Petal Length (cm)"),
    gr.Slider(0, 10, 0.2, label="Petal Width (cm)")
]
outputs = [
    gr.Textbox(label="Prediction"),
    gr.Label(label="Confidence Scores"),
    gr.Image(label="Predicted Species Image")
]
gr.Interface(fn=predict_iris, inputs=inputs, outputs=outputs, title="Iris Species Prediction").launch()