Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from sklearn.datasets import load_iris
|
| 3 |
+
from sklearn.ensemble import RandomForestClassifier
|
| 4 |
+
|
| 5 |
+
# Load the Iris dataset and train a model
|
| 6 |
+
iris = load_iris()
|
| 7 |
+
X, y = iris.data, iris.target
|
| 8 |
+
clf = RandomForestClassifier()
|
| 9 |
+
clf.fit(X, y)
|
| 10 |
+
|
| 11 |
+
# Define the prediction function
|
| 12 |
+
def predict_iris(sepal_length, sepal_width, petal_length, petal_width):
|
| 13 |
+
prediction = clf.predict([[sepal_length, sepal_width, petal_length, petal_width]])
|
| 14 |
+
return iris.target_names[prediction[0]]
|
| 15 |
+
|
| 16 |
+
# Create the Gradio interface
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=predict_iris,
|
| 19 |
+
inputs=[
|
| 20 |
+
gr.components.Number(label="Sepal Length (cm)"),
|
| 21 |
+
gr.components.Number(label="Sepal Width (cm)"),
|
| 22 |
+
gr.components.Number(label="Petal Length (cm)"),
|
| 23 |
+
gr.components.Number(label="Petal Width (cm)")
|
| 24 |
+
],
|
| 25 |
+
outputs="text"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
iface.launch()
|