exo / API_fastapi_server.py
Edmilson Alexandre
y
d63f9a0
raw
history blame contribute delete
853 Bytes
## An python API for our Model
## Design by edander32 (Edmilson Alexandre) and jjambo(Joaquim Jambo)
import gradio as gr
import pandas as pd
import joblib
from huggingface_hub import hf_hub_download
# Carrega modelo
model_path = hf_hub_download(repo_id="Edalexan/ia-pkl", filename="exoplanet_model.pkl")
model = joblib.load(model_path)
def predict(feature1, feature2, feature3):
df = pd.DataFrame([[feature1, feature2, feature3]], columns=["feature1", "feature2", "feature3"])
pred = model.predict(df)[0]
prob = model.predict_proba(df)[0][1]
return {"prediction": int(pred), "probability": float(prob)}
# Interface mínima só para expor a API
iface = gr.Interface(
fn=predict,
inputs=["number", "number", "number"],
outputs="json"
)
iface.launch(server_name="0.0.0.0", server_port=7860)