From 80b2e9b80774c558cb863841e7e8214fbc0eca67 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 20 May 2024 01:28:08 +0200 Subject: Add some options to messages in gui, saves generated images local --- .gitignore | 3 ++- README.md | 7 +++++- g4f/Provider/needs_auth/Gemini.py | 9 ++------ g4f/client/async_client.py | 3 ++- g4f/gui/client/index.html | 4 ++-- g4f/gui/client/static/css/style.css | 42 +++++++++++++++++++++++++-------- g4f/gui/client/static/js/chat.v1.js | 24 +++++++++++++++++++ g4f/gui/server/api.py | 46 ++++++++++++++++++++++++++++--------- g4f/gui/server/backend.py | 8 +++---- generated_images/.gitkeep | 0 10 files changed, 109 insertions(+), 37 deletions(-) create mode 100644 generated_images/.gitkeep diff --git a/.gitignore b/.gitignore index 3803a710..8d678a0f 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,5 @@ dist.py x.txt bench.py to-reverse.txt -g4f/Provider/OpenaiChat2.py \ No newline at end of file +g4f/Provider/OpenaiChat2.py +generated_images/ \ No newline at end of file diff --git a/README.md b/README.md index 65baf7ad..ddcaf318 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,12 @@ As per the survey, here is a list of improvements to come ```sh docker pull hlohaus789/g4f -docker run -p 8080:8080 -p 1337:1337 -p 7900:7900 --shm-size="2g" -v ${PWD}/har_and_cookies:/app/har_and_cookies hlohaus789/g4f:latest +docker run \ + -p 8080:8080 -p 1337:1337 -p 7900:7900 \ + --shm-size="2g" \ + -v ${PWD}/har_and_cookies:/app/har_and_cookies \ + -v ${PWD}/generated_images:/app/generated_images \ + hlohaus789/g4f:latest ``` 3. **Access the Client:** diff --git a/g4f/Provider/needs_auth/Gemini.py b/g4f/Provider/needs_auth/Gemini.py index f9b1c4a5..71cc8d81 100644 --- a/g4f/Provider/needs_auth/Gemini.py +++ b/g4f/Provider/needs_auth/Gemini.py @@ -4,7 +4,6 @@ import os import json import random import re -import base64 from aiohttp import ClientSession, BaseConnector @@ -193,14 +192,10 @@ class Gemini(AsyncGeneratorProvider): yield content if image_prompt: images = [image[0][3][3] for image in response_part[4][0][12][7][0]] - resolved_images = [] if response_format == "b64_json": - for image in images: - async with client.get(image) as response: - data = base64.b64encode(await response.content.read()).decode() - resolved_images.append(data) - yield ImageDataResponse(resolved_images, image_prompt) + yield ImageResponse(images, image_prompt, {"cookies": cls._cookies}) else: + resolved_images = [] preview = [] for image in images: async with client.get(image, allow_redirects=False) as fetch: diff --git a/g4f/client/async_client.py b/g4f/client/async_client.py index 1508e566..a97b4d7a 100644 --- a/g4f/client/async_client.py +++ b/g4f/client/async_client.py @@ -171,7 +171,8 @@ async def iter_image_response( if isinstance(chunk, ImageProviderResponse): if response_format == "b64_json": async with ClientSession( - connector=get_connector(connector, proxy) + connector=get_connector(connector, proxy), + cookies=chunk.options.get("cookies") ) as session: async def fetch_image(image): async with session.get(image) as response: diff --git a/g4f/gui/client/index.html b/g4f/gui/client/index.html index 3c428f38..a2f883d9 100644 --- a/g4f/gui/client/index.html +++ b/g4f/gui/client/index.html @@ -32,10 +32,10 @@ - - +