navjotk's picture
Create app.py
04fc35c verified
raw
history blame
1.38 kB
import gradio as gr
from huggingface_hub import hf_hub_download
import joblib
import pandas as pd
import json
# Load model and config from Hugging Face
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")
# Load the model
model = joblib.load(model_path)
# Load the config to get feature names
with open(config_path, "r") as f:
config = json.load(f)
feature_names = config["features"]
# Inference function
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}"
# Gradio interface
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()