diff --git a/in_cluster/sklearn/iris/app.py b/in_cluster/sklearn/iris/app.py new file mode 100644 index 0000000..56beb5b --- /dev/null +++ b/in_cluster/sklearn/iris/app.py @@ -0,0 +1,57 @@ +import streamlit as st +import pandas as pd +import joblib +import argparse + +from PIL import Image + + +def load_model(model_path: str): + model = open(model_path, "rb") + return joblib.load(model) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument( + '--model-path', + type=str, + ) + args = parser.parse_args() + + setosa = Image.open("images/iris-setosa.png") + versicolor = Image.open("images/iris-versicolor.png") + virginica = Image.open("images/iris-virginica.png") + classifier = load_model(args.model_path) + print(classifier) + + st.title("Iris flower species Classification") + st.sidebar.title("Features") + parameter_list = [ + "Sepal length (cm)", + "Sepal Width (cm)", + "Petal length (cm)", + "Petal Width (cm)" + ] + sliders = [] + for parameter, parameter_df in zip(parameter_list, ['5.2', '3.2', '4.2', '1.2']): + values = st.sidebar.slider( + label=parameter, + key=parameter, + value=float(parameter_df), + min_value=0.0, + max_value=8.0, + step=0.1 + ) + sliders.append(values) + + input_variables = pd.DataFrame([sliders], columns=parameter_list) + + prediction = classifier.predict(input_variables) + if prediction == 0: + st.image(setosa) + elif prediction == 1: + st.image(versicolor) + else: + st.image(virginica) + diff --git a/in_cluster/sklearn/iris/hyper-polyaxonfile.yml b/in_cluster/sklearn/iris/hyper-polyaxonfile.yml new file mode 100644 index 0000000..69b353b --- /dev/null +++ b/in_cluster/sklearn/iris/hyper-polyaxonfile.yml @@ -0,0 +1,19 @@ +version: 1.1 +kind: operation +matrix: + kind: random + numRuns: 15 + params: + n_neighbors: + kind: range + value: "3:50:5" + leaf_size: + kind: choice + value: [5, 10, 20, 30] + metric: + kind: pchoice + value: [[minkowski, 0.8], [euclidean, 0.2]] + test_size: + kind: choice + value: [0.2, 0.3, 0.4] +urlRef: https://raw.githubusercontent.com/polyaxon/polyaxon-examples/master/in_cluster/sklearn/iris/polyaxonfile.yml diff --git a/in_cluster/sklearn/iris/images/iris-setosa.png b/in_cluster/sklearn/iris/images/iris-setosa.png new file mode 100644 index 0000000..8a9c80a Binary files /dev/null and b/in_cluster/sklearn/iris/images/iris-setosa.png differ diff --git a/in_cluster/sklearn/iris/images/iris-versicolor.png b/in_cluster/sklearn/iris/images/iris-versicolor.png new file mode 100644 index 0000000..e6c54b3 Binary files /dev/null and b/in_cluster/sklearn/iris/images/iris-versicolor.png differ diff --git a/in_cluster/sklearn/iris/images/iris-virginica.png b/in_cluster/sklearn/iris/images/iris-virginica.png new file mode 100644 index 0000000..0aa5fe1 Binary files /dev/null and b/in_cluster/sklearn/iris/images/iris-virginica.png differ diff --git a/in_cluster/sklearn/iris/streamlit-polyaxonfile.yml b/in_cluster/sklearn/iris/streamlit-polyaxonfile.yml new file mode 100644 index 0000000..e32fe5c --- /dev/null +++ b/in_cluster/sklearn/iris/streamlit-polyaxonfile.yml @@ -0,0 +1,22 @@ +version: 1.1 +kind: component +name: iris-classification +tags: ["streamlit", "app"] + +inputs: +- name: uuid + isOptional: true + type: str + +run: + kind: service + ports: [8501] + rewritePath: true + init: + - git: {"url": "https://github.com/polyaxon/polyaxon-examples"} + - artifacts: {"files": ["{{ uuid }}/assets/model/iris-model.joblib"]} + container: + image: polyaxon/polyaxon-contrib + workingDir: "{{ globals.artifacts_path }}/polyaxon-examples/in_cluster/sklearn/iris" + command: [streamlit, run, app.py] + args: ["--", "--model-path={{ globals.artifacts_path }}/{{ uuid }}/assets/model/iris-model.joblib"]