Spaces:
Sleeping
Sleeping
File size: 1,045 Bytes
605c6dd | 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 | from fastapi import FastAPI
from pydantic import BaseModel
from typing import Dict
import joblib
import numpy as np
app = FastAPI()
# Define the input schema
class UsageInput(BaseModel):
days_until_cycle_end: int
voice_total_allowance: float
voice_remaining: float
data_total_allowance: float
data_remaining: float
plan_price: float
# Load the trained model
model = joblib.load("model.pkl")
@app.post("/predict")
def predict(input_data: UsageInput) -> Dict[str, float]:
# Convert input to model format
input_array = np.array([[
input_data.days_until_cycle_end,
input_data.voice_total_allowance,
input_data.voice_remaining,
input_data.data_total_allowance,
input_data.data_remaining,
input_data.plan_price
]])
# Predict using the model
predicted_voice, predicted_data = model.predict(input_array)[0]
return {
"predicted_total_voice_usage": round(predicted_voice, 2),
"predicted_total_data_usage": round(predicted_data, 2)
}
|