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

XFEstudio/gpt4free

Use ImageOps

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

代码差异

2 个文件 +6 -21
Modified g4f/Provider/needs_auth/GeminiPro.py +2 -2
@@ -13,7 +13,7 @@ from ...errors import MissingAuthError, ModelNotFoundError
13 13 from ...requests.raise_for_status import raise_for_status
14 14 from ...providers.response import Usage, FinishReason
15 15 from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
16 from ..helper import get_connector
16 from ..helper import get_connector, to_string
17 17 from ... import debug
18 18
19 19 class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin):
@@ -102,7 +102,7 @@ class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin):
102 102 contents = [
103 103 {
104 104 "role": "model" if message["role"] == "assistant" else "user",
105 "parts": [{"text": message["content"]}]
105 "parts": [{"text": to_string(message["content"])}]
106 106 }
107 107 for message in messages
108 108 if message["role"] != "system"
Modified g4f/image/__init__.py +4 -19
@@ -7,19 +7,16 @@ import base64
7 7 from io import BytesIO
8 8 from pathlib import Path
9 9 from typing import Optional
10 from collections import defaultdict
11 10
12 11 try:
13 from PIL.Image import open as open_image, new as new_image
14 from PIL.Image import ROTATE_180, ROTATE_90
15 from PIL import Image, ExifTags
12 from PIL import Image, ImageOps
13 from PIL import open as open_image
16 14 has_requirements = True
17 15 except ImportError:
18 16 has_requirements = False
19 17
20 18 from ..typing import ImageType, Image
21 19 from ..errors import MissingRequirementsError
22 from .. import debug
23 20
24 21 EXTENSIONS_MAP: dict[str, str] = {
25 22 # Image
@@ -218,24 +215,12 @@ def process_image(image: Image, new_width: int = 800, new_height: int = 400, sav
218 215 Returns:
219 216 Image: The processed image.
220 217 """
221 for orientation in ExifTags.TAGS.keys():
222 if ExifTags.TAGS[orientation] == 'Orientation': break
223 if hasattr(image, 'getexif'):
224 exif_data = image.getexif()
225 else:
226 exif_data = image._getexif()
227 exif = dict(exif_data.items())
228 if exif[orientation] == 3 :
229 image = image.rotate(180, expand=True)
230 elif exif[orientation] == 6 :
231 image = image.rotate(270, expand=True)
232 elif exif[orientation] == 8 :
233 image = image.rotate(90, expand=True)
218 image = ImageOps.exif_transpose(image)
234 219 image.thumbnail((new_width, new_height), Image.ANTIALIAS)
235 220 # Remove transparency
236 221 if image.mode == "RGBA":
237 222 image.load()
238 white = new_image('RGB', image.size, (255, 255, 255))
223 white = open_image('RGB', image.size, (255, 255, 255))
239 224 white.paste(image, mask=image.split()[-1])
240 225 return white
241 226 # Convert to RGB for jpg format