import gradio as gr from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from sklearn.pipeline import make_pipeline from sklearn.linear_model import LogisticRegression from sklearn.metrics import accuracy_score # Load Iris dataset iris = load_iris() X = iris.data y = iris.target # Split dataset into training and testing sets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Define model model = make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000)) # Train model model.fit(X_train, y_train) # Define a function for prediction def predict_iris(sepal_length, sepal_width, petal_length, petal_width): features = [[sepal_length, sepal_width, petal_length, petal_width]] prediction = model.predict(features) return iris.target_names[prediction[0]] # Create Gradio interface iris_interface = gr.Interface( fn=predict_iris, inputs=["number", "number", "number", "number"], outputs="text", title="Iris clarrification model", description="Measurements --> species prediction.", examples=[ [5.1, 3.5, 1.4, 0.2], [6.9, 3.1, 5.4, 2.1] ] ) # Launch the interface iris_interface.launch()