DerYur commited on
Commit
605c6dd
·
verified ·
1 Parent(s): 0963355

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +39 -0
main.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from typing import Dict
4
+ import joblib
5
+ import numpy as np
6
+
7
+ app = FastAPI()
8
+
9
+ # Define the input schema
10
+ class UsageInput(BaseModel):
11
+ days_until_cycle_end: int
12
+ voice_total_allowance: float
13
+ voice_remaining: float
14
+ data_total_allowance: float
15
+ data_remaining: float
16
+ plan_price: float
17
+
18
+ # Load the trained model
19
+ model = joblib.load("model.pkl")
20
+
21
+ @app.post("/predict")
22
+ def predict(input_data: UsageInput) -> Dict[str, float]:
23
+ # Convert input to model format
24
+ input_array = np.array([[
25
+ input_data.days_until_cycle_end,
26
+ input_data.voice_total_allowance,
27
+ input_data.voice_remaining,
28
+ input_data.data_total_allowance,
29
+ input_data.data_remaining,
30
+ input_data.plan_price
31
+ ]])
32
+
33
+ # Predict using the model
34
+ predicted_voice, predicted_data = model.predict(input_array)[0]
35
+
36
+ return {
37
+ "predicted_total_voice_usage": round(predicted_voice, 2),
38
+ "predicted_total_data_usage": round(predicted_data, 2)
39
+ }