Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,34 @@
|
|
1 |
import gradio as gr
|
2 |
-
from huggingface_hub import hf_hub_download
|
3 |
-
import joblib
|
4 |
import pandas as pd
|
5 |
-
import
|
6 |
-
|
7 |
-
# Load model and config from Hugging Face
|
8 |
-
repo_id = "abhishek/autotrain-iris-xgboost"
|
9 |
-
|
10 |
-
model_path = hf_hub_download(repo_id=repo_id, filename="model.joblib")
|
11 |
-
config_path = hf_hub_download(repo_id=repo_id, filename="config.json")
|
12 |
|
13 |
-
#
|
|
|
14 |
model = joblib.load(model_path)
|
15 |
|
16 |
-
#
|
17 |
-
with open(config_path, "r") as f:
|
18 |
-
config = json.load(f)
|
19 |
-
|
20 |
-
feature_names = config["features"]
|
21 |
-
|
22 |
-
# Inference function
|
23 |
def predict(sepal_length, sepal_width, petal_length, petal_width):
|
24 |
-
input_df = pd.DataFrame([
|
25 |
-
sepal_length,
|
26 |
-
|
27 |
-
|
|
|
|
|
28 |
prediction = model.predict(input_df)[0]
|
29 |
-
return
|
30 |
|
31 |
# Gradio interface
|
32 |
-
|
33 |
fn=predict,
|
34 |
inputs=[
|
35 |
-
gr.Slider(4.0, 8.0,
|
36 |
-
gr.Slider(2.0, 5.0,
|
37 |
-
gr.Slider(1.0, 7.0,
|
38 |
-
gr.Slider(0.1, 3.0,
|
39 |
],
|
40 |
-
outputs=
|
41 |
-
title="
|
42 |
-
description="Enter flower measurements to predict the species using a model trained with AutoTrain on Hugging Face.",
|
43 |
)
|
44 |
|
45 |
-
|
|
|
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 |
+
# Prediction function
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def predict(sepal_length, sepal_width, petal_length, petal_width):
|
12 |
+
input_df = pd.DataFrame([{
|
13 |
+
"feat_SepalLengthCm": sepal_length,
|
14 |
+
"feat_SepalWidthCm": sepal_width,
|
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.Slider(4.0, 8.0, label="Sepal Length (cm)"),
|
26 |
+
gr.Slider(2.0, 5.0, label="Sepal Width (cm)"),
|
27 |
+
gr.Slider(1.0, 7.0, label="Petal Length (cm)"),
|
28 |
+
gr.Slider(0.1, 3.0, label="Petal Width (cm)")
|
29 |
],
|
30 |
+
outputs="text",
|
31 |
+
title="Iris Flower Classifier 🌸"
|
|
|
32 |
)
|
33 |
|
34 |
+
iface.launch()
|