From 151f8b8b0e409b112c806927250d5f578f0f6805 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 12 Feb 2024 12:08:08 +0100 Subject: Add variant example --- README.md | 3 +++ docs/cat.webp | Bin 0 -> 5876 bytes docs/client.md | 6 ++++++ g4f/client.py | 16 +++++++++++----- 4 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 docs/cat.webp diff --git a/README.md b/README.md index dc7ef933..f7e9f0f7 100644 --- a/README.md +++ b/README.md @@ -227,6 +227,9 @@ docker-compose down ## 💡 Usage ### New Client with Image Generation + +#### not jet released + ```python from g4f.client import Client diff --git a/docs/cat.webp b/docs/cat.webp new file mode 100644 index 00000000..29c13f59 Binary files /dev/null and b/docs/cat.webp differ diff --git a/docs/client.md b/docs/client.md index 1201a83d..deb5b0ba 100644 --- a/docs/client.md +++ b/docs/client.md @@ -68,4 +68,10 @@ response = client.images.create_variation( image_url = response.data[0].url ``` +Orginal: +[![Image with cat](/docs/cat.jpeg)](/docs/client.md) + +Variant: +[![Image with cat](/docs/cat.webp)](/docs/client.md) + [to Home](/docs/client.md) diff --git a/g4f/client.py b/g4f/client.py index 117db375..03b0eda3 100644 --- a/g4f/client.py +++ b/g4f/client.py @@ -241,7 +241,8 @@ class Images(): "", [{"role": "user", "content": prompt}], True, - proxy=self.client.get_proxy() + proxy=self.client.get_proxy(), + **kwargs ) else: response = provider.create(prompt) @@ -253,15 +254,20 @@ class Images(): def create_variation(self, image: ImageType, model: str = None, **kwargs): provider = self.models.get(model) if model else self.provider - if isinstance(provider, BaseProvider): + result = None + if isinstance(provider, type) and issubclass(provider, BaseProvider): response = provider.create_completion( "", [{"role": "user", "content": "create a image like this"}], True, image=image, - proxy=self.client.get_proxy() + proxy=self.client.get_proxy(), + **kwargs ) for chunk in response: if isinstance(chunk, ImageProviderResponse): - return ImagesResponse([Image(image)for image in list(chunk.images)]) - raise NoImageResponseError() \ No newline at end of file + result = ([chunk.images] if isinstance(chunk.images, str) else chunk.images) + result = ImagesResponse([Image(image)for image in result]) + if result is None: + raise NoImageResponseError() + return result \ No newline at end of file -- cgit v1.2.3