XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/gpt4free

Refactor Dockerfile and backend API for improved image processing and dependency management

9b3e7a69
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

4 个文件 +9 -22
Modified docker/Dockerfile-armv7 +1 -18
@@ -3,7 +3,6 @@ FROM python:slim-bookworm
3 3 ARG G4F_VERSION
4 4 ARG G4F_USER=g4f
5 5 ARG G4F_USER_ID=1000
6 ARG PYDANTIC_VERSION=1.8.1
7 6
8 7 ENV G4F_VERSION $G4F_VERSION
9 8 ENV G4F_USER $G4F_USER
@@ -37,25 +36,9 @@ COPY requirements-min.txt $G4F_DIR
37 36 COPY requirements-slim.txt $G4F_DIR
38 37
39 38 # Upgrade pip for the latest features and install the project's Python dependencies.
40 RUN pip install --no-cache-dir -r requirements-min.txt \
41 && pip install --no-cache-dir --no-binary setuptools \
42 Cython==0.29.22 \
43 setuptools \
44 # Install PyDantic
45 && pip install \
46 -vvv \
47 --no-cache-dir \
48 --no-binary :all: \
49 --global-option=build_ext \
50 --global-option=-j8 \
51 pydantic==${PYDANTIC_VERSION}
39 RUN pip install --no-cache-dir -r requirements-min.txt
52 40 RUN cat requirements-slim.txt | xargs -n 1 timeout 5m pip install --no-cache-dir || true
53 41
54 # Remove build packages
55 RUN pip uninstall --yes \
56 Cython \
57 setuptools
58
59 42 USER root
60 43
61 44 # Clean up build deps
Modified g4f/gui/server/backend_api.py +5 -2
@@ -21,7 +21,7 @@ from urllib.parse import quote_plus
21 21 from hashlib import sha256
22 22
23 23 try:
24 from PIL import Image
24 from PIL import Image, UnidentifiedImageError
25 25 has_pillow = True
26 26 except ImportError:
27 27 has_pillow = False
@@ -452,7 +452,10 @@ class Backend_Api(Api):
452 452 image_size = {"width": width, "height": height}
453 453 thumbnail_dir = os.path.join(bucket_dir, "thumbnail")
454 454 os.makedirs(thumbnail_dir, exist_ok=True)
455 process_image(image, save=os.path.join(thumbnail_dir, filename))
455 width, height = process_image(image, save=os.path.join(thumbnail_dir, filename))
456 image_size = {"width": width, "height": height}
457 except UnidentifiedImageError:
458 pass
456 459 except Exception as e:
457 460 logger.exception(e)
458 461 if result:
Modified g4f/image/__init__.py +3 -1
@@ -341,7 +341,6 @@ def process_image(image: Image.Image, new_width: int = 400, new_height: int = 40
341 341 Image: The processed image.
342 342 """
343 343 image = ImageOps.exif_transpose(image)
344 image.thumbnail((new_width, new_height))
345 344 # Remove transparency
346 345 if image.mode == "RGBA":
347 346 # image.load()
@@ -352,8 +351,11 @@ def process_image(image: Image.Image, new_width: int = 400, new_height: int = 40
352 351 # Convert to RGB for jpg format
353 352 elif image.mode != "RGB":
354 353 image = image.convert("RGB")
354 image_size = image.size
355 image.thumbnail((new_width, new_height))
355 356 if save is not None:
356 357 image.save(save, exif=b"")
358 return image_size
357 359 return image
358 360
359 361 def to_bytes(image: ImageType) -> bytes:
Modified requirements.txt +0 -1
@@ -14,7 +14,6 @@ flask
14 14 brotli
15 15 beautifulsoup4
16 16 setuptools
17 nodriver
18 17 python-multipart
19 18 a2wsgi
20 19 python-dotenv