Download app.py from Mohit8219/Building_an_Interactive_Iris_Flower_Classification_Tool_Using_Gradio: direct link, hf CLI and curl.
- Browser
- Download file 841 Bytes
-
https://huggingface.co/spaces/Mohit8219/Building_an_Interactive_Iris_Flower_Classification_Tool_Using_Gradio/resolve/main/app.py
- Command line
-
hf download hf://spaces/Mohit8219/Building_an_Interactive_Iris_Flower_Classification_Tool_Using_Gradio/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Mohit8219/Building_an_Interactive_Iris_Flower_Classification_Tool_Using_Gradio/resolve/main/app.py
841 Bytes
| import gradio as gr | |
| from sklearn.datasets import load_iris | |
| from sklearn.ensemble import RandomForestClassifier | |
| # Load the Iris dataset and train a model | |
| iris = load_iris() | |
| X, y = iris.data, iris.target | |
| clf = RandomForestClassifier() | |
| clf.fit(X, y) | |
| # Define the prediction function | |
| 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]] | |
| # Create the Gradio interface | |
| 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() | |