webscout 8.2.9__py3-none-any.whl → 8.3.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webscout might be problematic. Click here for more details.
- webscout/AIauto.py +6 -6
- webscout/AIbase.py +61 -1
- webscout/Extra/YTToolkit/ytapi/patterns.py +45 -45
- webscout/Extra/YTToolkit/ytapi/stream.py +1 -1
- webscout/Extra/YTToolkit/ytapi/video.py +10 -10
- webscout/Extra/autocoder/autocoder_utiles.py +1 -1
- webscout/Litlogger/formats.py +9 -0
- webscout/Litlogger/handlers.py +18 -0
- webscout/Litlogger/logger.py +43 -1
- webscout/Provider/AISEARCH/scira_search.py +3 -2
- webscout/Provider/Blackboxai.py +2 -0
- webscout/Provider/ChatSandbox.py +2 -1
- webscout/Provider/Deepinfra.py +1 -1
- webscout/Provider/HeckAI.py +1 -1
- webscout/Provider/LambdaChat.py +8 -1
- webscout/Provider/MCPCore.py +7 -3
- webscout/Provider/OPENAI/BLACKBOXAI.py +396 -113
- webscout/Provider/OPENAI/Cloudflare.py +31 -14
- webscout/Provider/OPENAI/FalconH1.py +457 -0
- webscout/Provider/OPENAI/FreeGemini.py +29 -13
- webscout/Provider/OPENAI/NEMOTRON.py +26 -14
- webscout/Provider/OPENAI/PI.py +427 -0
- webscout/Provider/OPENAI/Qwen3.py +161 -140
- webscout/Provider/OPENAI/README.md +3 -0
- webscout/Provider/OPENAI/TogetherAI.py +355 -0
- webscout/Provider/OPENAI/TwoAI.py +29 -12
- webscout/Provider/OPENAI/__init__.py +4 -1
- webscout/Provider/OPENAI/ai4chat.py +33 -23
- webscout/Provider/OPENAI/api.py +375 -24
- webscout/Provider/OPENAI/autoproxy.py +39 -0
- webscout/Provider/OPENAI/base.py +91 -12
- webscout/Provider/OPENAI/c4ai.py +31 -10
- webscout/Provider/OPENAI/chatgpt.py +56 -24
- webscout/Provider/OPENAI/chatgptclone.py +46 -16
- webscout/Provider/OPENAI/chatsandbox.py +7 -3
- webscout/Provider/OPENAI/copilot.py +26 -10
- webscout/Provider/OPENAI/deepinfra.py +29 -12
- webscout/Provider/OPENAI/e2b.py +358 -158
- webscout/Provider/OPENAI/exaai.py +13 -10
- webscout/Provider/OPENAI/exachat.py +10 -6
- webscout/Provider/OPENAI/flowith.py +7 -3
- webscout/Provider/OPENAI/freeaichat.py +10 -6
- webscout/Provider/OPENAI/glider.py +10 -6
- webscout/Provider/OPENAI/heckai.py +11 -8
- webscout/Provider/OPENAI/llmchatco.py +9 -7
- webscout/Provider/OPENAI/mcpcore.py +10 -7
- webscout/Provider/OPENAI/multichat.py +3 -1
- webscout/Provider/OPENAI/netwrck.py +10 -6
- webscout/Provider/OPENAI/oivscode.py +12 -9
- webscout/Provider/OPENAI/opkfc.py +31 -8
- webscout/Provider/OPENAI/scirachat.py +17 -10
- webscout/Provider/OPENAI/sonus.py +10 -6
- webscout/Provider/OPENAI/standardinput.py +18 -9
- webscout/Provider/OPENAI/textpollinations.py +14 -7
- webscout/Provider/OPENAI/toolbaz.py +16 -11
- webscout/Provider/OPENAI/typefully.py +14 -7
- webscout/Provider/OPENAI/typegpt.py +10 -6
- webscout/Provider/OPENAI/uncovrAI.py +22 -8
- webscout/Provider/OPENAI/venice.py +10 -6
- webscout/Provider/OPENAI/writecream.py +13 -10
- webscout/Provider/OPENAI/x0gpt.py +11 -9
- webscout/Provider/OPENAI/yep.py +12 -10
- webscout/Provider/PI.py +2 -1
- webscout/Provider/STT/__init__.py +3 -0
- webscout/Provider/STT/base.py +281 -0
- webscout/Provider/STT/elevenlabs.py +265 -0
- webscout/Provider/TTI/__init__.py +3 -1
- webscout/Provider/TTI/aiarta.py +399 -365
- webscout/Provider/TTI/base.py +74 -2
- webscout/Provider/TTI/fastflux.py +63 -30
- webscout/Provider/TTI/gpt1image.py +149 -0
- webscout/Provider/TTI/imagen.py +196 -0
- webscout/Provider/TTI/magicstudio.py +60 -29
- webscout/Provider/TTI/piclumen.py +43 -32
- webscout/Provider/TTI/pixelmuse.py +232 -225
- webscout/Provider/TTI/pollinations.py +43 -32
- webscout/Provider/TTI/together.py +287 -0
- webscout/Provider/TTI/utils.py +2 -1
- webscout/Provider/TTS/README.md +1 -0
- webscout/Provider/TTS/__init__.py +2 -1
- webscout/Provider/TTS/freetts.py +140 -0
- webscout/Provider/UNFINISHED/ChutesAI.py +314 -0
- webscout/Provider/UNFINISHED/fetch_together_models.py +95 -0
- webscout/Provider/__init__.py +3 -2
- webscout/Provider/granite.py +41 -6
- webscout/Provider/oivscode.py +37 -37
- webscout/Provider/scira_chat.py +3 -2
- webscout/Provider/scnet.py +1 -0
- webscout/Provider/toolbaz.py +0 -1
- webscout/litagent/Readme.md +12 -3
- webscout/litagent/agent.py +99 -62
- webscout/version.py +1 -1
- {webscout-8.2.9.dist-info → webscout-8.3.1.dist-info}/METADATA +2 -1
- {webscout-8.2.9.dist-info → webscout-8.3.1.dist-info}/RECORD +98 -87
- {webscout-8.2.9.dist-info → webscout-8.3.1.dist-info}/WHEEL +1 -1
- webscout/Provider/ChatGPTGratis.py +0 -194
- webscout/Provider/TTI/artbit.py +0 -0
- {webscout-8.2.9.dist-info → webscout-8.3.1.dist-info}/entry_points.txt +0 -0
- {webscout-8.2.9.dist-info → webscout-8.3.1.dist-info}/licenses/LICENSE.md +0 -0
- {webscout-8.2.9.dist-info → webscout-8.3.1.dist-info}/top_level.txt +0 -0
webscout/Provider/TTI/aiarta.py
CHANGED
|
@@ -1,365 +1,399 @@
|
|
|
1
|
-
"""AIArtaImager TTI-Compatible Provider - Generate stunning AI art with AI Arta! 🎨
|
|
2
|
-
|
|
3
|
-
Examples:
|
|
4
|
-
>>> from webscout.Provider.TTI.aiarta import AIArta
|
|
5
|
-
>>> client = AIArta()
|
|
6
|
-
>>> response = client.images.create(
|
|
7
|
-
... model="flux",
|
|
8
|
-
... prompt="A cool cyberpunk city at night",
|
|
9
|
-
... n=1
|
|
10
|
-
... )
|
|
11
|
-
>>> print(response)
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
import requests
|
|
15
|
-
from typing import Optional, List, Dict, Any
|
|
16
|
-
from webscout.Provider.TTI.utils import
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import
|
|
21
|
-
from
|
|
22
|
-
import
|
|
23
|
-
import
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
image_format:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
with
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
"
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
"
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
"
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
"
|
|
247
|
-
"
|
|
248
|
-
"
|
|
249
|
-
"
|
|
250
|
-
"
|
|
251
|
-
"
|
|
252
|
-
"
|
|
253
|
-
"
|
|
254
|
-
"
|
|
255
|
-
"
|
|
256
|
-
"
|
|
257
|
-
"
|
|
258
|
-
"
|
|
259
|
-
"
|
|
260
|
-
"
|
|
261
|
-
"
|
|
262
|
-
"
|
|
263
|
-
"
|
|
264
|
-
"
|
|
265
|
-
"
|
|
266
|
-
"
|
|
267
|
-
"
|
|
268
|
-
"
|
|
269
|
-
"
|
|
270
|
-
"
|
|
271
|
-
"
|
|
272
|
-
"
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
1
|
+
"""AIArtaImager TTI-Compatible Provider - Generate stunning AI art with AI Arta! 🎨
|
|
2
|
+
|
|
3
|
+
Examples:
|
|
4
|
+
>>> from webscout.Provider.TTI.aiarta import AIArta
|
|
5
|
+
>>> client = AIArta()
|
|
6
|
+
>>> response = client.images.create(
|
|
7
|
+
... model="flux",
|
|
8
|
+
... prompt="A cool cyberpunk city at night",
|
|
9
|
+
... n=1
|
|
10
|
+
... )
|
|
11
|
+
>>> print(response)
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import requests
|
|
15
|
+
from typing import Optional, List, Dict, Any
|
|
16
|
+
from webscout.Provider.TTI.utils import (
|
|
17
|
+
ImageData,
|
|
18
|
+
ImageResponse
|
|
19
|
+
)
|
|
20
|
+
from webscout.Provider.TTI.base import TTICompatibleProvider, BaseImages
|
|
21
|
+
from io import BytesIO
|
|
22
|
+
import os
|
|
23
|
+
import tempfile
|
|
24
|
+
from webscout.litagent import LitAgent
|
|
25
|
+
import time
|
|
26
|
+
import json
|
|
27
|
+
|
|
28
|
+
try:
|
|
29
|
+
from PIL import Image
|
|
30
|
+
except ImportError:
|
|
31
|
+
Image = None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Images(BaseImages):
|
|
35
|
+
def __init__(self, client: "AIArta"):
|
|
36
|
+
self._client = client
|
|
37
|
+
|
|
38
|
+
def create(
|
|
39
|
+
self,
|
|
40
|
+
*,
|
|
41
|
+
model: str,
|
|
42
|
+
prompt: str,
|
|
43
|
+
n: int = 1,
|
|
44
|
+
size: str = "1024x1024",
|
|
45
|
+
response_format: str = "url",
|
|
46
|
+
user: Optional[str] = None,
|
|
47
|
+
style: str = "none",
|
|
48
|
+
aspect_ratio: str = "1:1",
|
|
49
|
+
timeout: int = 60,
|
|
50
|
+
image_format: str = "png",
|
|
51
|
+
**kwargs,
|
|
52
|
+
) -> ImageResponse:
|
|
53
|
+
"""
|
|
54
|
+
image_format: "png" or "jpeg"
|
|
55
|
+
"""
|
|
56
|
+
if Image is None:
|
|
57
|
+
raise ImportError("Pillow (PIL) is required for image format conversion.")
|
|
58
|
+
|
|
59
|
+
images = []
|
|
60
|
+
urls = []
|
|
61
|
+
agent = LitAgent()
|
|
62
|
+
|
|
63
|
+
def upload_file_with_retry(img_bytes, image_format, max_retries=3):
|
|
64
|
+
ext = "jpg" if image_format.lower() == "jpeg" else "png"
|
|
65
|
+
for attempt in range(max_retries):
|
|
66
|
+
tmp_path = None
|
|
67
|
+
try:
|
|
68
|
+
with tempfile.NamedTemporaryFile(
|
|
69
|
+
suffix=f".{ext}", delete=False
|
|
70
|
+
) as tmp:
|
|
71
|
+
tmp.write(img_bytes)
|
|
72
|
+
tmp.flush()
|
|
73
|
+
tmp_path = tmp.name
|
|
74
|
+
with open(tmp_path, "rb") as f:
|
|
75
|
+
files = {"fileToUpload": (f"image.{ext}", f, f"image/{ext}")}
|
|
76
|
+
data = {"reqtype": "fileupload", "json": "true"}
|
|
77
|
+
headers = {"User-Agent": agent.random()}
|
|
78
|
+
if attempt > 0:
|
|
79
|
+
headers["Connection"] = "close"
|
|
80
|
+
resp = requests.post(
|
|
81
|
+
"https://catbox.moe/user/api.php",
|
|
82
|
+
files=files,
|
|
83
|
+
data=data,
|
|
84
|
+
headers=headers,
|
|
85
|
+
timeout=timeout,
|
|
86
|
+
)
|
|
87
|
+
if resp.status_code == 200 and resp.text.strip():
|
|
88
|
+
text = resp.text.strip()
|
|
89
|
+
if text.startswith("http"):
|
|
90
|
+
return text
|
|
91
|
+
try:
|
|
92
|
+
result = resp.json()
|
|
93
|
+
if "url" in result:
|
|
94
|
+
return result["url"]
|
|
95
|
+
except json.JSONDecodeError:
|
|
96
|
+
if "http" in text:
|
|
97
|
+
return text
|
|
98
|
+
except Exception:
|
|
99
|
+
if attempt < max_retries - 1:
|
|
100
|
+
time.sleep(1 * (attempt + 1))
|
|
101
|
+
finally:
|
|
102
|
+
if tmp_path and os.path.isfile(tmp_path):
|
|
103
|
+
try:
|
|
104
|
+
os.remove(tmp_path)
|
|
105
|
+
except Exception:
|
|
106
|
+
pass
|
|
107
|
+
return None
|
|
108
|
+
|
|
109
|
+
def upload_file_alternative(img_bytes, image_format):
|
|
110
|
+
try:
|
|
111
|
+
ext = "jpg" if image_format.lower() == "jpeg" else "png"
|
|
112
|
+
with tempfile.NamedTemporaryFile(suffix=f".{ext}", delete=False) as tmp:
|
|
113
|
+
tmp.write(img_bytes)
|
|
114
|
+
tmp.flush()
|
|
115
|
+
tmp_path = tmp.name
|
|
116
|
+
try:
|
|
117
|
+
if not os.path.isfile(tmp_path):
|
|
118
|
+
return None
|
|
119
|
+
with open(tmp_path, "rb") as img_file:
|
|
120
|
+
files = {"file": img_file}
|
|
121
|
+
response = requests.post("https://0x0.st", files=files)
|
|
122
|
+
response.raise_for_status()
|
|
123
|
+
image_url = response.text.strip()
|
|
124
|
+
if not image_url.startswith("http"):
|
|
125
|
+
return None
|
|
126
|
+
return image_url
|
|
127
|
+
except Exception:
|
|
128
|
+
return None
|
|
129
|
+
finally:
|
|
130
|
+
try:
|
|
131
|
+
os.remove(tmp_path)
|
|
132
|
+
except Exception:
|
|
133
|
+
pass
|
|
134
|
+
except Exception:
|
|
135
|
+
return None
|
|
136
|
+
|
|
137
|
+
for _ in range(n):
|
|
138
|
+
# Step 1: Get Authentication Token
|
|
139
|
+
auth_data = self._client.read_and_refresh_token()
|
|
140
|
+
gen_headers = {
|
|
141
|
+
"Authorization": auth_data.get("idToken"),
|
|
142
|
+
}
|
|
143
|
+
# Remove content-type header for form data
|
|
144
|
+
if "content-type" in self._client.session.headers:
|
|
145
|
+
del self._client.session.headers["content-type"]
|
|
146
|
+
# get_model now returns the proper style name from model_aliases
|
|
147
|
+
style_value = self._client.get_model(model)
|
|
148
|
+
image_payload = {
|
|
149
|
+
"prompt": str(prompt),
|
|
150
|
+
"negative_prompt": str(
|
|
151
|
+
kwargs.get("negative_prompt", "blurry, deformed hands, ugly")
|
|
152
|
+
),
|
|
153
|
+
"style": str(style_value),
|
|
154
|
+
"images_num": str(1), # Generate one image at a time in the loop
|
|
155
|
+
"cfg_scale": str(kwargs.get("guidance_scale", 7)),
|
|
156
|
+
"steps": str(kwargs.get("num_inference_steps", 30)),
|
|
157
|
+
"aspect_ratio": str(aspect_ratio),
|
|
158
|
+
}
|
|
159
|
+
# Step 2: Generate Image (send as form data, not JSON)
|
|
160
|
+
image_response = self._client.session.post(
|
|
161
|
+
self._client.image_generation_url,
|
|
162
|
+
data=image_payload, # Use form data instead of JSON
|
|
163
|
+
headers=gen_headers,
|
|
164
|
+
timeout=timeout,
|
|
165
|
+
)
|
|
166
|
+
if image_response.status_code != 200:
|
|
167
|
+
raise RuntimeError(
|
|
168
|
+
f"AIArta API error {image_response.status_code}: {image_response.text}\nPayload: {image_payload}"
|
|
169
|
+
)
|
|
170
|
+
image_data = image_response.json()
|
|
171
|
+
record_id = image_data.get("record_id")
|
|
172
|
+
if not record_id:
|
|
173
|
+
raise RuntimeError(f"Failed to initiate image generation: {image_data}")
|
|
174
|
+
# Step 3: Check Generation Status
|
|
175
|
+
status_url = self._client.status_check_url.format(record_id=record_id)
|
|
176
|
+
while True:
|
|
177
|
+
status_response = self._client.session.get(
|
|
178
|
+
status_url,
|
|
179
|
+
headers=gen_headers,
|
|
180
|
+
timeout=timeout,
|
|
181
|
+
)
|
|
182
|
+
status_data = status_response.json()
|
|
183
|
+
status = status_data.get("status")
|
|
184
|
+
if status == "DONE":
|
|
185
|
+
image_urls = [
|
|
186
|
+
image["url"] for image in status_data.get("response", [])
|
|
187
|
+
]
|
|
188
|
+
if not image_urls:
|
|
189
|
+
raise RuntimeError("No image URLs returned from AIArta")
|
|
190
|
+
img_resp = self._client.session.get(
|
|
191
|
+
image_urls[0],
|
|
192
|
+
timeout=timeout,
|
|
193
|
+
)
|
|
194
|
+
img_resp.raise_for_status()
|
|
195
|
+
img_bytes = img_resp.content
|
|
196
|
+
# Convert to png or jpeg in memory
|
|
197
|
+
with BytesIO(img_bytes) as input_io:
|
|
198
|
+
with Image.open(input_io) as im:
|
|
199
|
+
out_io = BytesIO()
|
|
200
|
+
if image_format.lower() == "jpeg":
|
|
201
|
+
im = im.convert("RGB")
|
|
202
|
+
im.save(out_io, format="JPEG")
|
|
203
|
+
else:
|
|
204
|
+
im.save(out_io, format="PNG")
|
|
205
|
+
img_bytes = out_io.getvalue()
|
|
206
|
+
images.append(img_bytes)
|
|
207
|
+
if response_format == "url":
|
|
208
|
+
uploaded_url = upload_file_with_retry(img_bytes, image_format)
|
|
209
|
+
if not uploaded_url:
|
|
210
|
+
uploaded_url = upload_file_alternative(
|
|
211
|
+
img_bytes, image_format
|
|
212
|
+
)
|
|
213
|
+
if uploaded_url:
|
|
214
|
+
urls.append(uploaded_url)
|
|
215
|
+
else:
|
|
216
|
+
raise RuntimeError(
|
|
217
|
+
"Failed to upload image to catbox.moe using all available methods"
|
|
218
|
+
)
|
|
219
|
+
break
|
|
220
|
+
elif status in ("IN_QUEUE", "IN_PROGRESS"):
|
|
221
|
+
time.sleep(2)
|
|
222
|
+
else:
|
|
223
|
+
raise RuntimeError(f"Image generation failed with status: {status}")
|
|
224
|
+
|
|
225
|
+
result_data = []
|
|
226
|
+
if response_format == "url":
|
|
227
|
+
for url in urls:
|
|
228
|
+
result_data.append(ImageData(url=url))
|
|
229
|
+
elif response_format == "b64_json":
|
|
230
|
+
import base64
|
|
231
|
+
|
|
232
|
+
for img in images:
|
|
233
|
+
b64 = base64.b64encode(img).decode("utf-8")
|
|
234
|
+
result_data.append(ImageData(b64_json=b64))
|
|
235
|
+
else:
|
|
236
|
+
raise ValueError("response_format must be 'url' or 'b64_json'")
|
|
237
|
+
|
|
238
|
+
from time import time as _time
|
|
239
|
+
|
|
240
|
+
return ImageResponse(created=int(_time()), data=result_data)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
class AIArta(TTICompatibleProvider):
|
|
244
|
+
# Model aliases mapping from lowercase keys to proper API style names
|
|
245
|
+
model_aliases = {
|
|
246
|
+
"flux": "Flux",
|
|
247
|
+
"medieval": "Medieval",
|
|
248
|
+
"vincent_van_gogh": "Vincent Van Gogh",
|
|
249
|
+
"f_dev": "F Dev",
|
|
250
|
+
"low_poly": "Low Poly",
|
|
251
|
+
"dreamshaper_xl": "Dreamshaper-xl",
|
|
252
|
+
"anima_pencil_xl": "Anima-pencil-xl",
|
|
253
|
+
"biomech": "Biomech",
|
|
254
|
+
"trash_polka": "Trash Polka",
|
|
255
|
+
"no_style": "No Style",
|
|
256
|
+
"cheyenne_xl": "Cheyenne-xl",
|
|
257
|
+
"chicano": "Chicano",
|
|
258
|
+
"embroidery_tattoo": "Embroidery tattoo",
|
|
259
|
+
"red_and_black": "Red and Black",
|
|
260
|
+
"fantasy_art": "Fantasy Art",
|
|
261
|
+
"watercolor": "Watercolor",
|
|
262
|
+
"dotwork": "Dotwork",
|
|
263
|
+
"old_school_colored": "Old school colored",
|
|
264
|
+
"realistic_tattoo": "Realistic tattoo",
|
|
265
|
+
"japanese_2": "Japanese_2",
|
|
266
|
+
"realistic_stock_xl": "Realistic-stock-xl",
|
|
267
|
+
"f_pro": "F Pro",
|
|
268
|
+
"revanimated": "RevAnimated",
|
|
269
|
+
"katayama_mix_xl": "Katayama-mix-xl",
|
|
270
|
+
"sdxl_l": "SDXL L",
|
|
271
|
+
"cor_epica_xl": "Cor-epica-xl",
|
|
272
|
+
"anime_tattoo": "Anime tattoo",
|
|
273
|
+
"new_school": "New School",
|
|
274
|
+
"death_metal": "Death metal",
|
|
275
|
+
"old_school": "Old School",
|
|
276
|
+
"juggernaut_xl": "Juggernaut-xl",
|
|
277
|
+
"photographic": "Photographic",
|
|
278
|
+
"sdxl_1_0": "SDXL 1.0",
|
|
279
|
+
"graffiti": "Graffiti",
|
|
280
|
+
"mini_tattoo": "Mini tattoo",
|
|
281
|
+
"surrealism": "Surrealism",
|
|
282
|
+
"neo_traditional": "Neo-traditional",
|
|
283
|
+
"on_limbs_black": "On limbs black",
|
|
284
|
+
"yamers_realistic_xl": "Yamers-realistic-xl",
|
|
285
|
+
"pony_xl": "Pony-xl",
|
|
286
|
+
"playground_xl": "Playground-xl",
|
|
287
|
+
"anything_xl": "Anything-xl",
|
|
288
|
+
"flame_design": "Flame design",
|
|
289
|
+
"kawaii": "Kawaii",
|
|
290
|
+
"cinematic_art": "Cinematic Art",
|
|
291
|
+
"professional": "Professional",
|
|
292
|
+
"black_ink": "Black Ink",
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
AVAILABLE_MODELS = list(model_aliases.keys())
|
|
296
|
+
default_model = "Flux"
|
|
297
|
+
default_image_model = default_model
|
|
298
|
+
|
|
299
|
+
def __init__(self):
|
|
300
|
+
self.image_generation_url = "https://img-gen-prod.ai-arta.com/api/v1/text2image"
|
|
301
|
+
self.status_check_url = (
|
|
302
|
+
"https://img-gen-prod.ai-arta.com/api/v1/text2image/{record_id}/status"
|
|
303
|
+
)
|
|
304
|
+
self.auth_url = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=AIzaSyB3-71wG0fIt0shj0ee4fvx1shcjJHGrrQ"
|
|
305
|
+
self.token_refresh_url = "https://securetoken.googleapis.com/v1/token?key=AIzaSyB3-71wG0fIt0shj0ee4fvx1shcjJHGrrQ"
|
|
306
|
+
self.session = requests.Session()
|
|
307
|
+
self.user_agent = LitAgent().random()
|
|
308
|
+
self.headers = {
|
|
309
|
+
"accept": "application/json",
|
|
310
|
+
"accept-language": "en-US,en;q=0.9",
|
|
311
|
+
"origin": "https://img-gen-prod.ai-arta.com",
|
|
312
|
+
"referer": "https://img-gen-prod.ai-arta.com/",
|
|
313
|
+
"user-agent": self.user_agent,
|
|
314
|
+
}
|
|
315
|
+
self.session.headers.update(self.headers)
|
|
316
|
+
self.images = Images(self)
|
|
317
|
+
|
|
318
|
+
def get_auth_file(self) -> str:
|
|
319
|
+
path = os.path.join(os.path.expanduser("~"), ".ai_arta_cookies")
|
|
320
|
+
if not os.path.exists(path):
|
|
321
|
+
os.makedirs(path)
|
|
322
|
+
filename = f"auth_{self.__class__.__name__}.json"
|
|
323
|
+
return os.path.join(path, filename)
|
|
324
|
+
|
|
325
|
+
def create_token(self, path: str) -> Dict[str, Any]:
|
|
326
|
+
auth_payload = {"clientType": "CLIENT_TYPE_ANDROID"}
|
|
327
|
+
proxies = self.session.proxies if self.session.proxies else None
|
|
328
|
+
auth_response = self.session.post(
|
|
329
|
+
self.auth_url,
|
|
330
|
+
json=auth_payload,
|
|
331
|
+
timeout=60,
|
|
332
|
+
proxies=proxies,
|
|
333
|
+
)
|
|
334
|
+
auth_data = auth_response.json()
|
|
335
|
+
auth_token = auth_data.get("idToken")
|
|
336
|
+
if not auth_token:
|
|
337
|
+
raise Exception("Failed to obtain authentication token.")
|
|
338
|
+
with open(path, "w") as f:
|
|
339
|
+
json.dump(auth_data, f)
|
|
340
|
+
return auth_data
|
|
341
|
+
|
|
342
|
+
def refresh_token(self, refresh_token: str) -> tuple[str, str]:
|
|
343
|
+
payload = {
|
|
344
|
+
"grant_type": "refresh_token",
|
|
345
|
+
"refresh_token": refresh_token,
|
|
346
|
+
}
|
|
347
|
+
response = self.session.post(
|
|
348
|
+
self.token_refresh_url,
|
|
349
|
+
data=payload,
|
|
350
|
+
timeout=60,
|
|
351
|
+
)
|
|
352
|
+
response_data = response.json()
|
|
353
|
+
return response_data.get("id_token"), response_data.get("refresh_token")
|
|
354
|
+
|
|
355
|
+
def read_and_refresh_token(self) -> Dict[str, Any]:
|
|
356
|
+
path = self.get_auth_file()
|
|
357
|
+
if os.path.isfile(path):
|
|
358
|
+
with open(path, "r") as f:
|
|
359
|
+
auth_data = json.load(f)
|
|
360
|
+
diff = time.time() - os.path.getmtime(path)
|
|
361
|
+
expires_in = int(auth_data.get("expiresIn", 3600))
|
|
362
|
+
if diff < expires_in:
|
|
363
|
+
if diff > expires_in / 2:
|
|
364
|
+
auth_data["idToken"], auth_data["refreshToken"] = (
|
|
365
|
+
self.refresh_token(auth_data.get("refreshToken"))
|
|
366
|
+
)
|
|
367
|
+
with open(path, "w") as f:
|
|
368
|
+
json.dump(auth_data, f)
|
|
369
|
+
return auth_data
|
|
370
|
+
return self.create_token(path)
|
|
371
|
+
|
|
372
|
+
def get_model(self, model_name: str) -> str:
|
|
373
|
+
# Convert to lowercase for lookup
|
|
374
|
+
model_key = model_name.lower()
|
|
375
|
+
# Return the proper style name from model_aliases, or the original if not found
|
|
376
|
+
return self.model_aliases.get(model_key, model_name)
|
|
377
|
+
|
|
378
|
+
@property
|
|
379
|
+
def models(self):
|
|
380
|
+
class _ModelList:
|
|
381
|
+
def list(inner_self):
|
|
382
|
+
return type(self).AVAILABLE_MODELS
|
|
383
|
+
|
|
384
|
+
return _ModelList()
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
# Example usage:
|
|
388
|
+
if __name__ == "__main__":
|
|
389
|
+
from rich import print
|
|
390
|
+
|
|
391
|
+
client = AIArta()
|
|
392
|
+
response = client.images.create(
|
|
393
|
+
model="flux",
|
|
394
|
+
prompt="a white siamese cat",
|
|
395
|
+
response_format="url",
|
|
396
|
+
n=2,
|
|
397
|
+
timeout=30,
|
|
398
|
+
)
|
|
399
|
+
print(response)
|