|
import gradio as gr |
|
from huggingface_hub import hf_hub_download |
|
import joblib |
|
import pandas as pd |
|
import json |
|
|
|
|
|
repo_id = "abhishek/autotrain-iris-xgboost" |
|
|
|
model_path = hf_hub_download(repo_id=repo_id, filename="model.joblib") |
|
config_path = hf_hub_download(repo_id=repo_id, filename="config.json") |
|
|
|
|
|
model = joblib.load(model_path) |
|
|
|
|
|
with open(config_path, "r") as f: |
|
config = json.load(f) |
|
|
|
feature_names = config["features"] |
|
|
|
|
|
def predict(sepal_length, sepal_width, petal_length, petal_width): |
|
input_df = pd.DataFrame([[ |
|
sepal_length, sepal_width, petal_length, petal_width |
|
]], columns=feature_names) |
|
|
|
prediction = model.predict(input_df)[0] |
|
return f"🌸 Predicted species: {prediction}" |
|
|
|
|
|
demo = gr.Interface( |
|
fn=predict, |
|
inputs=[ |
|
gr.Slider(4.0, 8.0, step=0.1, label="Sepal Length"), |
|
gr.Slider(2.0, 5.0, step=0.1, label="Sepal Width"), |
|
gr.Slider(1.0, 7.0, step=0.1, label="Petal Length"), |
|
gr.Slider(0.1, 3.0, step=0.1, label="Petal Width"), |
|
], |
|
outputs=gr.Textbox(label="Prediction"), |
|
title="🌸 Iris Flower Classifier", |
|
description="Enter flower measurements to predict the species using a model trained with AutoTrain on Hugging Face.", |
|
) |
|
|
|
demo.launch() |
|
|