Spaces:
Sleeping
Sleeping
Create model_api.py
Browse files- model_api.py +34 -0
model_api.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# model_api.py
|
| 2 |
+
|
| 3 |
+
from fastapi import FastAPI
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
# Define the input data model for your AI API
|
| 9 |
+
class EquipmentInput(BaseModel):
|
| 10 |
+
usage_hours: float
|
| 11 |
+
idle_hours: float
|
| 12 |
+
movement_frequency: float
|
| 13 |
+
cost_per_hour: float
|
| 14 |
+
last_maintenance: str # Expecting 'YYYY-MM-DD' format
|
| 15 |
+
|
| 16 |
+
# Example GET endpoint (test your server)
|
| 17 |
+
@app.get("/")
|
| 18 |
+
async def root():
|
| 19 |
+
return {"message": "AI model API is up and running!"}
|
| 20 |
+
|
| 21 |
+
# Example POST endpoint to accept input and respond with dummy AI results
|
| 22 |
+
@app.post("/predict")
|
| 23 |
+
async def predict(input_data: EquipmentInput):
|
| 24 |
+
# Here you would call your real AI model logic
|
| 25 |
+
# For now, returning dummy data
|
| 26 |
+
suggestion = "Move"
|
| 27 |
+
confidence = 0.92
|
| 28 |
+
utilization_score = 0.88
|
| 29 |
+
return {
|
| 30 |
+
"suggestion": suggestion,
|
| 31 |
+
"confidence": confidence,
|
| 32 |
+
"utilization_score": utilization_score,
|
| 33 |
+
"input_received": input_data.dict()
|
| 34 |
+
}
|