Skip to content

Commit

Permalink
chore: apply formatter suggestions (#263)
Browse files Browse the repository at this point in the history
This commit applies black and isort formatting suggestions to the codebase.
  • Loading branch information
rickstaa authored Nov 6, 2024
1 parent cbc6caf commit cdef350
Show file tree
Hide file tree
Showing 23 changed files with 110 additions and 89 deletions.
3 changes: 2 additions & 1 deletion runner/app/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from app.pipelines.base import Pipeline
from fastapi import Request

from app.pipelines.base import Pipeline


def get_pipeline(request: Request) -> Pipeline:
return request.app.pipeline
3 changes: 2 additions & 1 deletion runner/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import os
from contextlib import asynccontextmanager

from app.routes import health
from fastapi import FastAPI
from fastapi.routing import APIRoute

from app.routes import health

logger = logging.getLogger(__name__)


Expand Down
9 changes: 5 additions & 4 deletions runner/app/pipelines/audio_to_text.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from enum import Enum
import logging
import os
from typing import List
from dataclasses import dataclass
from enum import Enum
from typing import List

import torch
from fastapi import File, UploadFile
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline

from app.pipelines.base import Pipeline
from app.pipelines.utils import get_model_dir, get_torch_device
from app.pipelines.utils.audio import AudioConverter
from app.utils.errors import InferenceError
from fastapi import File, UploadFile
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline

logger = logging.getLogger(__name__)

Expand Down
21 changes: 11 additions & 10 deletions runner/app/pipelines/image_to_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@

import PIL
import torch
from app.pipelines.base import Pipeline
from app.pipelines.utils import (
LoraLoader,
SafetyChecker,
get_model_dir,
get_torch_device,
is_lightning_model,
is_turbo_model,
)
from app.utils.errors import InferenceError
from diffusers import (
AutoPipelineForImage2Image,
EulerAncestralDiscreteScheduler,
Expand All @@ -27,6 +17,17 @@
from PIL import ImageFile
from safetensors.torch import load_file

from app.pipelines.base import Pipeline
from app.pipelines.utils import (
LoraLoader,
SafetyChecker,
get_model_dir,
get_torch_device,
is_lightning_model,
is_turbo_model,
)
from app.utils.errors import InferenceError

ImageFile.LOAD_TRUNCATED_IMAGES = True

logger = logging.getLogger(__name__)
Expand Down
6 changes: 3 additions & 3 deletions runner/app/pipelines/image_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import os

import torch
from app.pipelines.base import Pipeline
from app.pipelines.utils import get_model_dir, get_torch_device
from huggingface_hub import file_download
from transformers import BlipProcessor, BlipForConditionalGeneration
from PIL import Image
from transformers import BlipForConditionalGeneration, BlipProcessor

from app.pipelines.base import Pipeline
from app.pipelines.utils import get_model_dir, get_torch_device
from app.utils.errors import InferenceError

logger = logging.getLogger(__name__)
Expand Down
7 changes: 4 additions & 3 deletions runner/app/pipelines/image_to_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

import PIL
import torch
from app.pipelines.base import Pipeline
from app.pipelines.utils import SafetyChecker, get_model_dir, get_torch_device
from app.utils.errors import InferenceError
from diffusers import StableVideoDiffusionPipeline
from huggingface_hub import file_download
from PIL import ImageFile

from app.pipelines.base import Pipeline
from app.pipelines.utils import SafetyChecker, get_model_dir, get_torch_device
from app.utils.errors import InferenceError

ImageFile.LOAD_TRUNCATED_IMAGES = True

logger = logging.getLogger(__name__)
Expand Down
5 changes: 3 additions & 2 deletions runner/app/pipelines/segment_anything_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

import torch
import PIL
from PIL import ImageFile
from sam2.sam2_image_predictor import SAM2ImagePredictor

from app.pipelines.base import Pipeline
from app.pipelines.utils import get_model_dir, get_torch_device
from app.utils.errors import InferenceError
from PIL import ImageFile
from sam2.sam2_image_predictor import SAM2ImagePredictor

ImageFile.LOAD_TRUNCATED_IMAGES = True

Expand Down
23 changes: 12 additions & 11 deletions runner/app/pipelines/text_to_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@

import PIL
import torch
from app.pipelines.base import Pipeline
from app.pipelines.utils import (
LoraLoader,
SafetyChecker,
get_model_dir,
get_torch_device,
is_lightning_model,
is_turbo_model,
split_prompt,
)
from app.utils.errors import InferenceError
from diffusers import (
AutoPipelineForText2Image,
EulerDiscreteScheduler,
Expand All @@ -28,6 +17,18 @@
from huggingface_hub import file_download, hf_hub_download
from safetensors.torch import load_file

from app.pipelines.base import Pipeline
from app.pipelines.utils import (
LoraLoader,
SafetyChecker,
get_model_dir,
get_torch_device,
is_lightning_model,
is_turbo_model,
split_prompt,
)
from app.utils.errors import InferenceError

logger = logging.getLogger(__name__)


Expand Down
7 changes: 4 additions & 3 deletions runner/app/pipelines/text_to_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

import soundfile as sf
import torch
from app.utils.errors import InferenceError
from app.pipelines.base import Pipeline
from app.pipelines.utils import get_model_dir, get_torch_device
from parler_tts import ParlerTTSForConditionalGeneration
from transformers import AutoTokenizer

from app.pipelines.base import Pipeline
from app.pipelines.utils import get_model_dir, get_torch_device
from app.utils.errors import InferenceError

logger = logging.getLogger(__name__)


Expand Down
7 changes: 4 additions & 3 deletions runner/app/pipelines/upscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

import PIL
import torch
from diffusers import StableDiffusionUpscalePipeline
from huggingface_hub import file_download
from PIL import ImageFile

from app.pipelines.base import Pipeline
from app.pipelines.utils import (
SafetyChecker,
Expand All @@ -13,9 +17,6 @@
is_turbo_model,
)
from app.utils.errors import InferenceError
from diffusers import StableDiffusionUpscalePipeline
from huggingface_hub import file_download
from PIL import ImageFile

ImageFile.LOAD_TRUNCATED_IMAGES = True

Expand Down
2 changes: 1 addition & 1 deletion runner/app/pipelines/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
get_model_path,
get_torch_device,
is_lightning_model,
is_turbo_model,
is_numeric,
is_turbo_model,
split_prompt,
validate_torch_device,
)
11 changes: 6 additions & 5 deletions runner/app/routes/audio_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
from typing import Annotated, Dict, Tuple, Union

import torch
from fastapi import APIRouter, Depends, File, Form, UploadFile, status
from fastapi.responses import JSONResponse
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer

from app.dependencies import get_pipeline
from app.pipelines.base import Pipeline
from app.routes.utils import (
HTTPError,
TextResponse,
file_exceeds_max_size,
parse_key_from_metadata,
get_media_duration_ffmpeg,
http_error,
handle_pipeline_exception,
http_error,
parse_key_from_metadata,
)
from fastapi import APIRouter, Depends, File, Form, UploadFile, status
from fastapi.responses import JSONResponse
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer

router = APIRouter()

Expand Down
11 changes: 6 additions & 5 deletions runner/app/routes/image_to_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
from typing import Annotated, Dict, Tuple, Union

import torch
from fastapi import APIRouter, Depends, File, Form, UploadFile, status
from fastapi.responses import JSONResponse
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from PIL import Image, ImageFile

from app.dependencies import get_pipeline
from app.pipelines.base import Pipeline
from app.routes.utils import (
HTTPError,
ImageResponse,
handle_pipeline_exception,
http_error,
image_to_data_url,
handle_pipeline_exception,
)
from fastapi import APIRouter, Depends, File, Form, UploadFile, status
from fastapi.responses import JSONResponse
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from PIL import Image, ImageFile

ImageFile.LOAD_TRUNCATED_IMAGES = True

Expand Down
8 changes: 4 additions & 4 deletions runner/app/routes/image_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from typing import Annotated, Dict, Tuple, Union

import torch
from fastapi import APIRouter, Depends, File, Form, UploadFile, status
from fastapi.responses import JSONResponse
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from PIL import Image

from app.dependencies import get_pipeline
from app.pipelines.base import Pipeline
Expand All @@ -13,10 +17,6 @@
handle_pipeline_exception,
http_error,
)
from fastapi import APIRouter, Depends, File, Form, UploadFile, status
from fastapi.responses import JSONResponse
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from PIL import Image

router = APIRouter()

Expand Down
11 changes: 6 additions & 5 deletions runner/app/routes/image_to_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
from typing import Annotated, Dict, Tuple, Union

import torch
from fastapi import APIRouter, Depends, File, Form, UploadFile, status
from fastapi.responses import JSONResponse
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from PIL import Image, ImageFile

from app.dependencies import get_pipeline
from app.pipelines.base import Pipeline
from app.routes.utils import (
HTTPError,
VideoResponse,
handle_pipeline_exception,
http_error,
image_to_data_url,
handle_pipeline_exception,
)
from fastapi import APIRouter, Depends, File, Form, UploadFile, status
from fastapi.responses import JSONResponse
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from PIL import Image, ImageFile

ImageFile.LOAD_TRUNCATED_IMAGES = True

Expand Down
11 changes: 6 additions & 5 deletions runner/app/routes/segment_anything_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@

import numpy as np
import torch
from fastapi import APIRouter, Depends, File, Form, UploadFile, status
from fastapi.responses import JSONResponse
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from PIL import Image, ImageFile

from app.dependencies import get_pipeline
from app.pipelines.base import Pipeline
from app.routes.utils import (
HTTPError,
MasksResponse,
handle_pipeline_exception,
http_error,
json_str_to_np_array,
handle_pipeline_exception,
)
from fastapi import APIRouter, Depends, File, Form, UploadFile, status
from fastapi.responses import JSONResponse
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from PIL import Image, ImageFile

ImageFile.LOAD_TRUNCATED_IMAGES = True

Expand Down
11 changes: 6 additions & 5 deletions runner/app/routes/text_to_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
from typing import Annotated, Dict, Tuple, Union

import torch
from fastapi import APIRouter, Depends, status
from fastapi.responses import JSONResponse
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from pydantic import BaseModel, Field

from app.dependencies import get_pipeline
from app.pipelines.base import Pipeline
from app.routes.utils import (
HTTPError,
ImageResponse,
handle_pipeline_exception,
http_error,
image_to_data_url,
handle_pipeline_exception,
)
from fastapi import APIRouter, Depends, status
from fastapi.responses import JSONResponse
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from pydantic import BaseModel, Field

router = APIRouter()

Expand Down
9 changes: 5 additions & 4 deletions runner/app/routes/text_to_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
from typing import Annotated, Dict, Tuple, Union

import torch
from fastapi import APIRouter, Depends, status
from fastapi.responses import JSONResponse
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from pydantic import BaseModel, Field

from app.dependencies import get_pipeline
from app.pipelines.base import Pipeline
from app.routes.utils import (
Expand All @@ -13,10 +18,6 @@
handle_pipeline_exception,
http_error,
)
from fastapi import APIRouter, Depends, status
from fastapi.responses import JSONResponse
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from pydantic import BaseModel, Field

router = APIRouter()

Expand Down
Loading

0 comments on commit cdef350

Please sign in to comment.