ChristianSardo commited on
Commit
35ae1e9
·
verified ·
1 Parent(s): dc46c66

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, UploadFile, File
2
+ import pandas as pd
3
+ import joblib
4
+ from io import BytesIO
5
+
6
+ app = FastAPI()
7
+
8
+ model = joblib.load("modelo_anomalia.pkl")
9
+
10
+ @app.get("/")
11
+ def home():
12
+ return {"status": "API FastAPI rodando no Hugging Face!"}
13
+
14
+ @app.post("/classify")
15
+ async def classify_csv(file: UploadFile = File(...)):
16
+ content = await file.read()
17
+ df = pd.read_csv(BytesIO(content))
18
+
19
+ X = df[["elapsed", "success"]]
20
+ preds = model.predict(X)
21
+
22
+ percent_anom = (preds == -1).mean() * 100
23
+
24
+ return {
25
+ "anomalias": int((preds == -1).sum()),
26
+ "total": len(df),
27
+ "percentual": percent_anom,
28
+ "limite": percent_anom > 5
29
+ }