summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/airforce/AirforceImage.py
diff options
context:
space:
mode:
authorkqlio67 <kqlio67@users.noreply.github.com>2024-11-08 18:20:21 +0100
committerkqlio67 <kqlio67@users.noreply.github.com>2024-11-08 18:20:21 +0100
commitdb347ef09734f9292ba449b242186d89746c0b64 (patch)
tree673b96af58ac149c12bdc9d208e47eb4fc2223d3 /g4f/Provider/airforce/AirforceImage.py
parentUpdate (g4f/client/) (diff)
downloadgpt4free-db347ef09734f9292ba449b242186d89746c0b64.tar
gpt4free-db347ef09734f9292ba449b242186d89746c0b64.tar.gz
gpt4free-db347ef09734f9292ba449b242186d89746c0b64.tar.bz2
gpt4free-db347ef09734f9292ba449b242186d89746c0b64.tar.lz
gpt4free-db347ef09734f9292ba449b242186d89746c0b64.tar.xz
gpt4free-db347ef09734f9292ba449b242186d89746c0b64.tar.zst
gpt4free-db347ef09734f9292ba449b242186d89746c0b64.zip
Diffstat (limited to 'g4f/Provider/airforce/AirforceImage.py')
-rw-r--r--g4f/Provider/airforce/AirforceImage.py55
1 files changed, 24 insertions, 31 deletions
diff --git a/g4f/Provider/airforce/AirforceImage.py b/g4f/Provider/airforce/AirforceImage.py
index 010d1a94..443c0f6b 100644
--- a/g4f/Provider/airforce/AirforceImage.py
+++ b/g4f/Provider/airforce/AirforceImage.py
@@ -1,46 +1,47 @@
from __future__ import annotations
from aiohttp import ClientSession
+from urllib.parse import urlencode
import random
from ...typing import AsyncResult, Messages
-from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
from ...image import ImageResponse
+from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
class AirforceImage(AsyncGeneratorProvider, ProviderModelMixin):
label = "Airforce Image"
#url = "https://api.airforce"
- api_endpoint_imagine2 = "https://api.airforce/imagine2"
+ api_endpoint = "https://api.airforce/imagine2"
#working = True
default_model = 'flux'
image_models = [
'flux',
- 'flux-realism',
+ 'flux-realism',
'flux-anime',
'flux-3d',
'flux-disney',
'flux-pixel',
'flux-4o',
'any-dark',
+ 'any-uncensored',
'stable-diffusion-xl-base',
'stable-diffusion-xl-lightning',
+ 'Flux-1.1-Pro',
]
models = [*image_models]
model_aliases = {
"sdxl": "stable-diffusion-xl-base",
- "sdxl": "stable-diffusion-xl-lightning",
+ "sdxl": "stable-diffusion-xl-lightning",
+ "flux-pro": "Flux-1.1-Pro",
}
-
-
+
@classmethod
def get_model(cls, model: str) -> str:
if model in cls.models:
return model
- elif model in cls.model_aliases:
- return cls.model_aliases[model]
else:
return cls.default_model
@@ -49,49 +50,41 @@ class AirforceImage(AsyncGeneratorProvider, ProviderModelMixin):
cls,
model: str,
messages: Messages,
- size: str = '1:1',
+ size: str = '1:1', # "1:1", "16:9", "9:16", "21:9", "9:21", "1:2", "2:1"
proxy: str = None,
**kwargs
) -> AsyncResult:
model = cls.get_model(model)
headers = {
- 'accept': '*/*',
+ 'accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
'accept-language': 'en-US,en;q=0.9',
- 'authorization': 'Bearer missing api key',
'cache-control': 'no-cache',
- 'origin': 'https://llmplayground.net',
+ 'dnt': '1',
'pragma': 'no-cache',
'priority': 'u=1, i',
'referer': 'https://llmplayground.net/',
'sec-ch-ua': '"Not?A_Brand";v="99", "Chromium";v="130"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Linux"',
- 'sec-fetch-dest': 'empty',
- 'sec-fetch-mode': 'cors',
+ 'sec-fetch-dest': 'image',
+ 'sec-fetch-mode': 'no-cors',
'sec-fetch-site': 'cross-site',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36'
}
-
+
async with ClientSession(headers=headers) as session:
- prompt = messages[-1]['content']
- seed = random.randint(0, 4294967295)
+ seed = random.randint(0, 58463)
params = {
'model': model,
- 'prompt': prompt,
+ 'prompt': messages[-1]["content"],
'size': size,
- 'seed': str(seed)
+ 'seed': seed
}
- async with session.get(cls.api_endpoint_imagine2, params=params, proxy=proxy) as response:
- response.raise_for_status()
- if response.status == 200:
- content_type = response.headers.get('Content-Type', '')
- if 'image' in content_type:
- image_url = str(response.url)
- yield ImageResponse(image_url, alt="Airforce generated image")
- else:
- content = await response.text()
- yield f"Unexpected content type: {content_type}\nResponse content: {content}"
+ full_url = f"{cls.api_endpoint}?{urlencode(params)}"
+
+ async with session.get(full_url, headers=headers, proxy=proxy) as response:
+ if response.status == 200 and response.headers.get('content-type', '').startswith('image'):
+ yield ImageResponse(images=[full_url], alt="Generated Image")
else:
- error_content = await response.text()
- yield f"Error: {error_content}"
+ raise Exception(f"Error: status {response.status}, content type {response.headers.get('content-type')}")