hermelawesene0924 commited on
Commit
6be5713
·
1 Parent(s): a8fd384

first commit

Browse files
Files changed (4) hide show
  1. app.py +34 -0
  2. models/iris_model.joblib +3 -0
  3. models/scaler.joblib +3 -0
  4. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import joblib
4
+ from sklearn.datasets import load_iris
5
+
6
+ # Load model and scaler
7
+ model = joblib.load('models/iris_model.joblib')
8
+ scaler = joblib.load('models/scaler.joblib')
9
+ iris = load_iris()
10
+
11
+ # Feature names
12
+ features = iris.feature_names
13
+
14
+ # Prediction function
15
+ def predict_iris(sepal_length, sepal_width, petal_length, petal_width):
16
+ input_data = pd.DataFrame([[sepal_length, sepal_width, petal_length, petal_width]], columns=features)
17
+ input_data_scaled = scaler.transform(input_data)
18
+ prediction = model.predict(input_data_scaled)
19
+ probabilities = model.predict_proba(input_data_scaled)[0]
20
+ species = iris.target_names[prediction[0]]
21
+ return (
22
+ f"Predicted Species: {species}",
23
+ {iris.target_names[i]: f"{prob:.2f}" for i, prob in enumerate(probabilities)}
24
+ )
25
+
26
+ # Gradio interface
27
+ inputs = [
28
+ gr.Slider(0, 10, 5.0, label="Sepal Length (cm)"),
29
+ gr.Slider(0, 10, 3.5, label="Sepal Width (cm)"),
30
+ gr.Slider(0, 10, 1.4, label="Petal Length (cm)"),
31
+ gr.Slider(0, 10, 0.2, label="Petal Width (cm)")
32
+ ]
33
+ outputs = [gr.Textbox(label="Prediction"), gr.Label(label="Confidence Scores")]
34
+ gr.Interface(fn=predict_iris, inputs=inputs, outputs=outputs, title="Iris Species Prediction").launch()
models/iris_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c201be3cf668244dbf62a7b12d3d5cf09c00e08baf10c06993644170b56fb1fa
3
+ size 991
models/scaler.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aa294d8111a148c835f16e383756d3a9aec4f10d8278febbe8ede2cd6abd791c
3
+ size 1047
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ pandas
3
+ scikit-learn
4
+ joblib