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
|
||||
- flake8 app
|
||||
- mypy app
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
name: Test
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.11'
|
||||
cache: 'pip'
|
||||
- pip install -e .[dev]
|
||||
- pytest
|
||||
# test:
|
||||
# runs-on: ubuntu-latest
|
||||
# name: Test
|
||||
# steps:
|
||||
# - uses: actions/checkout@v3
|
||||
# - uses: actions/setup-python@v4
|
||||
# with:
|
||||
# python-version: '3.11'
|
||||
# cache: 'pip'
|
||||
# - pip install -e .[test]
|
||||
# - pytest
|
||||
|
||||
3
Makefile
3
Makefile
@@ -1,5 +1,6 @@
|
||||
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:
|
||||
black app
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
[alembic]
|
||||
# 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
|
||||
# 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 sqlalchemy import engine_from_config, pool
|
||||
|
||||
from app.config import settings
|
||||
from app.db.models import Base
|
||||
from app.shared.config import settings
|
||||
from app.shared.db.models import Base
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# 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.orm import Session, sessionmaker
|
||||
|
||||
from app.config import settings
|
||||
from app.shared.config import settings
|
||||
|
||||
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.orm import Mapped, declarative_mixin, declared_attr
|
||||
|
||||
from app.db.dtos import ArtifactType, JobStatus, JobType
|
||||
from .dtos import ArtifactType, JobStatus, JobType
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
@@ -4,9 +4,9 @@ import pytest
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy_utils import create_database, database_exists, drop_database
|
||||
|
||||
from app.db.base import SessionLocal, engine, get_session
|
||||
from app.db.models import Base
|
||||
from app.main import app
|
||||
from app.shared.db.base import SessionLocal, engine, get_session
|
||||
from app.shared.db.models import Base
|
||||
from app.web.main import app
|
||||
|
||||
|
||||
def pytest_configure() -> None:
|
||||
|
||||
@@ -2,8 +2,8 @@ from typing import Dict
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.config import settings
|
||||
from app.main import app
|
||||
from app.shared.config import settings
|
||||
from app.web.main import 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 sqlalchemy.orm import Session
|
||||
|
||||
import app.db.dtos as dtos
|
||||
import app.db.models as models
|
||||
from app.db.base import get_session
|
||||
from app.utils.security import authenticate_api_key
|
||||
import app.shared.db.dtos as dtos
|
||||
import app.shared.db.models as models
|
||||
from app.shared.db.base import get_session
|
||||
from app.web.security import authenticate_api_key
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@@ -3,7 +3,7 @@ from hmac import compare_digest
|
||||
from fastapi import Depends, HTTPException
|
||||
from fastapi.security import OAuth2PasswordBearer
|
||||
|
||||
from app.config import settings
|
||||
from app.shared.config import settings
|
||||
|
||||
|
||||
def authenticate_api_key(
|
||||
@@ -6,4 +6,4 @@ set -e
|
||||
alembic upgrade head
|
||||
|
||||
# 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 .config import settings
|
||||
from app.shared.config import settings
|
||||
|
||||
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:
|
||||
container_name: whisper_api_app
|
||||
build:
|
||||
context: .
|
||||
dockerfile: dev.Dockerfile
|
||||
command: bash ./app/start.sh
|
||||
context: ../
|
||||
dockerfile: docker/app.dev.Dockerfile
|
||||
environment: *app-variables
|
||||
ports:
|
||||
- "8000:80"
|
||||
networks:
|
||||
- app
|
||||
volumes:
|
||||
- ./:/code
|
||||
- ../:/code
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
@@ -55,12 +54,11 @@ services:
|
||||
|
||||
worker:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: dev.Dockerfile
|
||||
context: ../
|
||||
dockerfile: docker/worker.dev.Dockerfile
|
||||
container_name: whisper_api_worker
|
||||
command: celery --app=app.worker.celery worker --loglevel=info
|
||||
volumes:
|
||||
- ./:/code
|
||||
- ../:/code
|
||||
environment: *app-variables
|
||||
depends_on:
|
||||
- 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]
|
||||
|
||||
worker=[
|
||||
"whisper @ git+https://github.com/openai/whisper.git"
|
||||
]
|
||||
|
||||
dev = [
|
||||
# code formatting
|
||||
"black",
|
||||
|
||||
Reference in New Issue
Block a user