Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,32 @@
|
|
1 |
import gradio as gr
|
2 |
-
import pandas as pd
|
3 |
import joblib
|
|
|
4 |
from huggingface_hub import hf_hub_download
|
5 |
|
6 |
-
# Download model from Hugging Face
|
7 |
model_path = hf_hub_download(repo_id="abhishek/autotrain-iris-xgboost", filename="model.joblib")
|
8 |
model = joblib.load(model_path)
|
9 |
|
10 |
-
#
|
|
|
|
|
11 |
def predict(sepal_length, sepal_width, petal_length, petal_width):
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
"feat_PetalLengthCm": petal_length,
|
16 |
-
"feat_PetalWidthCm": petal_width
|
17 |
-
}])
|
18 |
-
prediction = model.predict(input_df)[0]
|
19 |
-
return prediction
|
20 |
|
21 |
# Gradio interface
|
22 |
iface = gr.Interface(
|
23 |
fn=predict,
|
24 |
inputs=[
|
25 |
-
gr.
|
26 |
-
gr.
|
27 |
-
gr.
|
28 |
-
gr.
|
29 |
],
|
30 |
-
outputs="
|
31 |
-
title="Iris
|
|
|
32 |
)
|
33 |
|
34 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import joblib
|
3 |
+
import pandas as pd
|
4 |
from huggingface_hub import hf_hub_download
|
5 |
|
6 |
+
# Download model from Hugging Face Hub
|
7 |
model_path = hf_hub_download(repo_id="abhishek/autotrain-iris-xgboost", filename="model.joblib")
|
8 |
model = joblib.load(model_path)
|
9 |
|
10 |
+
# Input labels expected by the model
|
11 |
+
feature_names = ['feat_SepalLengthCm', 'feat_SepalWidthCm', 'feat_PetalLengthCm', 'feat_PetalWidthCm']
|
12 |
+
|
13 |
def predict(sepal_length, sepal_width, petal_length, petal_width):
|
14 |
+
data = pd.DataFrame([[sepal_length, sepal_width, petal_length, petal_width]], columns=feature_names)
|
15 |
+
prediction = model.predict(data)[0]
|
16 |
+
return f"Predicted Iris Class: {prediction}"
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
# Gradio interface
|
19 |
iface = gr.Interface(
|
20 |
fn=predict,
|
21 |
inputs=[
|
22 |
+
gr.Number(label="Sepal Length (cm)"),
|
23 |
+
gr.Number(label="Sepal Width (cm)"),
|
24 |
+
gr.Number(label="Petal Length (cm)"),
|
25 |
+
gr.Number(label="Petal Width (cm)"),
|
26 |
],
|
27 |
+
outputs=gr.Textbox(label="Prediction"),
|
28 |
+
title="Iris Species Predictor 🌸",
|
29 |
+
description="Enter flower features to predict the Iris species using a model trained with AutoTrain Tabular."
|
30 |
)
|
31 |
|
32 |
iface.launch()
|