File size: 980 Bytes
7116c32
 
ef266ea
 
 
 
642edc4
ef266ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
!pip install gradio

import gradio as gr
import numpy as np
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier

# Load the Iris dataset
iris = load_iris()
X = iris.data
y = iris.target
target_names = iris.target_names

# Train a RandomForestClassifier
clf = RandomForestClassifier(n_estimators=100).fit(X, y)

# Function to make predictions
def predict_species(sepal_length, sepal_width, petal_length, petal_width):
    features = np.array([sepal_length, sepal_width, petal_length, petal_width]).reshape(1, -1)
    prediction = clf.predict(features)[0]
    species = target_names[prediction]
    return species

# Create a Gradio interface
iface = gr.Interface(
    fn=predict_species,
    inputs=["number", "number", "number", "number"],
    outputs="text",
    title="Iris Species Classification",
    description="Predict the species of an Iris flower based on its sepal and petal measurements."
)

# Launch the interface
iface.launch()