webscout 6.2b0__py3-none-any.whl → 6.4__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 +191 -176
- webscout/AIbase.py +112 -239
- webscout/AIutel.py +488 -1130
- webscout/Agents/functioncall.py +248 -198
- webscout/Bing_search.py +250 -153
- webscout/DWEBS.py +454 -178
- webscout/Extra/__init__.py +2 -1
- webscout/Extra/autocoder/__init__.py +9 -0
- webscout/Extra/autocoder/autocoder_utiles.py +121 -0
- webscout/Extra/autocoder/rawdog.py +681 -0
- webscout/Extra/autollama.py +246 -195
- webscout/Extra/gguf.py +441 -226
- webscout/Extra/weather.py +172 -67
- webscout/LLM.py +442 -100
- webscout/Litlogger/__init__.py +681 -0
- webscout/Local/formats.py +4 -2
- webscout/Provider/Amigo.py +19 -10
- webscout/Provider/Andi.py +0 -33
- webscout/Provider/Blackboxai.py +4 -204
- webscout/Provider/DARKAI.py +1 -1
- webscout/Provider/EDITEE.py +1 -1
- webscout/Provider/Llama3.py +1 -1
- webscout/Provider/Marcus.py +137 -0
- webscout/Provider/NinjaChat.py +1 -1
- webscout/Provider/PI.py +221 -207
- webscout/Provider/Perplexity.py +598 -598
- webscout/Provider/RoboCoders.py +206 -0
- webscout/Provider/TTI/AiForce/__init__.py +22 -0
- webscout/Provider/TTI/AiForce/async_aiforce.py +257 -0
- webscout/Provider/TTI/AiForce/sync_aiforce.py +242 -0
- webscout/Provider/TTI/Nexra/__init__.py +22 -0
- webscout/Provider/TTI/Nexra/async_nexra.py +286 -0
- webscout/Provider/TTI/Nexra/sync_nexra.py +258 -0
- webscout/Provider/TTI/PollinationsAI/__init__.py +23 -0
- webscout/Provider/TTI/PollinationsAI/async_pollinations.py +330 -0
- webscout/Provider/TTI/PollinationsAI/sync_pollinations.py +285 -0
- webscout/Provider/TTI/__init__.py +3 -4
- webscout/Provider/TTI/artbit/__init__.py +22 -0
- webscout/Provider/TTI/artbit/async_artbit.py +184 -0
- webscout/Provider/TTI/artbit/sync_artbit.py +176 -0
- webscout/Provider/TTI/blackbox/__init__.py +4 -0
- webscout/Provider/TTI/blackbox/async_blackbox.py +212 -0
- webscout/Provider/TTI/{blackboximage.py → blackbox/sync_blackbox.py} +199 -153
- webscout/Provider/TTI/deepinfra/__init__.py +4 -0
- webscout/Provider/TTI/deepinfra/async_deepinfra.py +227 -0
- webscout/Provider/TTI/deepinfra/sync_deepinfra.py +199 -0
- webscout/Provider/TTI/huggingface/__init__.py +22 -0
- webscout/Provider/TTI/huggingface/async_huggingface.py +199 -0
- webscout/Provider/TTI/huggingface/sync_huggingface.py +195 -0
- webscout/Provider/TTI/imgninza/__init__.py +4 -0
- webscout/Provider/TTI/imgninza/async_ninza.py +214 -0
- webscout/Provider/TTI/{imgninza.py → imgninza/sync_ninza.py} +209 -136
- webscout/Provider/TTI/talkai/__init__.py +4 -0
- webscout/Provider/TTI/talkai/async_talkai.py +229 -0
- webscout/Provider/TTI/talkai/sync_talkai.py +207 -0
- webscout/Provider/__init__.py +146 -132
- webscout/Provider/askmyai.py +158 -0
- webscout/Provider/cerebras.py +227 -206
- webscout/Provider/geminiapi.py +208 -198
- webscout/Provider/llama3mitril.py +180 -0
- webscout/Provider/llmchat.py +203 -0
- webscout/Provider/mhystical.py +176 -0
- webscout/Provider/perplexitylabs.py +265 -0
- webscout/Provider/talkai.py +196 -0
- webscout/Provider/twitterclone.py +251 -244
- webscout/Provider/typegpt.py +359 -0
- webscout/__init__.py +28 -23
- webscout/__main__.py +5 -5
- webscout/cli.py +327 -347
- webscout/conversation.py +227 -0
- webscout/exceptions.py +161 -29
- webscout/litagent/__init__.py +172 -0
- webscout/litprinter/__init__.py +831 -0
- webscout/optimizers.py +270 -0
- webscout/prompt_manager.py +279 -0
- webscout/swiftcli/__init__.py +810 -0
- webscout/transcriber.py +479 -551
- webscout/update_checker.py +125 -0
- webscout/version.py +1 -1
- webscout-6.4.dist-info/LICENSE.md +211 -0
- {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/METADATA +34 -55
- webscout-6.4.dist-info/RECORD +154 -0
- webscout/Provider/TTI/AIuncensored.py +0 -103
- webscout/Provider/TTI/Nexra.py +0 -120
- webscout/Provider/TTI/PollinationsAI.py +0 -138
- webscout/Provider/TTI/WebSimAI.py +0 -142
- webscout/Provider/TTI/aiforce.py +0 -160
- webscout/Provider/TTI/artbit.py +0 -141
- webscout/Provider/TTI/deepinfra.py +0 -148
- webscout/Provider/TTI/huggingface.py +0 -155
- webscout/models.py +0 -23
- webscout-6.2b0.dist-info/LICENSE.md +0 -50
- webscout-6.2b0.dist-info/RECORD +0 -118
- /webscout/{g4f.py → gpt4free.py} +0 -0
- {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/WHEEL +0 -0
- {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/entry_points.txt +0 -0
- {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"""PollinationsAI Synchronous Provider - Your go-to for text-to-image generation! 🔥
|
|
2
|
+
|
|
3
|
+
Examples:
|
|
4
|
+
>>> from webscout import PollinationsAI
|
|
5
|
+
>>> provider = PollinationsAI()
|
|
6
|
+
>>>
|
|
7
|
+
>>> # Generate a single image
|
|
8
|
+
>>> images = provider.generate("A cool cyberpunk city at night")
|
|
9
|
+
>>> provider.save(images, dir="my_images")
|
|
10
|
+
>>>
|
|
11
|
+
>>> # Generate multiple images with different settings
|
|
12
|
+
>>> images = provider.generate(
|
|
13
|
+
... prompt="A majestic dragon",
|
|
14
|
+
... amount=3,
|
|
15
|
+
... width=1024,
|
|
16
|
+
... height=1024,
|
|
17
|
+
... model="sdxl"
|
|
18
|
+
... )
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import requests
|
|
22
|
+
import os
|
|
23
|
+
import time
|
|
24
|
+
from typing import List, Optional, Union
|
|
25
|
+
from string import punctuation
|
|
26
|
+
from random import choice
|
|
27
|
+
from requests.exceptions import RequestException
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
from webscout.AIbase import ImageProvider
|
|
31
|
+
from webscout.Litlogger import LitLogger, LogFormat, ColorScheme
|
|
32
|
+
from webscout.litagent import LitAgent
|
|
33
|
+
|
|
34
|
+
# Set up logging with cyberpunk style! 🎨
|
|
35
|
+
logger = LitLogger(
|
|
36
|
+
name="PollinationsAI",
|
|
37
|
+
format=LogFormat.MODERN_EMOJI,
|
|
38
|
+
color_scheme=ColorScheme.CYBERPUNK
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# Get a fresh user agent! 🔄
|
|
42
|
+
agent = LitAgent()
|
|
43
|
+
|
|
44
|
+
class PollinationsAI(ImageProvider):
|
|
45
|
+
"""Your homie for generating fire images using pollinations.ai! 🎨
|
|
46
|
+
|
|
47
|
+
This provider supports various models and image sizes, with built-in retry logic
|
|
48
|
+
and error handling to make sure you get your images no cap! 💯
|
|
49
|
+
|
|
50
|
+
Examples:
|
|
51
|
+
>>> provider = PollinationsAI()
|
|
52
|
+
>>> # Generate one image with default model
|
|
53
|
+
>>> image = provider.generate("A futuristic city")
|
|
54
|
+
>>> provider.save(image, "city.jpg")
|
|
55
|
+
>>>
|
|
56
|
+
>>> # Generate multiple with specific model
|
|
57
|
+
>>> images = provider.generate(
|
|
58
|
+
... prompt="Space station",
|
|
59
|
+
... amount=3,
|
|
60
|
+
... width=1024,
|
|
61
|
+
... height=1024,
|
|
62
|
+
... model="flux-3d" # For 3D-style images
|
|
63
|
+
... )
|
|
64
|
+
>>> provider.save(images, dir="space_pics")
|
|
65
|
+
>>>
|
|
66
|
+
>>> # Try different models
|
|
67
|
+
>>> anime_pics = provider.generate(
|
|
68
|
+
... prompt="Anime character",
|
|
69
|
+
... model="flux-anime"
|
|
70
|
+
... )
|
|
71
|
+
>>> realistic_pics = provider.generate(
|
|
72
|
+
... prompt="Portrait photo",
|
|
73
|
+
... model="flux-realism"
|
|
74
|
+
... )
|
|
75
|
+
|
|
76
|
+
Attributes:
|
|
77
|
+
AVAILABLE_MODELS (list): Available models to use:
|
|
78
|
+
- "flux": Default model, good for general use
|
|
79
|
+
- "flux-realism": Enhanced realism
|
|
80
|
+
- "flux-cablyai": CablyAI style
|
|
81
|
+
- "flux-anime": Anime/manga style
|
|
82
|
+
- "flux-3d": 3D-style renders
|
|
83
|
+
- "any-dark": Dark/gothic style
|
|
84
|
+
- "flux-pro": Professional quality
|
|
85
|
+
- "turbo": Fast generation
|
|
86
|
+
DEFAULT_MODEL (str): Default model to use ("flux")
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
AVAILABLE_MODELS = [
|
|
90
|
+
"flux",
|
|
91
|
+
"flux-realism",
|
|
92
|
+
"flux-cablyai",
|
|
93
|
+
"flux-anime",
|
|
94
|
+
"flux-3d",
|
|
95
|
+
"any-dark",
|
|
96
|
+
"flux-pro",
|
|
97
|
+
"turbo"
|
|
98
|
+
]
|
|
99
|
+
DEFAULT_MODEL = "flux"
|
|
100
|
+
|
|
101
|
+
def __init__(
|
|
102
|
+
self,
|
|
103
|
+
timeout: int = 60,
|
|
104
|
+
proxies: Optional[dict] = None
|
|
105
|
+
):
|
|
106
|
+
"""Initialize your PollinationsAI provider with custom settings
|
|
107
|
+
|
|
108
|
+
Examples:
|
|
109
|
+
>>> provider = PollinationsAI(timeout=30)
|
|
110
|
+
>>> provider = PollinationsAI(proxies={"http": "http://proxy:8080"})
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
timeout (int): HTTP request timeout in seconds (default: 60)
|
|
114
|
+
proxies (dict, optional): Proxy configuration for requests
|
|
115
|
+
"""
|
|
116
|
+
self.image_gen_endpoint = "https://image.pollinations.ai/prompt/{prompt}"
|
|
117
|
+
self.headers = {
|
|
118
|
+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
|
119
|
+
"Accept-Language": "en-US,en;q=0.5",
|
|
120
|
+
"Accept-Encoding": "gzip, deflate",
|
|
121
|
+
"User-Agent": agent.random(),
|
|
122
|
+
}
|
|
123
|
+
self.session = requests.Session()
|
|
124
|
+
self.session.headers.update(self.headers)
|
|
125
|
+
if proxies:
|
|
126
|
+
self.session.proxies.update(proxies)
|
|
127
|
+
|
|
128
|
+
self.timeout = timeout
|
|
129
|
+
self.prompt: str = "AI-generated image - webscout"
|
|
130
|
+
self.image_extension: str = "jpeg"
|
|
131
|
+
|
|
132
|
+
def generate(
|
|
133
|
+
self,
|
|
134
|
+
prompt: str,
|
|
135
|
+
amount: int = 1,
|
|
136
|
+
additives: bool = True,
|
|
137
|
+
width: int = 768,
|
|
138
|
+
height: int = 768,
|
|
139
|
+
model: str = DEFAULT_MODEL,
|
|
140
|
+
max_retries: int = 3,
|
|
141
|
+
retry_delay: int = 5,
|
|
142
|
+
negative_prompt: Optional[str] = None,
|
|
143
|
+
seed: Optional[int] = None,
|
|
144
|
+
) -> List[bytes]:
|
|
145
|
+
"""Generate some fire images from your prompt! 🎨
|
|
146
|
+
|
|
147
|
+
Args:
|
|
148
|
+
prompt (str): Your image description
|
|
149
|
+
amount (int): How many images you want (default: 1)
|
|
150
|
+
additives (bool): Make each prompt unique for variety (default: True)
|
|
151
|
+
width (int): Image width (default: 768)
|
|
152
|
+
height (int): Image height (default: 768)
|
|
153
|
+
model (str): Model to use - check AVAILABLE_MODELS (default: "flux")
|
|
154
|
+
max_retries (int): Max retry attempts if something fails (default: 3)
|
|
155
|
+
retry_delay (int): Seconds to wait between retries (default: 5)
|
|
156
|
+
negative_prompt (str, optional): What you don't want in the image
|
|
157
|
+
seed (int, optional): Seed for reproducible results
|
|
158
|
+
|
|
159
|
+
Returns:
|
|
160
|
+
List[bytes]: Your generated images as bytes
|
|
161
|
+
|
|
162
|
+
Raises:
|
|
163
|
+
ValueError: If the inputs ain't valid
|
|
164
|
+
RequestException: If the API calls fail after retries
|
|
165
|
+
"""
|
|
166
|
+
# Input validation
|
|
167
|
+
if not prompt:
|
|
168
|
+
raise ValueError("Yo fam, the prompt can't be empty! 🤔")
|
|
169
|
+
if not isinstance(amount, int) or amount < 1:
|
|
170
|
+
raise ValueError("Amount needs to be a positive number! 📈")
|
|
171
|
+
if model not in self.AVAILABLE_MODELS:
|
|
172
|
+
raise ValueError(f"Model must be one of {self.AVAILABLE_MODELS}! 🎯")
|
|
173
|
+
|
|
174
|
+
# Function to add random characters for variety
|
|
175
|
+
def add_variety():
|
|
176
|
+
return "" if not additives else "".join(choice(punctuation) for _ in range(5))
|
|
177
|
+
|
|
178
|
+
self.prompt = prompt
|
|
179
|
+
response = []
|
|
180
|
+
|
|
181
|
+
# Build base URL with parameters
|
|
182
|
+
base_params = {
|
|
183
|
+
"width": width,
|
|
184
|
+
"height": height,
|
|
185
|
+
"model": model
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if negative_prompt:
|
|
189
|
+
base_params["negative"] = negative_prompt
|
|
190
|
+
if seed is not None:
|
|
191
|
+
base_params["seed"] = seed
|
|
192
|
+
|
|
193
|
+
for _ in range(amount):
|
|
194
|
+
current_prompt = f"{prompt}{add_variety()}"
|
|
195
|
+
params_str = "&".join(f"{k}={v}" for k, v in base_params.items())
|
|
196
|
+
url = f"{self.image_gen_endpoint.format(prompt=current_prompt)}?{params_str}"
|
|
197
|
+
|
|
198
|
+
for attempt in range(max_retries):
|
|
199
|
+
try:
|
|
200
|
+
logger.info(f"Generating image {_ + 1}/{amount} with prompt: {current_prompt[:50]}...")
|
|
201
|
+
resp = self.session.get(url, timeout=self.timeout)
|
|
202
|
+
resp.raise_for_status()
|
|
203
|
+
response.append(resp.content)
|
|
204
|
+
logger.success(f"Successfully generated image {_ + 1}/{amount}! 🎨")
|
|
205
|
+
break
|
|
206
|
+
except RequestException as e:
|
|
207
|
+
if attempt == max_retries - 1:
|
|
208
|
+
logger.error(f"Failed to generate image after {max_retries} attempts: {e} 😢")
|
|
209
|
+
raise
|
|
210
|
+
logger.warning(f"Attempt {attempt + 1} failed. Retrying in {retry_delay} seconds... 🔄")
|
|
211
|
+
time.sleep(retry_delay)
|
|
212
|
+
|
|
213
|
+
return response
|
|
214
|
+
|
|
215
|
+
def save(
|
|
216
|
+
self,
|
|
217
|
+
response: List[bytes],
|
|
218
|
+
name: Optional[str] = None,
|
|
219
|
+
dir: Optional[Union[str, Path]] = None,
|
|
220
|
+
filenames_prefix: str = "",
|
|
221
|
+
) -> List[str]:
|
|
222
|
+
"""Save your fire generated images! 💾
|
|
223
|
+
|
|
224
|
+
Examples:
|
|
225
|
+
>>> provider = PollinationsAI()
|
|
226
|
+
>>> images = provider.generate("Cool art")
|
|
227
|
+
>>> # Save with default settings
|
|
228
|
+
>>> paths = provider.save(images)
|
|
229
|
+
>>> # Save with custom name and directory
|
|
230
|
+
>>> paths = provider.save(
|
|
231
|
+
... images,
|
|
232
|
+
... name="my_art",
|
|
233
|
+
... dir="my_images",
|
|
234
|
+
... filenames_prefix="test_"
|
|
235
|
+
... )
|
|
236
|
+
|
|
237
|
+
Args:
|
|
238
|
+
response (List[bytes]): Your generated images
|
|
239
|
+
name (Optional[str]): Custom name for your images
|
|
240
|
+
dir (Optional[Union[str, Path]]): Where to save the images (default: current directory)
|
|
241
|
+
filenames_prefix (str): Prefix for your image files
|
|
242
|
+
|
|
243
|
+
Returns:
|
|
244
|
+
List[str]: Paths to your saved images
|
|
245
|
+
"""
|
|
246
|
+
save_dir = dir if dir else os.getcwd()
|
|
247
|
+
if not os.path.exists(save_dir):
|
|
248
|
+
os.makedirs(save_dir)
|
|
249
|
+
logger.info(f"Created directory: {save_dir} 📁")
|
|
250
|
+
|
|
251
|
+
saved_paths = []
|
|
252
|
+
timestamp = int(time.time())
|
|
253
|
+
|
|
254
|
+
for i, image_bytes in enumerate(response):
|
|
255
|
+
if name:
|
|
256
|
+
filename = f"{filenames_prefix}{name}_{i}.{self.image_extension}"
|
|
257
|
+
else:
|
|
258
|
+
filename = f"{filenames_prefix}pollinations_{timestamp}_{i}.{self.image_extension}"
|
|
259
|
+
|
|
260
|
+
filepath = os.path.join(save_dir, filename)
|
|
261
|
+
|
|
262
|
+
with open(filepath, "wb") as f:
|
|
263
|
+
f.write(image_bytes)
|
|
264
|
+
|
|
265
|
+
saved_paths.append(filepath)
|
|
266
|
+
logger.success(f"Saved image to: {filepath} 💾")
|
|
267
|
+
|
|
268
|
+
return saved_paths
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
if __name__ == "__main__":
|
|
272
|
+
# Example usage
|
|
273
|
+
provider = PollinationsAI()
|
|
274
|
+
try:
|
|
275
|
+
images = provider.generate(
|
|
276
|
+
prompt="A cyberpunk city at night with neon lights",
|
|
277
|
+
amount=2,
|
|
278
|
+
width=1024,
|
|
279
|
+
height=1024,
|
|
280
|
+
model="sdxl"
|
|
281
|
+
)
|
|
282
|
+
paths = provider.save(images, dir="generated_images")
|
|
283
|
+
print(f"Successfully saved images to: {paths}")
|
|
284
|
+
except Exception as e:
|
|
285
|
+
print(f"Oops, something went wrong: {e}")
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
from .deepinfra import *
|
|
2
2
|
from .PollinationsAI import *
|
|
3
|
-
from .
|
|
4
|
-
from .
|
|
3
|
+
from .AiForce import *
|
|
4
|
+
from .blackbox import *
|
|
5
5
|
from .Nexra import *
|
|
6
6
|
from .huggingface import *
|
|
7
7
|
from .artbit import *
|
|
8
|
-
from .WebSimAI import *
|
|
9
8
|
from .imgninza import *
|
|
10
|
-
from .
|
|
9
|
+
from .talkai import *
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Artbit Providers - Your go-to solution for generating fire images! 🔥
|
|
3
|
+
|
|
4
|
+
Examples:
|
|
5
|
+
>>> # Sync Usage
|
|
6
|
+
>>> from webscout import ArtbitImager
|
|
7
|
+
>>> provider = ArtbitImager(logging=True)
|
|
8
|
+
>>> images = provider.generate("Cool art")
|
|
9
|
+
>>> paths = provider.save(images)
|
|
10
|
+
>>>
|
|
11
|
+
>>> # Async Usage
|
|
12
|
+
>>> from webscout import AsyncArtbitImager
|
|
13
|
+
>>> async def example():
|
|
14
|
+
... provider = AsyncArtbitImager(logging=True)
|
|
15
|
+
... images = await provider.generate("Epic dragon")
|
|
16
|
+
... paths = await provider.save(images)
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from .sync_artbit import ArtbitImager
|
|
20
|
+
from .async_artbit import AsyncArtbitImager
|
|
21
|
+
|
|
22
|
+
__all__ = ["ArtbitImager", "AsyncArtbitImager"]
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AsyncArtbitImager - Your go-to async provider for generating fire images with Artbit! ⚡
|
|
3
|
+
|
|
4
|
+
Examples:
|
|
5
|
+
>>> from webscout import AsyncArtbitImager
|
|
6
|
+
>>> import asyncio
|
|
7
|
+
>>>
|
|
8
|
+
>>> async def example():
|
|
9
|
+
... # Initialize with logging
|
|
10
|
+
... provider = AsyncArtbitImager(logging=True)
|
|
11
|
+
...
|
|
12
|
+
... # Generate a single image
|
|
13
|
+
... images = await provider.generate("Cool art")
|
|
14
|
+
... paths = await provider.save(images)
|
|
15
|
+
...
|
|
16
|
+
... # Generate multiple images with parameters
|
|
17
|
+
... images = await provider.generate(
|
|
18
|
+
... prompt="Epic dragon in cyberpunk city",
|
|
19
|
+
... amount=3,
|
|
20
|
+
... caption_model="sdxl",
|
|
21
|
+
... selected_ratio="1024",
|
|
22
|
+
... negative_prompt="blurry, bad quality"
|
|
23
|
+
... )
|
|
24
|
+
... paths = await provider.save(images, name="dragon", dir="outputs")
|
|
25
|
+
>>>
|
|
26
|
+
>>> # Run the example
|
|
27
|
+
>>> asyncio.run(example())
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
import aiohttp
|
|
31
|
+
import aiofiles
|
|
32
|
+
import asyncio
|
|
33
|
+
import os
|
|
34
|
+
from typing import List
|
|
35
|
+
from webscout.AIbase import AsyncImageProvider
|
|
36
|
+
from webscout.Litlogger import LitLogger, LogFormat, ColorScheme
|
|
37
|
+
from webscout.litagent import LitAgent
|
|
38
|
+
|
|
39
|
+
# Initialize our fire logger and agent 🔥
|
|
40
|
+
logger = LitLogger(
|
|
41
|
+
"AsyncArtbit",
|
|
42
|
+
format=LogFormat.MODERN_EMOJI,
|
|
43
|
+
color_scheme=ColorScheme.CYBERPUNK
|
|
44
|
+
)
|
|
45
|
+
agent = LitAgent()
|
|
46
|
+
|
|
47
|
+
class AsyncArtbitImager(AsyncImageProvider):
|
|
48
|
+
"""Your go-to async provider for generating fire images with Artbit! ⚡"""
|
|
49
|
+
|
|
50
|
+
def __init__(self, timeout: int = 60, proxies: dict = {}, logging: bool = True):
|
|
51
|
+
"""Initialize your async Artbit provider with custom settings! ⚙️
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
timeout (int): Request timeout in seconds (default: 60)
|
|
55
|
+
proxies (dict): Proxy settings for requests (default: {})
|
|
56
|
+
logging (bool): Enable fire logging (default: True)
|
|
57
|
+
"""
|
|
58
|
+
self.url = "https://artbit.ai/api/generateImage"
|
|
59
|
+
self.headers = {
|
|
60
|
+
"User-Agent": agent.random(),
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
"Accept": "application/json"
|
|
63
|
+
}
|
|
64
|
+
self.timeout = timeout
|
|
65
|
+
self.proxies = proxies
|
|
66
|
+
self.prompt: str = "AI-generated image - webscout"
|
|
67
|
+
self.image_extension: str = "png"
|
|
68
|
+
self.logging = logging
|
|
69
|
+
if self.logging:
|
|
70
|
+
logger.info("AsyncArtbit provider initialized! 🚀")
|
|
71
|
+
|
|
72
|
+
async def generate(
|
|
73
|
+
self,
|
|
74
|
+
prompt: str,
|
|
75
|
+
amount: int = 1,
|
|
76
|
+
caption_model: str = "sdxl",
|
|
77
|
+
selected_ratio: str = "1024",
|
|
78
|
+
negative_prompt: str = ""
|
|
79
|
+
) -> List[str]:
|
|
80
|
+
"""Generate some fire images asynchronously! ⚡
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
prompt (str): Your lit image description
|
|
84
|
+
amount (int): How many images to generate (default: 1)
|
|
85
|
+
caption_model (str): Which model to use (default: "sdxl")
|
|
86
|
+
selected_ratio (str): Image size ratio (default: "1024")
|
|
87
|
+
negative_prompt (str): What you don't want in the image (default: "")
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
List[str]: Your generated image URLs
|
|
91
|
+
"""
|
|
92
|
+
assert bool(prompt), "Yo fam, prompt can't be empty! 🚫"
|
|
93
|
+
assert isinstance(amount, int), f"Amount gotta be an integer, not {type(amount)} 🤔"
|
|
94
|
+
assert amount > 0, "Amount gotta be greater than 0! 📈"
|
|
95
|
+
|
|
96
|
+
self.prompt = prompt
|
|
97
|
+
response: List[str] = []
|
|
98
|
+
|
|
99
|
+
if self.logging:
|
|
100
|
+
logger.info(f"Generating {amount} images with {caption_model}... 🎨")
|
|
101
|
+
|
|
102
|
+
payload = {
|
|
103
|
+
"captionInput": prompt,
|
|
104
|
+
"captionModel": caption_model,
|
|
105
|
+
"selectedRatio": selected_ratio,
|
|
106
|
+
"selectedSamples": str(amount),
|
|
107
|
+
"negative_prompt": negative_prompt
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
try:
|
|
111
|
+
async with aiohttp.ClientSession(headers=self.headers) as session:
|
|
112
|
+
async with session.post(self.url, json=payload, timeout=self.timeout) as resp:
|
|
113
|
+
resp.raise_for_status()
|
|
114
|
+
response_data = await resp.json()
|
|
115
|
+
imgs = response_data.get("imgs", [])
|
|
116
|
+
|
|
117
|
+
if imgs:
|
|
118
|
+
response.extend(imgs)
|
|
119
|
+
if self.logging:
|
|
120
|
+
logger.success("Images generated successfully! 🎉")
|
|
121
|
+
else:
|
|
122
|
+
if self.logging:
|
|
123
|
+
logger.warning("No images found in the response 😢")
|
|
124
|
+
|
|
125
|
+
except aiohttp.ClientError as e:
|
|
126
|
+
if self.logging:
|
|
127
|
+
logger.error(f"Failed to generate images: {e} 😢")
|
|
128
|
+
raise
|
|
129
|
+
|
|
130
|
+
return response
|
|
131
|
+
|
|
132
|
+
async def save(
|
|
133
|
+
self,
|
|
134
|
+
response: List[str],
|
|
135
|
+
name: str = None,
|
|
136
|
+
dir: str = os.getcwd(),
|
|
137
|
+
filenames_prefix: str = "",
|
|
138
|
+
) -> List[str]:
|
|
139
|
+
"""Save your fire images asynchronously! 💾
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
response (List[str]): Your image URLs to save
|
|
143
|
+
name (str, optional): Custom name (default: uses prompt)
|
|
144
|
+
dir (str, optional): Where to save (default: current directory)
|
|
145
|
+
filenames_prefix (str, optional): Add prefix to filenames
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
List[str]: Where your images were saved
|
|
149
|
+
"""
|
|
150
|
+
assert isinstance(response, list), f"Response gotta be a list, not {type(response)} 🤔"
|
|
151
|
+
name = self.prompt if name is None else name
|
|
152
|
+
|
|
153
|
+
filenames = []
|
|
154
|
+
count = 0
|
|
155
|
+
|
|
156
|
+
if self.logging:
|
|
157
|
+
logger.info(f"Saving {len(response)} images... 💾")
|
|
158
|
+
|
|
159
|
+
async with aiohttp.ClientSession(headers=self.headers) as session:
|
|
160
|
+
for img_url in response:
|
|
161
|
+
def complete_path():
|
|
162
|
+
count_value = "" if count == 0 else f"_{count}"
|
|
163
|
+
return os.path.join(dir, name + count_value + "." + self.image_extension)
|
|
164
|
+
|
|
165
|
+
while os.path.isfile(complete_path()):
|
|
166
|
+
count += 1
|
|
167
|
+
|
|
168
|
+
absolute_path_to_file = complete_path()
|
|
169
|
+
filenames.append(filenames_prefix + os.path.split(absolute_path_to_file)[1])
|
|
170
|
+
|
|
171
|
+
try:
|
|
172
|
+
async with session.get(img_url, timeout=self.timeout) as resp:
|
|
173
|
+
resp.raise_for_status()
|
|
174
|
+
async with aiofiles.open(absolute_path_to_file, "wb") as fh:
|
|
175
|
+
await fh.write(await resp.read())
|
|
176
|
+
|
|
177
|
+
except aiohttp.ClientError as e:
|
|
178
|
+
if self.logging:
|
|
179
|
+
logger.error(f"Failed to save image from {img_url}: {e} 😢")
|
|
180
|
+
raise
|
|
181
|
+
|
|
182
|
+
if self.logging:
|
|
183
|
+
logger.success(f"Images saved successfully! Check {dir} 🎉")
|
|
184
|
+
return filenames
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ArtbitImager - Your go-to provider for generating fire images with Artbit! 🔥
|
|
3
|
+
|
|
4
|
+
Examples:
|
|
5
|
+
>>> from webscout import ArtbitImager
|
|
6
|
+
>>>
|
|
7
|
+
>>> # Initialize with logging
|
|
8
|
+
>>> provider = ArtbitImager(logging=True)
|
|
9
|
+
>>>
|
|
10
|
+
>>> # Generate a single image
|
|
11
|
+
>>> images = provider.generate("Cool art")
|
|
12
|
+
>>> paths = provider.save(images)
|
|
13
|
+
>>>
|
|
14
|
+
>>> # Generate multiple images with parameters
|
|
15
|
+
>>> images = provider.generate(
|
|
16
|
+
... prompt="Epic dragon in cyberpunk city",
|
|
17
|
+
... amount=3,
|
|
18
|
+
... caption_model="sdxl",
|
|
19
|
+
... selected_ratio="1024",
|
|
20
|
+
... negative_prompt="blurry, bad quality"
|
|
21
|
+
... )
|
|
22
|
+
>>> paths = provider.save(images, name="dragon", dir="outputs")
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
import cloudscraper
|
|
26
|
+
import os
|
|
27
|
+
import requests
|
|
28
|
+
from typing import List
|
|
29
|
+
from webscout.AIbase import ImageProvider
|
|
30
|
+
from webscout.Litlogger import LitLogger, LogFormat, ColorScheme
|
|
31
|
+
from webscout.litagent import LitAgent
|
|
32
|
+
|
|
33
|
+
# Initialize our fire logger and agent 🔥
|
|
34
|
+
logger = LitLogger(
|
|
35
|
+
"Artbit",
|
|
36
|
+
format=LogFormat.MODERN_EMOJI,
|
|
37
|
+
color_scheme=ColorScheme.CYBERPUNK
|
|
38
|
+
)
|
|
39
|
+
agent = LitAgent()
|
|
40
|
+
|
|
41
|
+
class ArtbitImager(ImageProvider):
|
|
42
|
+
"""Your go-to provider for generating fire images with Artbit! 🔥"""
|
|
43
|
+
|
|
44
|
+
def __init__(self, timeout: int = 60, proxies: dict = {}, logging: bool = True):
|
|
45
|
+
"""Initialize your Artbit provider with custom settings! ⚙️
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
timeout (int): Request timeout in seconds (default: 60)
|
|
49
|
+
proxies (dict): Proxy settings for requests (default: {})
|
|
50
|
+
logging (bool): Enable fire logging (default: True)
|
|
51
|
+
"""
|
|
52
|
+
self.url = "https://artbit.ai/api/generateImage"
|
|
53
|
+
self.scraper = cloudscraper.create_scraper()
|
|
54
|
+
self.scraper.headers.update({"User-Agent": agent.random()})
|
|
55
|
+
self.scraper.proxies.update(proxies)
|
|
56
|
+
self.timeout = timeout
|
|
57
|
+
self.prompt: str = "AI-generated image - webscout"
|
|
58
|
+
self.image_extension: str = "png"
|
|
59
|
+
self.logging = logging
|
|
60
|
+
if self.logging:
|
|
61
|
+
logger.info("Artbit provider initialized! 🚀")
|
|
62
|
+
|
|
63
|
+
def generate(
|
|
64
|
+
self,
|
|
65
|
+
prompt: str,
|
|
66
|
+
amount: int = 1,
|
|
67
|
+
caption_model: str = "sdxl",
|
|
68
|
+
selected_ratio: str = "1024",
|
|
69
|
+
negative_prompt: str = ""
|
|
70
|
+
) -> List[str]:
|
|
71
|
+
"""Generate some fire images! 🎨
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
prompt (str): Your lit image description
|
|
75
|
+
amount (int): How many images to generate (default: 1)
|
|
76
|
+
caption_model (str): Which model to use (default: "sdxl")
|
|
77
|
+
selected_ratio (str): Image size ratio (default: "1024")
|
|
78
|
+
negative_prompt (str): What you don't want in the image (default: "")
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
List[str]: Your generated image URLs
|
|
82
|
+
"""
|
|
83
|
+
assert bool(prompt), "Yo fam, prompt can't be empty! 🚫"
|
|
84
|
+
assert isinstance(amount, int), f"Amount gotta be an integer, not {type(amount)} 🤔"
|
|
85
|
+
assert amount > 0, "Amount gotta be greater than 0! 📈"
|
|
86
|
+
|
|
87
|
+
self.prompt = prompt
|
|
88
|
+
response: List[str] = []
|
|
89
|
+
|
|
90
|
+
if self.logging:
|
|
91
|
+
logger.info(f"Generating {amount} images with {caption_model}... 🎨")
|
|
92
|
+
|
|
93
|
+
payload = {
|
|
94
|
+
"captionInput": prompt,
|
|
95
|
+
"captionModel": caption_model,
|
|
96
|
+
"selectedRatio": selected_ratio,
|
|
97
|
+
"selectedSamples": str(amount),
|
|
98
|
+
"negative_prompt": negative_prompt
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
try:
|
|
102
|
+
resp = self.scraper.post(self.url, json=payload, timeout=self.timeout)
|
|
103
|
+
resp.raise_for_status()
|
|
104
|
+
|
|
105
|
+
response_data = resp.json()
|
|
106
|
+
imgs = response_data.get("imgs", [])
|
|
107
|
+
|
|
108
|
+
if imgs:
|
|
109
|
+
response.extend(imgs)
|
|
110
|
+
if self.logging:
|
|
111
|
+
logger.success("Images generated successfully! 🎉")
|
|
112
|
+
else:
|
|
113
|
+
if self.logging:
|
|
114
|
+
logger.warning("No images found in the response 😢")
|
|
115
|
+
|
|
116
|
+
except requests.RequestException as e:
|
|
117
|
+
if self.logging:
|
|
118
|
+
logger.error(f"Failed to generate images: {e} 😢")
|
|
119
|
+
raise
|
|
120
|
+
|
|
121
|
+
return response
|
|
122
|
+
|
|
123
|
+
def save(
|
|
124
|
+
self,
|
|
125
|
+
response: List[str],
|
|
126
|
+
name: str = None,
|
|
127
|
+
dir: str = os.getcwd(),
|
|
128
|
+
filenames_prefix: str = "",
|
|
129
|
+
) -> List[str]:
|
|
130
|
+
"""Save your fire images! 💾
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
response (List[str]): Your image URLs to save
|
|
134
|
+
name (str, optional): Custom name (default: uses prompt)
|
|
135
|
+
dir (str, optional): Where to save (default: current directory)
|
|
136
|
+
filenames_prefix (str, optional): Add prefix to filenames
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
List[str]: Where your images were saved
|
|
140
|
+
"""
|
|
141
|
+
assert isinstance(response, list), f"Response gotta be a list, not {type(response)} 🤔"
|
|
142
|
+
name = self.prompt if name is None else name
|
|
143
|
+
|
|
144
|
+
filenames = []
|
|
145
|
+
count = 0
|
|
146
|
+
|
|
147
|
+
if self.logging:
|
|
148
|
+
logger.info(f"Saving {len(response)} images... 💾")
|
|
149
|
+
|
|
150
|
+
for img_url in response:
|
|
151
|
+
def complete_path():
|
|
152
|
+
count_value = "" if count == 0 else f"_{count}"
|
|
153
|
+
return os.path.join(dir, name + count_value + "." + self.image_extension)
|
|
154
|
+
|
|
155
|
+
while os.path.isfile(complete_path()):
|
|
156
|
+
count += 1
|
|
157
|
+
|
|
158
|
+
absolute_path_to_file = complete_path()
|
|
159
|
+
filenames.append(filenames_prefix + os.path.split(absolute_path_to_file)[1])
|
|
160
|
+
|
|
161
|
+
try:
|
|
162
|
+
img_response = requests.get(img_url, stream=True, timeout=self.timeout)
|
|
163
|
+
img_response.raise_for_status()
|
|
164
|
+
|
|
165
|
+
with open(absolute_path_to_file, "wb") as fh:
|
|
166
|
+
for chunk in img_response.iter_content(chunk_size=8192):
|
|
167
|
+
fh.write(chunk)
|
|
168
|
+
|
|
169
|
+
except requests.exceptions.RequestException as e:
|
|
170
|
+
if self.logging:
|
|
171
|
+
logger.error(f"Failed to save image from {img_url}: {e} 😢")
|
|
172
|
+
raise
|
|
173
|
+
|
|
174
|
+
if self.logging:
|
|
175
|
+
logger.success(f"Images saved successfully! Check {dir} 🎉")
|
|
176
|
+
return filenames
|