File size: 1,366 Bytes
0ccd2b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import gradio as gr
import pickle
import numpy as np
import json

with open("model.pkl", "rb") as f:
    model = pickle.load(f)

with open("metrics.json", "r") as f:
    metrics = json.load(f)

CLASS_NAMES = ["Setosa", "Versicolor", "Virginica"]


def predict(sepal_length, sepal_width, petal_length, petal_width):
    features = np.array([[sepal_length, sepal_width, petal_length, petal_width]])
    probabilities = model.predict_proba(features)[0]
    result = {CLASS_NAMES[i]: float(prob) for i, prob in enumerate(probabilities)}
    return result


demo = gr.Interface(
    fn=predict,
    inputs=[
        gr.Slider(4.0, 8.0, value=5.8, label="Sepal Length (cm)"),
        gr.Slider(2.0, 4.5, value=3.0, label="Sepal Width (cm)"),
        gr.Slider(1.0, 7.0, value=4.0, label="Petal Length (cm)"),
        gr.Slider(0.1, 2.5, value=1.2, label="Petal Width (cm)"),
    ],
    outputs=gr.Label(num_top_classes=3, label="Prediction"),
    title="Iris Classifier (CI/CD Demo)",
    description=(
        "Classify Iris flowers based on sepal and petal measurements. "
        "Model Performance: 90.0% accuracy. "
        "This model was automatically trained and deployed via GitHub Actions CI/CD."
    ),
    examples=[
        [5.1, 3.5, 1.4, 0.2],
        [6.2, 2.9, 4.3, 1.3],
        [7.7, 3.0, 6.1, 2.3],
    ]
)

if __name__ == "__main__":
    demo.launch()