jflo commited on
Commit
4e5fb56
·
verified ·
1 Parent(s): 89ffd90

Created classify image API

Browse files
Files changed (1) hide show
  1. app.py +2 -13
app.py CHANGED
@@ -177,19 +177,8 @@ async def upload_image(file: UploadFile = File(...)):
177
  # Read and convert the image to a PIL Image
178
  contents = await file.read()
179
  image = Image.open(io.BytesIO(contents)).convert("RGB")
180
-
181
- # Optional: Transform the image into a tensor for PyTorch
182
- transform = transforms.Compose([
183
- transforms.Resize((224, 224)), # Resize to your model's expected input
184
- transforms.ToTensor(), # Convert to tensor
185
- ])
186
- tensor = transform(image).unsqueeze(0) # Add batch dimension
187
-
188
- # Dummy model prediction
189
- # Replace this with your actual PyTorch model
190
- prediction = torch.rand(1).item()
191
-
192
- return JSONResponse(content={"message": "Image received", "prediction": prediction})
193
 
194
  except Exception as e:
195
  return JSONResponse(content={"error": str(e)}, status_code=500)
 
177
  # Read and convert the image to a PIL Image
178
  contents = await file.read()
179
  image = Image.open(io.BytesIO(contents)).convert("RGB")
180
+
181
+ return JSONResponse(content=classify_img(image), status_code=201)
 
 
 
 
 
 
 
 
 
 
 
182
 
183
  except Exception as e:
184
  return JSONResponse(content={"error": str(e)}, status_code=500)