MissingBreath commited on
Commit
b44ccd8
·
verified ·
1 Parent(s): 3dd8e32

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +10 -12
api.py CHANGED
@@ -27,15 +27,13 @@ def inference(review):
27
 
28
  app = FastAPI()
29
  @app.post("/classify")
30
- async def classify(image: UploadFile = File(...)):
31
- if image is not None:
32
- img = Image.open(io.BytesIO(await image.read()))
33
- img = img.resize((128, 128))
34
- img_array = np.array(img) / 255.0
35
- img_array = np.expand_dims(img_array, axis=0)
36
- predictions = model.predict(img_array)
37
- predicted_class_idx = np.argmax(predictions)
38
- predicted_class_idx = int(predicted_class_idx)
39
- return {"prediction": predicted_class_idx}
40
- else:
41
- return {"error": "No image provided"}
 
27
 
28
  app = FastAPI()
29
  @app.post("/classify")
30
+ async def classify(request: ReviewRequest):
31
+ reviews = request.reviews
32
+ predictions = []
33
+
34
+ # Process each review and get the predictions
35
+ for review in reviews:
36
+ predicted_class = inference(review)
37
+ predictions.append({predicted_class})
38
+
39
+ return {"predictions": predictions}