| import gradio as gr |
| from sklearn.datasets import load_iris |
| from sklearn.ensemble import RandomForestClassifier |
|
|
| |
| iris = load_iris() |
| X, y = iris.data, iris.target |
| clf = RandomForestClassifier() |
| clf.fit(X, y) |
|
|
| |
| def predict_iris(sepal_length, sepal_width, petal_length, petal_width): |
| prediction = clf.predict([[sepal_length, sepal_width, petal_length, petal_width]]) |
| return iris.target_names[prediction[0]] |
|
|
| |
| iface = gr.Interface( |
| fn=predict_iris, |
| inputs=[ |
| gr.components.Number(label="Sepal Length (cm)"), |
| gr.components.Number(label="Sepal Width (cm)"), |
| gr.components.Number(label="Petal Length (cm)"), |
| gr.components.Number(label="Petal Width (cm)") |
| ], |
| outputs="text" |
| ) |
|
|
| iface.launch() |
|
|