File size: 1,246 Bytes
266d9b4
 
 
a94e576
 
266d9b4
 
c0203bb
 
a94e576
 
 
 
c0203bb
a94e576
c0203bb
 
 
 
a94e576
 
 
 
 
 
266d9b4
a94e576
266d9b4
 
 
a94e576
 
266d9b4
a94e576
 
266d9b4
 
a94e576
266d9b4
a94e576
266d9b4
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
## An python API for our Model
## Design by edander32 (Edmilson Alexandre) and jjambo(Joaquim Jambo)

from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import pandas as pd
import joblib
from huggingface_hub import hf_hub_download

# Inicializa o app
app = FastAPI(title="Exoplanet Classifier API")

# Baixa e carrega o modelo
model_path = hf_hub_download(
    repo_id="Edalexan/ia-pkl",  # substitua pelo seu repo/ID
    filename="exoplanet_model.pkl"
)
model = joblib.load(model_path)

# Define o modelo de entrada
class InputData(BaseModel):
    # Substitua pelos nomes reais das features que seu modelo espera
    feature1: float
    feature2: float
    feature3: float  # e assim por diante

@app.get("/")
def home():
    return {"message": "API do classificador de exoplanetas online."}

@app.post("/predict")
def predict(input_data: InputData):
    try:
        # Converte para DataFrame
        df = pd.DataFrame([input_data.dict()])
        pred = model.predict(df)[0]
        prob = model.predict_proba(df)[0][1]
        return {"prediction": int(pred), "probability": float(prob)}
    except Exception as e:
        raise HTTPException(status_code=400, detail=str(e))