Spaces:
Runtime error
Runtime error
Update app.py
Browse files22 unmodified lines2324252627282922 unmodified lines@app.post("/uploadfile/")async def create_upload_file(file: UploadFile = File(...)):request_object_content = await file.read()img = Image.open(io.BytesIO(request_object_content))pred, idx, probs = learn.predict(img)return dict(zip(categories, map(float, probs)))22 unmodified lines23242526272829303132333435363738394041424344454622 unmodified lines@app.post("/uploadfile/")async def create_upload_file(file: UploadFile = File(...)):# Read the uploaded file contentrequest_object_content = await file.read()try:# Attempt to open the imageimg = Image.open(io.BytesIO(request_object_content))except Exception as e:return {"error": "Failed to open the image file. Make sure it is a valid image file."}# Check if img is None or notif img is None:return {"error": "Failed to open the image file."}try:# Assuming 'learn' is your image classifier modelpred, idx, probs = learn.predict(img)except Exception as e:return {"error": "Failed to make predictions."}# Assuming categories is a list of category labelsreturn dict(zip(categories, map(float, probs)))
app.py+19-2