Skip to content

Commit 5782344

Browse files
authored
Merge pull request #71 from codeguru42/66-fast-api
66 fast api
2 parents 8085daf + a3587be commit 5782344

20 files changed

+325
-335
lines changed

docker-compose-dev.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
api:
33
build: .
4-
command: "poetry run python3 /api/manage.py runserver 0.0.0.0:8000"
4+
command: "poetry run uvicorn main:app --host 0.0.0.0 --port 8000"
55
env_file:
66
- env/dev.env
77
environment:
@@ -16,7 +16,7 @@ services:
1616
- .:/api
1717
worker:
1818
build: .
19-
command: "poetry run celery -A go_capture.tasks worker"
19+
command: "poetry run celery -A tasks worker"
2020
depends_on:
2121
- broker
2222
environment:

docker-compose-prod.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
api:
3-
command: "poetry run gunicorn go_capture.wsgi:application --bind 0.0.0.0:8000 -t 60"
3+
command: "poetry run uvicorn main:app --host 0.0.0.0 --port 8000"
44
environment:
55
- CELERY_BROKER_URL=amqp://guest:guest@broker:5672
66
- FIREBASE_CREDENTIALS_FILE=/run/secrets/firebase-credentials
@@ -15,7 +15,7 @@ services:
1515
volumes:
1616
- media:/api/media
1717
worker:
18-
command: "poetry run celery -A go_capture.tasks worker"
18+
command: "poetry run celery -A tasks worker"
1919
depends_on:
2020
- broker
2121
environment:

go_capture/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

go_capture/asgi.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

go_capture/settings.py

Lines changed: 0 additions & 137 deletions
This file was deleted.

go_capture/urls.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

go_capture/views.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

go_capture/wsgi.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

main.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import io
2+
from pathlib import Path
3+
from typing import Annotated
4+
5+
from fastapi import FastAPI, File, UploadFile, Form
6+
7+
import settings
8+
from sgf.process_image import process_image
9+
from tasks import process_image_task
10+
11+
app = FastAPI()
12+
13+
14+
@app.get("/health_check/")
15+
def health_check():
16+
return {"message": "Healthy!"}
17+
18+
19+
@app.post("/capture/")
20+
def capture(image: Annotated[UploadFile, File()]):
21+
output_file = io.StringIO()
22+
process_image(image.file, output_file)
23+
output_file.seek(0)
24+
return {
25+
"sgf": output_file.read(),
26+
"image_filename": image.filename,
27+
}
28+
29+
30+
@app.post("/capture_async/")
31+
def capture_async(
32+
image: Annotated[UploadFile, File()], fcm_registration_token: Annotated[str, Form()]
33+
):
34+
filename = Path(image.filename)
35+
output_path = settings.IMAGES_DIR / filename
36+
with output_path.open("wb") as output_file:
37+
output_file.write(image.file.read())
38+
process_image_task.delay(str(output_path.absolute()), fcm_registration_token)

manage.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)