Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import numpy as np | |
| import pickle | |
| import sklearn | |
| # Load your trained model | |
| model_file = "model-3.pkl" | |
| try: | |
| with open(model_file, 'rb') as file: | |
| model = pickle.load(file) | |
| except FileNotFoundError: | |
| raise FileNotFoundError("Model file 'model-3.pkl' not found in the directory.") | |
| # Define prediction function | |
| def predict_flower(sepal_length, sepal_width, petal_length, petal_width): | |
| features = np.array([[sepal_length, sepal_width, petal_length, petal_width]]) | |
| prediction = model.predict(features)[0] | |
| return f"The predicted flower class is: {prediction}" | |
| # Define input and output components | |
| inputs = [ | |
| gr.Number(label="Sepal Length"), | |
| gr.Number(label="Sepal Width"), | |
| gr.Number(label="Petal Length"), | |
| gr.Number(label="Petal Width") | |
| ] | |
| output = gr.Textbox(label="Prediction Result") | |
| # Create the Gradio interface | |
| demo = gr.Interface( | |
| fn=predict_flower, | |
| inputs=inputs, | |
| outputs=output, | |
| title="🌸 Flower Classification on IRIS Dataset", | |
| description="Enter the flower's sepal and petal measurements to predict its species using a trained ML model." | |
| ) | |
| # Launch the Gradio app | |
| if __name__ == "__main__": | |
| demo.launch() | |