first cimmit

This commit is contained in:
zcr
2026-01-26 11:40:11 +08:00
parent 71400cff38
commit dc2c1ddb03
11 changed files with 27 additions and 27 deletions

2
.dockerignore Normal file
View File

@@ -0,0 +1,2 @@
models
test

3
.gitignore vendored
View File

@@ -150,4 +150,5 @@ app/logs/*
*.avi
*.json
*.env*
config.backup.py
config.backup.py
models

View File

@@ -16,20 +16,21 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
ca-certificates \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY pyproject.toml uv.lock ./
COPY pyproject.toml uv.lock download_model.sh ./
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. 拷贝项目文件并安装项目本身
COPY . .
RUN uv sync --frozen --no-dev --python 3.10
#COPY . .
RUN uv sync --frozen --no-dev --python 3.13
ENV PATH="/app/.venv/bin:$PATH"

View File

@@ -17,7 +17,10 @@ class Settings(BaseSettings):
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表示生产环境运行")

View File

@@ -1,4 +1,4 @@
LOGS_PATH = 'logs/'
LOGS_PATH = './logs/'
LOGGER_CONFIG_DICT = {
'version': 1,
'disable_existing_loggers': False,

View File

@@ -3,8 +3,7 @@ import os
import litserve as ls
from app.config.config import settings
from logging_env import LOGGER_CONFIG_DICT
from app.logging_env import LOGGER_CONFIG_DICT
from app.server.generate_image.flux2_klein.server import Flux2KleinServer
logger = logging.getLogger(__name__)
@@ -22,4 +21,4 @@ if __name__ == '__main__':
to_product = Flux2KleinServer(api_path='/api/v1/to_product')
server = ls.LitServer([to_product])
server.run(port=settings.SERVE_PROD)
server.run(port=8888)

View File

@@ -9,5 +9,5 @@ request_data = {
"infer_step":4,
"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}")

View File

@@ -1,4 +1,6 @@
import io
import os
import torch
import litserve as ls
from diffusers import Flux2KleinPipeline
@@ -15,7 +17,8 @@ class Flux2KleinServer(ls.LitAPI):
# Load the model
dtype = torch.bfloat16
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
def decode_request(self, request):

View File

@@ -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}")

View File

@@ -1,20 +1,17 @@
services:
AiDA_Model_Litserve:
aida_model_litserve:
build:
context: .
dockerfile: Dockerfile
working_dir: /app
environment:
GOOGLE_APPLICATION_CREDENTIALS: /google_application_credentials.json
DEBUG: 0
volumes:
- ./app:/app/app
- ./.prod_env:/app/.env
- ./data:/data
- ./google_application_credentials.json:/google_application_credentials.json
- ./.env_prod:/app/.env
- ./models:/models
- ./logs:/app/logs
- /etc/localtime:/etc/localtime:ro
ports:
- "10070:8000"
- "${SERVE_PORT}:8888"
deploy:
resources:
reservations:

1
download_model.sh Normal file
View File

@@ -0,0 +1 @@
huggingface-cli download black-forest-labs/FLUX.2-klein-4B --local-dir /data/models/FLUX.2-klein-4B