samanthakarungi commited on
Commit
bc07c80
1 Parent(s): a42db91

Upload main app file

Browse files
Files changed (2) hide show
  1. app.py +29 -0
  2. requirements.txt +0 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from typing import List
3
+
4
+ app = FastAPI()
5
+
6
+ @app.get("/")
7
+ async def read_root():
8
+ return {"message": "Welcome to the FastAPI application!"}
9
+
10
+ @app.post("/classify")
11
+ async def classify(labels: List[dict]):
12
+ try:
13
+ # if labels is empty return 400 error
14
+ if not labels:
15
+ raise HTTPException(status_code=400, detail="No labels provided")
16
+
17
+ # Check if the highest score is lower than 0.6
18
+ if labels[0]["score"] < 0.6:
19
+ predicted_label = "OTHER"
20
+ else:
21
+ # Find the label with the highest score
22
+ predicted_label = labels[0]["label"]
23
+
24
+ # Return the predicted label
25
+ return {"predicted_label": predicted_label}
26
+
27
+ except Exception as e:
28
+ raise HTTPException(status_code=500, detail=str(e))
29
+
requirements.txt ADDED
Binary file (462 Bytes). View file