返回提交历史
Modified
g4f/image/__init__.py
+9
-0
XFEstudio/gpt4free
Update __init__.py
4047ac56
代码差异
1 个文件
+9
-0
@@ -9,6 +9,8 @@ from pathlib import Path
9
9
from typing import Optional
10
10
from urllib.parse import urlparse
11
11
12
import requests
13
12
14
try:
13
15
from PIL import Image, ImageOps
14
16
has_requirements = True
@@ -383,6 +385,13 @@ def to_bytes(image: ImageType) -> bytes:
383
385
return Path(path).read_bytes()
384
386
else:
385
387
raise FileNotFoundError(f"File not found: {path}")
388
else:
389
resp = requests.get(image, headers={
390
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0",
391
})
392
if resp.ok and is_accepted_format(resp.content):
393
return resp.content
394
raise ValueError("Invalid image url. Expected bytes, str, or PIL Image.")
386
395
else:
387
396
raise ValueError("Invalid image format. Expected bytes, str, or PIL Image.")
388
397
elif isinstance(image, Image.Image):