GithubHelp home page GithubHelp logo

Comments (5)

jf--- avatar jf--- commented on July 17, 2024 2

@Sieboldianus I ran into this issue, it still comes up running the current master. Can I suggest to keep this issue open until #43 is closed?

from full-stack-fastapi-postgresql.

tiangolo avatar tiangolo commented on July 17, 2024 1

Thanks for the report and discussion here everyone!

This should be fixed in the current master. 🎉 🚀

So I guess we could close this issue, right @Sieboldianus ?

from full-stack-fastapi-postgresql.

Sieboldianus avatar Sieboldianus commented on July 17, 2024

Just noticed that this seems already addressed in PR 43. I've tested the PR and it works! This can be closed..

from full-stack-fastapi-postgresql.

 avatar commented on July 17, 2024

I can confirm I have the same issue running the current master. Thanks.

Edit:
I can also confirm that #43 seems to address the "Exception in ASGI".

This is awesome! Thanks.

from full-stack-fastapi-postgresql.

ajithyb225 avatar ajithyb225 commented on July 17, 2024

Can any one explain where to add the changes ??
i am little bit confused :)
P.S: I am a complete rookie into fastapi
I am using POSTman to upload an image to the server ..but showing internal server error..can anyone help me with this!!
using the latest version of every library .

Error Log:

Started server process [4532]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://localhost:8000 (Press CTRL+C to quit)
INFO: ::1:49810 - "GET /ping HTTP/1.1" 200 OK
INFO: ::1:49811 - "GET /predict HTTP/1.1" 405 Method Not Allowed
INFO: ::1:49819 - "POST /predict HTTP/1.1" 500 Internal Server Error
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "C:\Users\ajith\AppData\Local\Programs\Python\Python310\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 366, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "C:\Users\ajith\AppData\Local\Programs\Python\Python310\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 75, in call
return await self.app(scope, receive, send)
File "C:\Users\ajith\AppData\Local\Programs\Python\Python310\lib\site-packages\fastapi\applications.py", line 261, in call
await super().call(scope, receive, send)
File "C:\Users\ajith\AppData\Local\Programs\Python\Python310\lib\site-packages\starlette\applications.py", line 112, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\ajith\AppData\Local\Programs\Python\Python310\lib\site-packages\starlette\middleware\errors.py", line 181, in call
raise exc
File "C:\Users\ajith\AppData\Local\Programs\Python\Python310\lib\site-packages\starlette\middleware\errors.py", line 159, in call
await self.app(scope, receive, _send)
File "C:\Users\ajith\AppData\Local\Programs\Python\Python310\lib\site-packages\starlette\exceptions.py", line 82, in call
raise exc
File "C:\Users\ajith\AppData\Local\Programs\Python\Python310\lib\site-packages\starlette\exceptions.py", line 71, in call
await self.app(scope, receive, sender)
File "C:\Users\ajith\AppData\Local\Programs\Python\Python310\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 21, in call
raise e
File "C:\Users\ajith\AppData\Local\Programs\Python\Python310\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in call
await self.app(scope, receive, send)
File "C:\Users\ajith\AppData\Local\Programs\Python\Python310\lib\site-packages\starlette\routing.py", line 656, in call
await route.handle(scope, receive, send)
File "C:\Users\ajith\AppData\Local\Programs\Python\Python310\lib\site-packages\starlette\routing.py", line 259, in handle
await self.app(scope, receive, send)
File "C:\Users\ajith\AppData\Local\Programs\Python\Python310\lib\site-packages\starlette\routing.py", line 61, in app
response = await func(request)
File "C:\Users\ajith\AppData\Local\Programs\Python\Python310\lib\site-packages\fastapi\routing.py", line 227, in app
raw_response = await run_endpoint_function(
File "C:\Users\ajith\AppData\Local\Programs\Python\Python310\lib\site-packages\fastapi\routing.py", line 160, in run_endpoint_function
return await dependant.call(**values)
File "C:/Users/ajith/Desktop/Project/api/main.py", line 22, in predict
image = read_file_as_image( file.read())
File "C:/Users/ajith/Desktop/Project/api/main.py", line 16, in read_file_as_image
image = np.array(Image.open(BytesIO(data)))
TypeError: a bytes-like object is required, not 'coroutine'

CODE:

import uvicorn
from fastapi import FastAPI,File,UploadFile
import numpy as np
from io import BytesIO
from PIL import Image
import tensorflow as tf

app = FastAPI()

MODEL = tf.keras.models.load_model("C:/Users/ajith/Desktop/Project/Models/1")
['Healthy', 'Kole Roga']
@app.get("/ping")
async def ping():
return "Hello World:)"
def read_file_as_image(data) -> np.ndarray:
image = np.array(Image.open(BytesIO(data)))
return image

@app.post("/predict")
async def predict( file:UploadFile=File(...) ):

image = read_file_as_image( file.read())
img_batch = np.expand_dims(image, 0)

predictions = MODEL.predict(img_batch)
pass

if name=="main":
uvicorn.run(app, host="localhost", port=8000)

from full-stack-fastapi-postgresql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.