Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import numpy as np | |
| import pickle | |
| # Load model | |
| with open("iris_model.pkl", "rb") as f: | |
| model = pickle.load(f) | |
| # Define prediction function | |
| def predict(sepal_length, sepal_width, petal_length, petal_width): | |
| input_data = np.array([[sepal_length, sepal_width, petal_length, petal_width]]) | |
| prediction = model.predict(input_data)[0] | |
| species = ["Setosa πΌ", "Versicolor π·", "Virginica πΉ"] | |
| return f"The predicted species is: **{species[prediction]}**" | |
| # Create the app layout | |
| with gr.Blocks(theme="soft") as demo: | |
| gr.Markdown("# πΊ Iris Flower Classifier") | |
| gr.Markdown("Enter the flower measurements below to predict its species using a trained Machine Learning model.") | |
| with gr.Row(): | |
| sepal_length = gr.Number(label="π Sepal Length (cm)") | |
| sepal_width = gr.Number(label="π Sepal Width (cm)") | |
| with gr.Row(): | |
| petal_length = gr.Number(label="πΈ Petal Length (cm)") | |
| petal_width = gr.Number(label="πΈ Petal Width (cm)") | |
| predict_btn = gr.Button("π Predict Species") | |
| output = gr.Markdown() | |
| predict_btn.click(fn=predict, inputs=[sepal_length, sepal_width, petal_length, petal_width], outputs=output) | |
| # Launch the app | |
| demo.launch() | |