first cimmit
This commit is contained in:
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
models
|
||||||
|
test
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -150,4 +150,5 @@ app/logs/*
|
|||||||
*.avi
|
*.avi
|
||||||
*.json
|
*.json
|
||||||
*.env*
|
*.env*
|
||||||
config.backup.py
|
config.backup.py
|
||||||
|
models
|
||||||
@@ -16,20 +16,21 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|||||||
libgl1 \
|
libgl1 \
|
||||||
libglib2.0-0 \
|
libglib2.0-0 \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
|
git \
|
||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY pyproject.toml uv.lock ./
|
COPY pyproject.toml uv.lock download_model.sh ./
|
||||||
|
|
||||||
ENV UV_COMPILE_BYTECODE=0
|
ENV UV_COMPILE_BYTECODE=0
|
||||||
|
|
||||||
RUN uv sync --frozen --no-dev --no-install-project --python 3.10
|
RUN uv sync --frozen --no-dev --no-install-project --python 3.13
|
||||||
|
|
||||||
# 4. 拷贝项目文件并安装项目本身
|
# 4. 拷贝项目文件并安装项目本身
|
||||||
COPY . .
|
#COPY . .
|
||||||
RUN uv sync --frozen --no-dev --python 3.10
|
RUN uv sync --frozen --no-dev --python 3.13
|
||||||
|
|
||||||
ENV PATH="/app/.venv/bin:$PATH"
|
ENV PATH="/app/.venv/bin:$PATH"
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ class Settings(BaseSettings):
|
|||||||
extra='ignore' # 忽略环境变量中多余的键
|
extra='ignore' # 忽略环境变量中多余的键
|
||||||
)
|
)
|
||||||
# 启动端口
|
# 启动端口
|
||||||
SERVE_PROD: int = Field(default=8000, description='')
|
SERVE_PORT: int = Field(default=10090, description='')
|
||||||
|
|
||||||
|
FLUX2_KLEIN_MODEL_PATH: str = Field(default="/models", description='')
|
||||||
|
|
||||||
# 调试配饰
|
# 调试配饰
|
||||||
LOCAL: int = Field(default=0, description="是否在本地运行,1表示本地运行,0表示生产环境运行")
|
LOCAL: int = Field(default=0, description="是否在本地运行,1表示本地运行,0表示生产环境运行")
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
LOGS_PATH = 'logs/'
|
LOGS_PATH = './logs/'
|
||||||
LOGGER_CONFIG_DICT = {
|
LOGGER_CONFIG_DICT = {
|
||||||
'version': 1,
|
'version': 1,
|
||||||
'disable_existing_loggers': False,
|
'disable_existing_loggers': False,
|
||||||
@@ -3,8 +3,7 @@ import os
|
|||||||
|
|
||||||
import litserve as ls
|
import litserve as ls
|
||||||
|
|
||||||
from app.config.config import settings
|
from app.logging_env import LOGGER_CONFIG_DICT
|
||||||
from logging_env import LOGGER_CONFIG_DICT
|
|
||||||
from app.server.generate_image.flux2_klein.server import Flux2KleinServer
|
from app.server.generate_image.flux2_klein.server import Flux2KleinServer
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -22,4 +21,4 @@ if __name__ == '__main__':
|
|||||||
to_product = Flux2KleinServer(api_path='/api/v1/to_product')
|
to_product = Flux2KleinServer(api_path='/api/v1/to_product')
|
||||||
|
|
||||||
server = ls.LitServer([to_product])
|
server = ls.LitServer([to_product])
|
||||||
server.run(port=settings.SERVE_PROD)
|
server.run(port=8888)
|
||||||
@@ -9,5 +9,5 @@ request_data = {
|
|||||||
"infer_step":4,
|
"infer_step":4,
|
||||||
"tasks_id":"123456-123"
|
"tasks_id":"123456-123"
|
||||||
}
|
}
|
||||||
response = requests.post("http://127.0.0.1:8012//api/v1/to_product", json=request_data)
|
response = requests.post("http://127.0.0.1:10090//api/v1/to_product", json=request_data)
|
||||||
print(f"Status: {response.status_code}\nResponse:\n {response.text}")
|
print(f"Status: {response.status_code}\nResponse:\n {response.text}")
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import io
|
import io
|
||||||
|
import os
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
import litserve as ls
|
import litserve as ls
|
||||||
from diffusers import Flux2KleinPipeline
|
from diffusers import Flux2KleinPipeline
|
||||||
@@ -15,7 +17,8 @@ class Flux2KleinServer(ls.LitAPI):
|
|||||||
# Load the model
|
# Load the model
|
||||||
dtype = torch.bfloat16
|
dtype = torch.bfloat16
|
||||||
self.device = device
|
self.device = device
|
||||||
self.model = Flux2KleinPipeline.from_pretrained("black-forest-labs/FLUX.2-klein-4B", torch_dtype=dtype, is_distilled=False)
|
model_path = os.path.join(settings.FLUX2_KLEIN_MODEL_PATH, "FLUX.2-klein-4B")
|
||||||
|
self.model = Flux2KleinPipeline.from_pretrained(model_path, torch_dtype=dtype, is_distilled=False)
|
||||||
self.model.to(device) # save some VRAM by offloading the model to CPU
|
self.model.to(device) # save some VRAM by offloading the model to CPU
|
||||||
|
|
||||||
def decode_request(self, request):
|
def decode_request(self, request):
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
# This file is auto-generated by LitServe.
|
|
||||||
# Disable auto-generation by setting `generate_client_file=False` in `LitServer.run()`.
|
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
response = requests.post("http://127.0.0.1:8012/predict", json={"input": 4.0})
|
|
||||||
print(f"Status: {response.status_code}\nResponse:\n {response.text}")
|
|
||||||
@@ -1,20 +1,17 @@
|
|||||||
services:
|
services:
|
||||||
AiDA_Model_Litserve:
|
aida_model_litserve:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
environment:
|
|
||||||
GOOGLE_APPLICATION_CREDENTIALS: /google_application_credentials.json
|
|
||||||
DEBUG: 0
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./app:/app/app
|
- ./app:/app/app
|
||||||
- ./.prod_env:/app/.env
|
- ./.env_prod:/app/.env
|
||||||
- ./data:/data
|
- ./models:/models
|
||||||
- ./google_application_credentials.json:/google_application_credentials.json
|
- ./logs:/app/logs
|
||||||
- /etc/localtime:/etc/localtime:ro
|
- /etc/localtime:/etc/localtime:ro
|
||||||
ports:
|
ports:
|
||||||
- "10070:8000"
|
- "${SERVE_PORT}:8888"
|
||||||
deploy:
|
deploy:
|
||||||
resources:
|
resources:
|
||||||
reservations:
|
reservations:
|
||||||
|
|||||||
1
download_model.sh
Normal file
1
download_model.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
huggingface-cli download black-forest-labs/FLUX.2-klein-4B --local-dir /data/models/FLUX.2-klein-4B
|
||||||
Reference in New Issue
Block a user