mirror of
https://github.com/bellingcat/whisperbox-transcribe.git
synced 2026-06-07 19:18:35 +03:00
refactor: restructure project layout
This commit is contained in:
22
.github/workflows/ci.yml
vendored
22
.github/workflows/ci.yml
vendored
@@ -16,14 +16,14 @@ jobs:
|
|||||||
- isort --check app
|
- isort --check app
|
||||||
- flake8 app
|
- flake8 app
|
||||||
- mypy app
|
- mypy app
|
||||||
test:
|
# test:
|
||||||
runs-on: ubuntu-latest
|
# runs-on: ubuntu-latest
|
||||||
name: Test
|
# name: Test
|
||||||
steps:
|
# steps:
|
||||||
- uses: actions/checkout@v3
|
# - uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v4
|
# - uses: actions/setup-python@v4
|
||||||
with:
|
# with:
|
||||||
python-version: '3.11'
|
# python-version: '3.11'
|
||||||
cache: 'pip'
|
# cache: 'pip'
|
||||||
- pip install -e .[dev]
|
# - pip install -e .[test]
|
||||||
- pytest
|
# - pytest
|
||||||
|
|||||||
3
Makefile
3
Makefile
@@ -1,5 +1,6 @@
|
|||||||
dev:
|
dev:
|
||||||
docker-compose -f dev.docker-compose.yml up --build --remove-orphans
|
docker-compose -f docker/dev.docker-compose.yml build --progress tty
|
||||||
|
docker-compose -f docker/dev.docker-compose.yml up --remove-orphans
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
black app
|
black app
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
[alembic]
|
[alembic]
|
||||||
# path to migration scripts
|
# path to migration scripts
|
||||||
script_location = app/alembic
|
script_location = app/shared/db/alembic
|
||||||
|
|
||||||
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
|
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
|
||||||
# Uncomment the line below if you want the files to be prepended with date and time
|
# Uncomment the line below if you want the files to be prepended with date and time
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ from logging.config import fileConfig
|
|||||||
from alembic import context
|
from alembic import context
|
||||||
from sqlalchemy import engine_from_config, pool
|
from sqlalchemy import engine_from_config, pool
|
||||||
|
|
||||||
from app.config import settings
|
from app.shared.config import settings
|
||||||
from app.db.models import Base
|
from app.shared.db.models import Base
|
||||||
|
|
||||||
# this is the Alembic Config object, which provides
|
# this is the Alembic Config object, which provides
|
||||||
# access to the values within the .ini file in use.
|
# access to the values within the .ini file in use.
|
||||||
@@ -3,7 +3,7 @@ from typing import Generator
|
|||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.orm import Session, sessionmaker
|
from sqlalchemy.orm import Session, sessionmaker
|
||||||
|
|
||||||
from app.config import settings
|
from app.shared.config import settings
|
||||||
|
|
||||||
engine = create_engine(settings.DATABASE_URI)
|
engine = create_engine(settings.DATABASE_URI)
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@ from sqlalchemy.dialects.postgresql import UUID
|
|||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import Mapped, declarative_mixin, declared_attr
|
from sqlalchemy.orm import Mapped, declarative_mixin, declared_attr
|
||||||
|
|
||||||
from app.db.dtos import ArtifactType, JobStatus, JobType
|
from .dtos import ArtifactType, JobStatus, JobType
|
||||||
|
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
|
||||||
@@ -4,9 +4,9 @@ import pytest
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from sqlalchemy_utils import create_database, database_exists, drop_database
|
from sqlalchemy_utils import create_database, database_exists, drop_database
|
||||||
|
|
||||||
from app.db.base import SessionLocal, engine, get_session
|
from app.shared.db.base import SessionLocal, engine, get_session
|
||||||
from app.db.models import Base
|
from app.shared.db.models import Base
|
||||||
from app.main import app
|
from app.web.main import app
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure() -> None:
|
def pytest_configure() -> None:
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ from typing import Dict
|
|||||||
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
from app.config import settings
|
from app.shared.config import settings
|
||||||
from app.main import app
|
from app.web.main import app
|
||||||
|
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
|
|
||||||
|
|||||||
0
app/web/__init__.py
Normal file
0
app/web/__init__.py
Normal file
@@ -5,10 +5,10 @@ from fastapi import APIRouter, Depends, FastAPI, HTTPException, Path
|
|||||||
from pydantic import AnyHttpUrl, BaseModel
|
from pydantic import AnyHttpUrl, BaseModel
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
import app.db.dtos as dtos
|
import app.shared.db.dtos as dtos
|
||||||
import app.db.models as models
|
import app.shared.db.models as models
|
||||||
from app.db.base import get_session
|
from app.shared.db.base import get_session
|
||||||
from app.utils.security import authenticate_api_key
|
from app.web.security import authenticate_api_key
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ from hmac import compare_digest
|
|||||||
from fastapi import Depends, HTTPException
|
from fastapi import Depends, HTTPException
|
||||||
from fastapi.security import OAuth2PasswordBearer
|
from fastapi.security import OAuth2PasswordBearer
|
||||||
|
|
||||||
from app.config import settings
|
from app.shared.config import settings
|
||||||
|
|
||||||
|
|
||||||
def authenticate_api_key(
|
def authenticate_api_key(
|
||||||
@@ -6,4 +6,4 @@ set -e
|
|||||||
alembic upgrade head
|
alembic upgrade head
|
||||||
|
|
||||||
# start app
|
# start app
|
||||||
uvicorn app.main:app --reload --host ${HOST:-0.0.0.0} --port ${PORT:-80}
|
uvicorn app.web.main:app --reload --host ${HOST:-0.0.0.0} --port ${PORT:-80}
|
||||||
0
app/worker/__init__.py
Normal file
0
app/worker/__init__.py
Normal file
@@ -1,6 +1,6 @@
|
|||||||
from celery import Celery
|
from celery import Celery
|
||||||
|
|
||||||
from .config import settings
|
from app.shared.config import settings
|
||||||
|
|
||||||
celery = Celery(__name__)
|
celery = Celery(__name__)
|
||||||
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
FROM python:3.11
|
|
||||||
|
|
||||||
WORKDIR /code
|
|
||||||
|
|
||||||
ENV PYTHONDONTWRITEBYTECODE 1
|
|
||||||
ENV PYTHONUNBUFFERED 1
|
|
||||||
|
|
||||||
# Install dependencies
|
|
||||||
COPY pyproject.toml .
|
|
||||||
RUN pip install -U pip
|
|
||||||
RUN pip install .[test]
|
|
||||||
|
|
||||||
# The source code is mounted as a volume at /code, no need to copy.
|
|
||||||
16
docker/app.dev.Dockerfile
Normal file
16
docker/app.dev.Dockerfile
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
FROM python:3.11 AS compile-image
|
||||||
|
|
||||||
|
COPY pyproject.toml .
|
||||||
|
RUN pip install --user .[test]
|
||||||
|
|
||||||
|
FROM python:3.11 AS build-image
|
||||||
|
|
||||||
|
WORKDIR /code
|
||||||
|
|
||||||
|
ENV PYTHONDONTWRITEBYTECODE 1
|
||||||
|
ENV PYTHONUNBUFFERED 1
|
||||||
|
|
||||||
|
COPY --from=compile-image /root/.local /root/.local
|
||||||
|
ENV PATH=/root/.local/bin:$PATH
|
||||||
|
|
||||||
|
ENTRYPOINT ["bash", "./app/web/start.sh"]
|
||||||
@@ -37,16 +37,15 @@ services:
|
|||||||
app:
|
app:
|
||||||
container_name: whisper_api_app
|
container_name: whisper_api_app
|
||||||
build:
|
build:
|
||||||
context: .
|
context: ../
|
||||||
dockerfile: dev.Dockerfile
|
dockerfile: docker/app.dev.Dockerfile
|
||||||
command: bash ./app/start.sh
|
|
||||||
environment: *app-variables
|
environment: *app-variables
|
||||||
ports:
|
ports:
|
||||||
- "8000:80"
|
- "8000:80"
|
||||||
networks:
|
networks:
|
||||||
- app
|
- app
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/code
|
- ../:/code
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
postgres:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -55,12 +54,11 @@ services:
|
|||||||
|
|
||||||
worker:
|
worker:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: ../
|
||||||
dockerfile: dev.Dockerfile
|
dockerfile: docker/worker.dev.Dockerfile
|
||||||
container_name: whisper_api_worker
|
container_name: whisper_api_worker
|
||||||
command: celery --app=app.worker.celery worker --loglevel=info
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/code
|
- ../:/code
|
||||||
environment: *app-variables
|
environment: *app-variables
|
||||||
depends_on:
|
depends_on:
|
||||||
- app
|
- app
|
||||||
18
docker/worker.dev.Dockerfile
Normal file
18
docker/worker.dev.Dockerfile
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
FROM python:3.10 AS compile-image
|
||||||
|
|
||||||
|
COPY pyproject.toml .
|
||||||
|
RUN pip install --user .[test,worker]
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get clean && apt-get install -y --no-install-recommends ffmpeg
|
||||||
|
|
||||||
|
FROM python:3.10 AS build-image
|
||||||
|
|
||||||
|
WORKDIR /code
|
||||||
|
|
||||||
|
ENV PYTHONDONTWRITEBYTECODE 1
|
||||||
|
ENV PYTHONUNBUFFERED 1
|
||||||
|
|
||||||
|
COPY --from=compile-image /root/.local /root/.local
|
||||||
|
ENV PATH=/root/.local/bin:$PATH
|
||||||
|
|
||||||
|
ENTRYPOINT ["celery", "--app=app.worker.main.celery", "worker", "--loglevel=info"]
|
||||||
@@ -14,6 +14,11 @@ dependencies=[
|
|||||||
]
|
]
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
|
|
||||||
|
worker=[
|
||||||
|
"whisper @ git+https://github.com/openai/whisper.git"
|
||||||
|
]
|
||||||
|
|
||||||
dev = [
|
dev = [
|
||||||
# code formatting
|
# code formatting
|
||||||
"black",
|
"black",
|
||||||
|
|||||||
Reference in New Issue
Block a user