feat: add 'transparent' image model and refactor HAR provider auth flow

- Added "transparent" to `image_models` in `PollinationsAI` and mapped it to "gptimage"
- Modified transparent flag handling in `_generate_image` call in `PollinationsAI`
- Removed unused `cls.get_models()` call from image generation method in `PollinationsAI`
- Replaced `AsyncGeneratorProvider` with `AsyncAuthedProvider` in `HarProvider`
- Implemented `on_auth_async` in `HarProvider` to support browser-based auth via `nodriver`
- Replaced `create_async_generator` with `create_authed` in `HarProvider` to support `AuthResult`
- Removed custom `headers` in HAR post requests; used `auth_result.get_dict()` for `StreamSession`
- Refactored `Video` provider to support optional search in `get_response`
- Added `search` parameter to `RequestConfig.get_response` and `Video.create_async_generator`
- Improved browser automation and element interaction logic in `Video` provider
- Extracted video request interception to collect URLs using `nodriver`
- Reduced video polling loop timeout from 600 to 300 iterations in `Video`
- Updated CLI `client.py` to fix handling of `conversation.conversation` assignment
- Fixed argparse config: removed `nargs='?'` and added `metavar` for `--conversation-file`
- Improved image metadata extraction in API and backend when Pillow is available
- Modified `ImageResponse.__str__` to output HTML anchor/image tags with dimensions if present
- Added support for returning `target_path` from `copy_media` if `return_target` is True
- Changed default image processing size in `process_image` from 800x400 to 400x400
- Disabled RGBA-to-RGB flattening in `process_image`
- Improved `get_args_from_nodriver` to ensure proper referer and cookie handling
- Added helper `get_target_paths_and_urls` in `Api` to extract image dimensions from disk paths
This commit is contained in:
hlohaus 2025-07-11 01:46:32 +02:00
parent 48e3577033
commit 3c66fa114a
14 changed files with 207 additions and 127 deletions

View file

@ -46,7 +46,6 @@ from ...image import is_allowed_extension, process_image, MEDIA_TYPE_MAP
from ...cookies import get_cookies_dir
from ...image.copy_images import secure_filename, get_source_url, get_media_dir, copy_media
from ...client.service import get_model_and_provider
from ... import ChatCompletion
from ... import models
from .api import Api
@ -442,18 +441,21 @@ class Backend_Api(Api):
if is_media:
os.makedirs(media_dir, exist_ok=True)
newfile = os.path.join(media_dir, filename)
if result:
media.append({"name": filename, "text": result})
else:
media.append({"name": filename})
image_size = {}
if has_pillow:
try:
image = Image.open(copyfile)
width, height = image.size
image_size = {"width": width, "height": height}
thumbnail_dir = os.path.join(bucket_dir, "thumbnail")
os.makedirs(thumbnail_dir, exist_ok=True)
process_image(image, save=os.path.join(thumbnail_dir, filename))
except Exception as e:
logger.exception(e)
if result:
media.append({"name": filename, "text": result, **image_size})
else:
media.append({"name": filename, **image_size})
elif is_supported and not result:
newfile = os.path.join(bucket_dir, filename)
filenames.append(filename)