webscout 7.4__py3-none-any.whl → 7.6__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 +5 -53
- webscout/AIutel.py +8 -318
- webscout/DWEBS.py +460 -489
- webscout/Extra/YTToolkit/YTdownloader.py +14 -53
- webscout/Extra/YTToolkit/transcriber.py +12 -13
- webscout/Extra/YTToolkit/ytapi/video.py +0 -1
- webscout/Extra/__init__.py +0 -1
- webscout/Extra/autocoder/autocoder_utiles.py +0 -4
- webscout/Extra/autocoder/rawdog.py +13 -41
- webscout/Extra/gguf.py +652 -428
- webscout/Extra/weather.py +178 -156
- webscout/Extra/weather_ascii.py +70 -17
- webscout/Litlogger/core/logger.py +1 -2
- webscout/Litlogger/handlers/file.py +1 -1
- webscout/Litlogger/styles/formats.py +0 -2
- webscout/Litlogger/utils/detectors.py +0 -1
- webscout/Provider/AISEARCH/DeepFind.py +0 -1
- webscout/Provider/AISEARCH/ISou.py +1 -1
- webscout/Provider/AISEARCH/felo_search.py +0 -1
- webscout/Provider/AllenAI.py +24 -9
- webscout/Provider/C4ai.py +432 -0
- webscout/Provider/ChatGPTGratis.py +24 -56
- webscout/Provider/Cloudflare.py +18 -21
- webscout/Provider/DeepSeek.py +27 -48
- webscout/Provider/Deepinfra.py +129 -53
- webscout/Provider/Gemini.py +1 -1
- webscout/Provider/GithubChat.py +362 -0
- webscout/Provider/Glider.py +25 -8
- webscout/Provider/HF_space/qwen_qwen2.py +2 -2
- webscout/Provider/HeckAI.py +38 -5
- webscout/Provider/HuggingFaceChat.py +462 -0
- webscout/Provider/Jadve.py +20 -5
- webscout/Provider/Marcus.py +7 -50
- webscout/Provider/Netwrck.py +43 -67
- webscout/Provider/PI.py +4 -2
- webscout/Provider/Perplexitylabs.py +26 -6
- webscout/Provider/Phind.py +29 -3
- webscout/Provider/PizzaGPT.py +10 -51
- webscout/Provider/TTI/AiForce/async_aiforce.py +4 -37
- webscout/Provider/TTI/AiForce/sync_aiforce.py +41 -38
- webscout/Provider/TTI/FreeAIPlayground/__init__.py +9 -9
- webscout/Provider/TTI/FreeAIPlayground/async_freeaiplayground.py +206 -206
- webscout/Provider/TTI/FreeAIPlayground/sync_freeaiplayground.py +192 -192
- webscout/Provider/TTI/MagicStudio/__init__.py +2 -0
- webscout/Provider/TTI/MagicStudio/async_magicstudio.py +111 -0
- webscout/Provider/TTI/MagicStudio/sync_magicstudio.py +109 -0
- webscout/Provider/TTI/PollinationsAI/async_pollinations.py +5 -24
- webscout/Provider/TTI/PollinationsAI/sync_pollinations.py +2 -22
- webscout/Provider/TTI/__init__.py +2 -3
- webscout/Provider/TTI/aiarta/__init__.py +2 -0
- webscout/Provider/TTI/aiarta/async_aiarta.py +482 -0
- webscout/Provider/TTI/aiarta/sync_aiarta.py +440 -0
- webscout/Provider/TTI/fastflux/__init__.py +22 -0
- webscout/Provider/TTI/fastflux/async_fastflux.py +257 -0
- webscout/Provider/TTI/fastflux/sync_fastflux.py +247 -0
- webscout/Provider/TTS/__init__.py +2 -2
- webscout/Provider/TTS/deepgram.py +12 -39
- webscout/Provider/TTS/elevenlabs.py +14 -40
- webscout/Provider/TTS/gesserit.py +11 -35
- webscout/Provider/TTS/murfai.py +13 -39
- webscout/Provider/TTS/parler.py +17 -40
- webscout/Provider/TTS/speechma.py +180 -0
- webscout/Provider/TTS/streamElements.py +17 -44
- webscout/Provider/TextPollinationsAI.py +39 -59
- webscout/Provider/Venice.py +217 -200
- webscout/Provider/WiseCat.py +27 -5
- webscout/Provider/Youchat.py +63 -36
- webscout/Provider/__init__.py +13 -8
- webscout/Provider/akashgpt.py +28 -10
- webscout/Provider/copilot.py +416 -0
- webscout/Provider/flowith.py +196 -0
- webscout/Provider/freeaichat.py +32 -45
- webscout/Provider/granite.py +17 -53
- webscout/Provider/koala.py +20 -5
- webscout/Provider/llamatutor.py +7 -47
- webscout/Provider/llmchat.py +36 -53
- webscout/Provider/multichat.py +92 -98
- webscout/Provider/talkai.py +1 -0
- webscout/Provider/turboseek.py +3 -0
- webscout/Provider/tutorai.py +2 -0
- webscout/Provider/typegpt.py +154 -64
- webscout/Provider/x0gpt.py +3 -1
- webscout/Provider/yep.py +102 -20
- webscout/__init__.py +3 -0
- webscout/cli.py +4 -40
- webscout/conversation.py +1 -10
- webscout/exceptions.py +19 -9
- webscout/litagent/__init__.py +2 -2
- webscout/litagent/agent.py +351 -20
- webscout/litagent/constants.py +34 -5
- webscout/litprinter/__init__.py +0 -3
- webscout/models.py +181 -0
- webscout/optimizers.py +1 -1
- webscout/prompt_manager.py +2 -8
- webscout/scout/core/scout.py +1 -4
- webscout/scout/core/search_result.py +1 -1
- webscout/scout/core/text_utils.py +1 -1
- webscout/scout/core.py +2 -5
- webscout/scout/element.py +1 -1
- webscout/scout/parsers/html_parser.py +1 -1
- webscout/scout/utils.py +0 -1
- webscout/swiftcli/__init__.py +1 -3
- webscout/tempid.py +1 -1
- webscout/update_checker.py +55 -95
- webscout/version.py +1 -1
- webscout/webscout_search_async.py +1 -2
- webscout/yep_search.py +297 -297
- webscout-7.6.dist-info/LICENSE.md +146 -0
- {webscout-7.4.dist-info → webscout-7.6.dist-info}/METADATA +104 -514
- {webscout-7.4.dist-info → webscout-7.6.dist-info}/RECORD +113 -120
- webscout/Extra/autollama.py +0 -231
- webscout/Local/__init__.py +0 -10
- webscout/Local/_version.py +0 -3
- webscout/Local/formats.py +0 -747
- webscout/Local/model.py +0 -1368
- webscout/Local/samplers.py +0 -125
- webscout/Local/thread.py +0 -539
- webscout/Local/ui.py +0 -401
- webscout/Local/utils.py +0 -388
- webscout/Provider/Amigo.py +0 -274
- webscout/Provider/Bing.py +0 -243
- webscout/Provider/DiscordRocks.py +0 -253
- webscout/Provider/TTI/blackbox/__init__.py +0 -4
- webscout/Provider/TTI/blackbox/async_blackbox.py +0 -212
- webscout/Provider/TTI/blackbox/sync_blackbox.py +0 -199
- webscout/Provider/TTI/deepinfra/__init__.py +0 -4
- webscout/Provider/TTI/deepinfra/async_deepinfra.py +0 -227
- webscout/Provider/TTI/deepinfra/sync_deepinfra.py +0 -199
- webscout/Provider/TTI/imgninza/__init__.py +0 -4
- webscout/Provider/TTI/imgninza/async_ninza.py +0 -214
- webscout/Provider/TTI/imgninza/sync_ninza.py +0 -209
- webscout/Provider/TTS/voicepod.py +0 -117
- webscout/Provider/dgaf.py +0 -214
- webscout-7.4.dist-info/LICENSE.md +0 -211
- {webscout-7.4.dist-info → webscout-7.6.dist-info}/WHEEL +0 -0
- {webscout-7.4.dist-info → webscout-7.6.dist-info}/entry_points.txt +0 -0
- {webscout-7.4.dist-info → webscout-7.6.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"""AsyncFastFluxImager - Generate stunning AI art with FastFlux (async version)! ⚡
|
|
2
|
+
|
|
3
|
+
Examples:
|
|
4
|
+
>>> from webscout import AsyncFastFluxImager
|
|
5
|
+
>>> import asyncio
|
|
6
|
+
>>>
|
|
7
|
+
>>> async def main():
|
|
8
|
+
... provider = AsyncFastFluxImager()
|
|
9
|
+
... # Generate a single image
|
|
10
|
+
... images = await provider.generate("A cool cyberpunk city at night")
|
|
11
|
+
... paths = await provider.save(images, dir="my_images")
|
|
12
|
+
... print(f"Saved images to: {paths}")
|
|
13
|
+
...
|
|
14
|
+
>>> asyncio.run(main())
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import aiohttp
|
|
18
|
+
import asyncio
|
|
19
|
+
import base64
|
|
20
|
+
import os
|
|
21
|
+
import time
|
|
22
|
+
from typing import List, Optional, Union, AsyncGenerator
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
import aiofiles
|
|
25
|
+
|
|
26
|
+
from webscout.AIbase import AsyncImageProvider
|
|
27
|
+
from webscout.litagent import LitAgent
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class AsyncFastFluxImager(AsyncImageProvider):
|
|
31
|
+
"""Your go-to async provider for generating fire images with FastFlux! ⚡
|
|
32
|
+
|
|
33
|
+
Examples:
|
|
34
|
+
>>> provider = AsyncFastFluxImager()
|
|
35
|
+
>>>
|
|
36
|
+
>>> # Generate one image with default model
|
|
37
|
+
>>> async def single_image():
|
|
38
|
+
... image = await provider.generate("A futuristic city")
|
|
39
|
+
... await provider.save(image, "city.png")
|
|
40
|
+
>>>
|
|
41
|
+
>>> # Generate multiple with specific model
|
|
42
|
+
>>> async def multiple_images():
|
|
43
|
+
... images = await provider.generate(
|
|
44
|
+
... prompt="Space station",
|
|
45
|
+
... amount=3,
|
|
46
|
+
... model="flux_1_dev",
|
|
47
|
+
... size="16_9"
|
|
48
|
+
... )
|
|
49
|
+
... await provider.save(images, dir="space_pics")
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
AVAILABLE_MODELS = [
|
|
53
|
+
"flux_1_schnell", # Fast generation model (default)
|
|
54
|
+
"flux_1_dev", # Developer model
|
|
55
|
+
"sana_1_6b" # SANA 1.6B model
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def __init__(self, timeout: int = 60, proxies: dict = None):
|
|
61
|
+
"""Initialize your async FastFluxImager provider with custom settings ⚙️
|
|
62
|
+
|
|
63
|
+
Examples:
|
|
64
|
+
>>> provider = AsyncFastFluxImager(timeout=120)
|
|
65
|
+
>>> provider = AsyncFastFluxImager(proxies={"http": "http://proxy:8080"})
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
timeout (int): HTTP request timeout in seconds (default: 60)
|
|
69
|
+
proxies (dict, optional): Proxy configuration for requests
|
|
70
|
+
logging (bool): Enable/disable logging (default: True)
|
|
71
|
+
"""
|
|
72
|
+
self.api_endpoint = "https://api.fastflux.co/v1/images/generate"
|
|
73
|
+
self.headers = {
|
|
74
|
+
"accept": "application/json, text/plain, */*",
|
|
75
|
+
"content-type": "application/json",
|
|
76
|
+
"origin": "https://fastflux.co",
|
|
77
|
+
"referer": "https://fastflux.co/",
|
|
78
|
+
"user-agent": LitAgent().random()
|
|
79
|
+
}
|
|
80
|
+
self.timeout = timeout
|
|
81
|
+
self.proxies = proxies
|
|
82
|
+
self.prompt: str = "AI-generated image - webscout"
|
|
83
|
+
self.image_extension: str = "png"
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
async def generate(
|
|
87
|
+
self,
|
|
88
|
+
prompt: str,
|
|
89
|
+
amount: int = 1,
|
|
90
|
+
model: str = "flux_1_schnell",
|
|
91
|
+
size: str = "1_1",
|
|
92
|
+
is_public: bool = False,
|
|
93
|
+
max_retries: int = 3,
|
|
94
|
+
retry_delay: int = 5
|
|
95
|
+
) -> List[bytes]:
|
|
96
|
+
"""Generate some fire images from your prompt asynchronously! ⚡
|
|
97
|
+
|
|
98
|
+
Examples:
|
|
99
|
+
>>> provider = AsyncFastFluxImager()
|
|
100
|
+
>>> async def example():
|
|
101
|
+
... # Basic usage
|
|
102
|
+
... images = await provider.generate("Cool art")
|
|
103
|
+
... # Advanced usage
|
|
104
|
+
... images = await provider.generate(
|
|
105
|
+
... prompt="Epic dragon",
|
|
106
|
+
... amount=2,
|
|
107
|
+
... model="flux_1_dev",
|
|
108
|
+
... size="16_9"
|
|
109
|
+
... )
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
prompt (str): Your image description
|
|
113
|
+
amount (int): How many images you want (default: 1)
|
|
114
|
+
model (str): Model to use - check AVAILABLE_MODELS (default: "flux_1_schnell")
|
|
115
|
+
size (str): Image size ratio (default: "1_1")
|
|
116
|
+
is_public (bool): Whether to make the image public (default: False)
|
|
117
|
+
max_retries (int): Max retry attempts if something fails (default: 3)
|
|
118
|
+
retry_delay (int): Seconds to wait between retries (default: 5)
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
List[bytes]: Your generated images
|
|
122
|
+
|
|
123
|
+
Raises:
|
|
124
|
+
ValueError: If the inputs ain't valid
|
|
125
|
+
aiohttp.ClientError: If the API calls fail after retries
|
|
126
|
+
"""
|
|
127
|
+
if not prompt:
|
|
128
|
+
raise ValueError("Yo fam, the prompt can't be empty! 🤔")
|
|
129
|
+
if not isinstance(amount, int) or amount < 1:
|
|
130
|
+
raise ValueError("Amount needs to be a positive number! 📈")
|
|
131
|
+
if model not in self.AVAILABLE_MODELS:
|
|
132
|
+
raise ValueError(f"Model must be one of {self.AVAILABLE_MODELS}! 🎯")
|
|
133
|
+
if size not in self.AVAILABLE_SIZES:
|
|
134
|
+
raise ValueError(f"Size must be one of {self.AVAILABLE_SIZES}! 📏")
|
|
135
|
+
|
|
136
|
+
self.prompt = prompt
|
|
137
|
+
response = []
|
|
138
|
+
|
|
139
|
+
# Prepare payload
|
|
140
|
+
payload = {
|
|
141
|
+
"prompt": prompt,
|
|
142
|
+
"model": model,
|
|
143
|
+
"size": size,
|
|
144
|
+
"isPublic": is_public
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
async with aiohttp.ClientSession(headers=self.headers) as session:
|
|
149
|
+
for i in range(amount):
|
|
150
|
+
for attempt in range(max_retries):
|
|
151
|
+
try:
|
|
152
|
+
async with session.post(
|
|
153
|
+
self.api_endpoint,
|
|
154
|
+
json=payload,
|
|
155
|
+
timeout=self.timeout,
|
|
156
|
+
proxy=self.proxies.get('http') if self.proxies else None
|
|
157
|
+
) as resp:
|
|
158
|
+
resp.raise_for_status()
|
|
159
|
+
result = await resp.json()
|
|
160
|
+
|
|
161
|
+
if result and 'result' in result:
|
|
162
|
+
# Get base64 data and remove header
|
|
163
|
+
image_data = result['result']
|
|
164
|
+
base64_data = image_data.split(',')[1]
|
|
165
|
+
|
|
166
|
+
# Decode base64 data
|
|
167
|
+
image_bytes = base64.b64decode(base64_data)
|
|
168
|
+
response.append(image_bytes)
|
|
169
|
+
break
|
|
170
|
+
else:
|
|
171
|
+
raise aiohttp.ClientError("Invalid response format")
|
|
172
|
+
|
|
173
|
+
except aiohttp.ClientError as e:
|
|
174
|
+
if attempt == max_retries - 1:
|
|
175
|
+
raise aiohttp.ClientError(f"Failed to generate image after {max_retries} attempts: {e}")
|
|
176
|
+
await asyncio.sleep(retry_delay)
|
|
177
|
+
|
|
178
|
+
return response
|
|
179
|
+
|
|
180
|
+
async def save(
|
|
181
|
+
self,
|
|
182
|
+
response: Union[AsyncGenerator[bytes, None], List[bytes]],
|
|
183
|
+
name: Optional[str] = None,
|
|
184
|
+
dir: Optional[Union[str, Path]] = None,
|
|
185
|
+
filenames_prefix: str = "",
|
|
186
|
+
) -> List[str]:
|
|
187
|
+
"""Save your fire generated images asynchronously! 💾
|
|
188
|
+
|
|
189
|
+
Examples:
|
|
190
|
+
>>> provider = AsyncFastFluxImager()
|
|
191
|
+
>>> async def example():
|
|
192
|
+
... images = await provider.generate("Cool art")
|
|
193
|
+
... # Save with default settings
|
|
194
|
+
... paths = await provider.save(images)
|
|
195
|
+
... # Save with custom name and directory
|
|
196
|
+
... paths = await provider.save(
|
|
197
|
+
... images,
|
|
198
|
+
... name="my_art",
|
|
199
|
+
... dir="my_images",
|
|
200
|
+
... filenames_prefix="test_"
|
|
201
|
+
... )
|
|
202
|
+
|
|
203
|
+
Args:
|
|
204
|
+
response (Union[AsyncGenerator[bytes, None], List[bytes]]): Your generated images
|
|
205
|
+
name (Optional[str]): Custom name for your images
|
|
206
|
+
dir (Optional[Union[str, Path]]): Where to save the images (default: current directory)
|
|
207
|
+
filenames_prefix (str): Prefix for your image files
|
|
208
|
+
|
|
209
|
+
Returns:
|
|
210
|
+
List[str]: Paths to your saved images
|
|
211
|
+
"""
|
|
212
|
+
save_dir = dir if dir else os.getcwd()
|
|
213
|
+
if not os.path.exists(save_dir):
|
|
214
|
+
os.makedirs(save_dir)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
name = self.prompt if name is None else name
|
|
218
|
+
|
|
219
|
+
# Clean up name for filename use
|
|
220
|
+
safe_name = "".join(c if c.isalnum() or c in "_-" else "_" for c in name)
|
|
221
|
+
safe_name = safe_name[:50] # Truncate if too long
|
|
222
|
+
|
|
223
|
+
# Handle both List[bytes] and AsyncGenerator
|
|
224
|
+
if isinstance(response, list):
|
|
225
|
+
image_list = response
|
|
226
|
+
else:
|
|
227
|
+
image_list = [chunk async for chunk in response]
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
async def save_single_image(image_bytes: bytes, index: int) -> str:
|
|
231
|
+
filename = f"{filenames_prefix}{safe_name}_{index}.{self.image_extension}"
|
|
232
|
+
filepath = os.path.join(save_dir, filename)
|
|
233
|
+
|
|
234
|
+
async with aiofiles.open(filepath, "wb") as f:
|
|
235
|
+
await f.write(image_bytes)
|
|
236
|
+
|
|
237
|
+
return filename
|
|
238
|
+
|
|
239
|
+
tasks = [save_single_image(img, i) for i, img in enumerate(image_list)]
|
|
240
|
+
saved_paths = await asyncio.gather(*tasks)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
return saved_paths
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
if __name__ == "__main__":
|
|
247
|
+
# Example usage
|
|
248
|
+
async def main():
|
|
249
|
+
provider = AsyncFastFluxImager()
|
|
250
|
+
try:
|
|
251
|
+
images = await provider.generate("A cyberpunk city at night with neon lights", amount=1)
|
|
252
|
+
paths = await provider.save(images, dir="generated_images")
|
|
253
|
+
print(f"Successfully saved images to: {paths}")
|
|
254
|
+
except Exception as e:
|
|
255
|
+
print(f"Oops, something went wrong: {e}")
|
|
256
|
+
|
|
257
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"""FastFluxImager Synchronous Provider - Generate stunning AI art with FastFlux! 🎨
|
|
2
|
+
|
|
3
|
+
Examples:
|
|
4
|
+
>>> from webscout import FastFluxImager
|
|
5
|
+
>>> provider = FastFluxImager()
|
|
6
|
+
>>>
|
|
7
|
+
>>> # Generate a single image
|
|
8
|
+
>>> images = provider.generate("A cool cyberpunk city at night")
|
|
9
|
+
>>> paths = provider.save(images, dir="my_images")
|
|
10
|
+
>>>
|
|
11
|
+
>>> # Generate multiple images with different settings
|
|
12
|
+
>>> images = provider.generate(
|
|
13
|
+
... prompt="Epic dragon breathing fire",
|
|
14
|
+
... amount=2,
|
|
15
|
+
... model="flux_1_schnell"
|
|
16
|
+
... )
|
|
17
|
+
>>> provider.save(images, dir="dragon_pics")
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import requests
|
|
21
|
+
import base64
|
|
22
|
+
import json
|
|
23
|
+
import os
|
|
24
|
+
import time
|
|
25
|
+
from typing import List, Optional, Union
|
|
26
|
+
from requests.exceptions import RequestException
|
|
27
|
+
from pathlib import Path
|
|
28
|
+
|
|
29
|
+
from webscout.AIbase import ImageProvider
|
|
30
|
+
from webscout.litagent import LitAgent
|
|
31
|
+
|
|
32
|
+
# Get a fresh user agent! 🔄
|
|
33
|
+
agent = LitAgent()
|
|
34
|
+
|
|
35
|
+
class FastFluxImager(ImageProvider):
|
|
36
|
+
"""Your go-to provider for generating fire images with FastFlux! 🎨
|
|
37
|
+
|
|
38
|
+
Examples:
|
|
39
|
+
>>> provider = FastFluxImager()
|
|
40
|
+
>>> # Generate one image with default model
|
|
41
|
+
>>> image = provider.generate("A futuristic city")
|
|
42
|
+
>>> provider.save(image, "city.png")
|
|
43
|
+
>>>
|
|
44
|
+
>>> # Generate multiple images with specific model
|
|
45
|
+
>>> images = provider.generate(
|
|
46
|
+
... prompt="Space station",
|
|
47
|
+
... amount=3,
|
|
48
|
+
... model="flux_1_dev"
|
|
49
|
+
... )
|
|
50
|
+
>>> provider.save(images, dir="space_pics")
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
AVAILABLE_MODELS = [
|
|
54
|
+
"flux_1_schnell", # Fast generation model (default)
|
|
55
|
+
"flux_1_dev", # Developer model
|
|
56
|
+
"sana_1_6b" # SANA 1.6B model
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def __init__(self, timeout: int = 60, proxies: dict = None):
|
|
61
|
+
"""Initialize your FastFluxImager provider with custom settings
|
|
62
|
+
|
|
63
|
+
Examples:
|
|
64
|
+
>>> provider = FastFluxImager(timeout=120)
|
|
65
|
+
>>> provider = FastFluxImager(proxies={"http": "http://proxy:8080"})
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
timeout (int): HTTP request timeout in seconds (default: 60)
|
|
69
|
+
proxies (dict, optional): Proxy configuration for requests
|
|
70
|
+
logging (bool): Enable/disable logging (default: True)
|
|
71
|
+
"""
|
|
72
|
+
self.api_endpoint = "https://api.fastflux.co/v1/images/generate"
|
|
73
|
+
self.headers = {
|
|
74
|
+
"accept": "application/json, text/plain, */*",
|
|
75
|
+
"content-type": "application/json",
|
|
76
|
+
"origin": "https://fastflux.co",
|
|
77
|
+
"referer": "https://fastflux.co/",
|
|
78
|
+
"user-agent": agent.random()
|
|
79
|
+
}
|
|
80
|
+
self.session = requests.Session()
|
|
81
|
+
self.session.headers.update(self.headers)
|
|
82
|
+
if proxies:
|
|
83
|
+
self.session.proxies.update(proxies)
|
|
84
|
+
self.timeout = timeout
|
|
85
|
+
self.prompt: str = "AI-generated image - webscout"
|
|
86
|
+
self.image_extension: str = "png"
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def generate(
|
|
90
|
+
self,
|
|
91
|
+
prompt: str,
|
|
92
|
+
amount: int = 1,
|
|
93
|
+
model: str = "flux_1_schnell",
|
|
94
|
+
size: str = "1_1",
|
|
95
|
+
is_public: bool = False,
|
|
96
|
+
max_retries: int = 3,
|
|
97
|
+
retry_delay: int = 5
|
|
98
|
+
) -> List[bytes]:
|
|
99
|
+
"""Generate some fire images from your prompt! 🎨
|
|
100
|
+
|
|
101
|
+
Examples:
|
|
102
|
+
>>> provider = FastFluxImager()
|
|
103
|
+
>>> # Basic usage
|
|
104
|
+
>>> images = provider.generate("Cool art")
|
|
105
|
+
>>> # Advanced usage
|
|
106
|
+
>>> images = provider.generate(
|
|
107
|
+
... prompt="Epic dragon",
|
|
108
|
+
... amount=2,
|
|
109
|
+
... model="flux_1_dev",
|
|
110
|
+
... size="16_9"
|
|
111
|
+
... )
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
prompt (str): Your image description
|
|
115
|
+
amount (int): How many images you want (default: 1)
|
|
116
|
+
model (str): Model to use - check AVAILABLE_MODELS (default: "flux_1_schnell")
|
|
117
|
+
size (str): Image size ratio (default: "1_1")
|
|
118
|
+
is_public (bool): Whether to make the image public (default: False)
|
|
119
|
+
max_retries (int): Max retry attempts if something fails (default: 3)
|
|
120
|
+
retry_delay (int): Seconds to wait between retries (default: 5)
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
List[bytes]: Your generated images
|
|
124
|
+
|
|
125
|
+
Raises:
|
|
126
|
+
ValueError: If the inputs ain't valid
|
|
127
|
+
RequestException: If the API calls fail after retries
|
|
128
|
+
"""
|
|
129
|
+
if not prompt:
|
|
130
|
+
raise ValueError("Yo fam, the prompt can't be empty! 🤔")
|
|
131
|
+
if not isinstance(amount, int) or amount < 1:
|
|
132
|
+
raise ValueError("Amount needs to be a positive number! 📈")
|
|
133
|
+
if model not in self.AVAILABLE_MODELS:
|
|
134
|
+
raise ValueError(f"Model must be one of {self.AVAILABLE_MODELS}! 🎯")
|
|
135
|
+
if size not in self.AVAILABLE_SIZES:
|
|
136
|
+
raise ValueError(f"Size must be one of {self.AVAILABLE_SIZES}! 📏")
|
|
137
|
+
|
|
138
|
+
self.prompt = prompt
|
|
139
|
+
response = []
|
|
140
|
+
|
|
141
|
+
# Prepare payload
|
|
142
|
+
payload = {
|
|
143
|
+
"prompt": prompt,
|
|
144
|
+
"model": model,
|
|
145
|
+
"size": size,
|
|
146
|
+
"isPublic": is_public
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
for i in range(amount):
|
|
150
|
+
for attempt in range(max_retries):
|
|
151
|
+
try:
|
|
152
|
+
if self.logging:
|
|
153
|
+
print(f"Generating image {i+1}/{amount}... 🎨")
|
|
154
|
+
|
|
155
|
+
resp = self.session.post(
|
|
156
|
+
self.api_endpoint,
|
|
157
|
+
json=payload,
|
|
158
|
+
timeout=self.timeout
|
|
159
|
+
)
|
|
160
|
+
resp.raise_for_status()
|
|
161
|
+
result = resp.json()
|
|
162
|
+
|
|
163
|
+
if result and 'result' in result:
|
|
164
|
+
# Get base64 data and remove header
|
|
165
|
+
image_data = result['result']
|
|
166
|
+
base64_data = image_data.split(',')[1]
|
|
167
|
+
|
|
168
|
+
# Decode base64 data
|
|
169
|
+
image_bytes = base64.b64decode(base64_data)
|
|
170
|
+
response.append(image_bytes)
|
|
171
|
+
|
|
172
|
+
break
|
|
173
|
+
else:
|
|
174
|
+
raise RequestException("Invalid response format")
|
|
175
|
+
|
|
176
|
+
except RequestException as e:
|
|
177
|
+
if attempt == max_retries - 1:
|
|
178
|
+
raise RequestException(f"Failed to generate image after {max_retries} attempts: {e}")
|
|
179
|
+
|
|
180
|
+
time.sleep(retry_delay)
|
|
181
|
+
|
|
182
|
+
return response
|
|
183
|
+
|
|
184
|
+
def save(
|
|
185
|
+
self,
|
|
186
|
+
response: List[bytes],
|
|
187
|
+
name: Optional[str] = None,
|
|
188
|
+
dir: Optional[Union[str, Path]] = None,
|
|
189
|
+
filenames_prefix: str = "",
|
|
190
|
+
) -> List[str]:
|
|
191
|
+
"""Save your fire generated images! 💾
|
|
192
|
+
|
|
193
|
+
Examples:
|
|
194
|
+
>>> provider = FastFluxImager()
|
|
195
|
+
>>> images = provider.generate("Cool art")
|
|
196
|
+
>>> # Save with default settings
|
|
197
|
+
>>> paths = provider.save(images)
|
|
198
|
+
>>> # Save with custom name and directory
|
|
199
|
+
>>> paths = provider.save(
|
|
200
|
+
... images,
|
|
201
|
+
... name="my_art",
|
|
202
|
+
... dir="my_images",
|
|
203
|
+
... filenames_prefix="test_"
|
|
204
|
+
... )
|
|
205
|
+
|
|
206
|
+
Args:
|
|
207
|
+
response (List[bytes]): Your generated images
|
|
208
|
+
name (Optional[str]): Custom name for your images
|
|
209
|
+
dir (Optional[Union[str, Path]]): Where to save the images (default: current directory)
|
|
210
|
+
filenames_prefix (str): Prefix for your image files
|
|
211
|
+
|
|
212
|
+
Returns:
|
|
213
|
+
List[str]: Paths to your saved images
|
|
214
|
+
"""
|
|
215
|
+
save_dir = dir if dir else os.getcwd()
|
|
216
|
+
if not os.path.exists(save_dir):
|
|
217
|
+
os.makedirs(save_dir)
|
|
218
|
+
|
|
219
|
+
name = self.prompt if name is None else name
|
|
220
|
+
|
|
221
|
+
# Clean up name for filename use
|
|
222
|
+
safe_name = "".join(c if c.isalnum() or c in "_-" else "_" for c in name)
|
|
223
|
+
safe_name = safe_name[:50] # Truncate if too long
|
|
224
|
+
|
|
225
|
+
filenames = []
|
|
226
|
+
|
|
227
|
+
for i, image in enumerate(response):
|
|
228
|
+
filename = f"{filenames_prefix}{safe_name}_{i}.{self.image_extension}"
|
|
229
|
+
filepath = os.path.join(save_dir, filename)
|
|
230
|
+
|
|
231
|
+
with open(filepath, "wb") as f:
|
|
232
|
+
f.write(image)
|
|
233
|
+
|
|
234
|
+
filenames.append(filename)
|
|
235
|
+
|
|
236
|
+
return filenames
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
if __name__ == "__main__":
|
|
240
|
+
# Example usage
|
|
241
|
+
provider = FastFluxImager()
|
|
242
|
+
try:
|
|
243
|
+
images = provider.generate("A cyberpunk city at night with neon lights", amount=1)
|
|
244
|
+
paths = provider.save(images, dir="generated_images")
|
|
245
|
+
print(f"Successfully saved images to: {paths}")
|
|
246
|
+
except Exception as e:
|
|
247
|
+
print(f"Oops, something went wrong: {e}")
|
|
@@ -2,12 +2,11 @@ import time
|
|
|
2
2
|
import requests
|
|
3
3
|
import pathlib
|
|
4
4
|
import base64
|
|
5
|
+
import tempfile
|
|
5
6
|
from io import BytesIO
|
|
6
|
-
from playsound import playsound
|
|
7
7
|
from webscout import exceptions
|
|
8
8
|
from webscout.AIbase import TTSProvider
|
|
9
9
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
10
|
-
from webscout.Litlogger import Logger, LogFormat
|
|
11
10
|
from webscout.litagent import LitAgent
|
|
12
11
|
from . import utils
|
|
13
12
|
|
|
@@ -19,7 +18,6 @@ class DeepgramTTS(TTSProvider):
|
|
|
19
18
|
headers: dict[str, str] = {
|
|
20
19
|
"User-Agent": LitAgent().random()
|
|
21
20
|
}
|
|
22
|
-
cache_dir = pathlib.Path("./audio_cache")
|
|
23
21
|
all_voices: dict[str, str] = {
|
|
24
22
|
"Asteria": "aura-asteria-en", "Arcas": "aura-arcas-en", "Luna": "aura-luna-en",
|
|
25
23
|
"Zeus": "aura-zeus-en", "Orpheus": "aura-orpheus-en", "Angus": "aura-angus-en",
|
|
@@ -34,11 +32,7 @@ class DeepgramTTS(TTSProvider):
|
|
|
34
32
|
if proxies:
|
|
35
33
|
self.session.proxies.update(proxies)
|
|
36
34
|
self.timeout = timeout
|
|
37
|
-
self.
|
|
38
|
-
name="DeepgramTTS",
|
|
39
|
-
format=LogFormat.MODERN_EMOJI,
|
|
40
|
-
|
|
41
|
-
)
|
|
35
|
+
self.temp_dir = tempfile.mkdtemp(prefix="webscout_tts_")
|
|
42
36
|
|
|
43
37
|
def tts(self, text: str, voice: str = "Brian", verbose: bool = True) -> str:
|
|
44
38
|
"""
|
|
@@ -62,13 +56,13 @@ class DeepgramTTS(TTSProvider):
|
|
|
62
56
|
), f"Voice '{voice}' not one of [{', '.join(self.all_voices.keys())}]"
|
|
63
57
|
|
|
64
58
|
url = "https://deepgram.com/api/ttsAudioGeneration"
|
|
65
|
-
filename =
|
|
59
|
+
filename = pathlib.Path(tempfile.mktemp(suffix=".mp3", dir=self.temp_dir))
|
|
66
60
|
|
|
67
61
|
# Split text into sentences using the utils module
|
|
68
62
|
sentences = utils.split_sentences(text)
|
|
69
63
|
if verbose:
|
|
70
64
|
for index, sen in enumerate(sentences):
|
|
71
|
-
|
|
65
|
+
print(f"[debug] Sentence {index}: {sen}")
|
|
72
66
|
|
|
73
67
|
def generate_audio_for_chunk(part_text: str, part_number: int):
|
|
74
68
|
"""
|
|
@@ -103,15 +97,15 @@ class DeepgramTTS(TTSProvider):
|
|
|
103
97
|
if response_data:
|
|
104
98
|
audio_data = base64.b64decode(response_data)
|
|
105
99
|
if verbose:
|
|
106
|
-
|
|
100
|
+
print(f"[debug] Chunk {part_number} processed successfully")
|
|
107
101
|
return part_number, audio_data
|
|
108
102
|
|
|
109
103
|
if verbose:
|
|
110
|
-
|
|
104
|
+
print(f"[debug] No data received for chunk {part_number}. Attempt {retry_count + 1}/{max_retries}")
|
|
111
105
|
|
|
112
106
|
except requests.RequestException as e:
|
|
113
107
|
if verbose:
|
|
114
|
-
|
|
108
|
+
print(f"[debug] Error processing chunk {part_number}: {str(e)}. Attempt {retry_count + 1}/{max_retries}")
|
|
115
109
|
if retry_count == max_retries - 1:
|
|
116
110
|
raise
|
|
117
111
|
|
|
@@ -121,9 +115,6 @@ class DeepgramTTS(TTSProvider):
|
|
|
121
115
|
raise RuntimeError(f"Failed to generate audio for chunk {part_number} after {max_retries} attempts")
|
|
122
116
|
|
|
123
117
|
try:
|
|
124
|
-
# Create the audio_cache directory if it doesn't exist
|
|
125
|
-
self.cache_dir.mkdir(parents=True, exist_ok=True)
|
|
126
|
-
|
|
127
118
|
# Using ThreadPoolExecutor to handle requests concurrently
|
|
128
119
|
with ThreadPoolExecutor() as executor:
|
|
129
120
|
futures = {
|
|
@@ -148,36 +139,18 @@ class DeepgramTTS(TTSProvider):
|
|
|
148
139
|
f.write(audio_chunks[chunk_num])
|
|
149
140
|
|
|
150
141
|
if verbose:
|
|
151
|
-
|
|
142
|
+
print(f"[debug] Audio saved to {filename}")
|
|
152
143
|
return str(filename)
|
|
153
144
|
|
|
154
145
|
except Exception as e:
|
|
155
|
-
|
|
146
|
+
print(f"[debug] Failed to generate audio: {str(e)}") if verbose else None
|
|
156
147
|
raise RuntimeError(f"Failed to generate audio: {str(e)}")
|
|
157
148
|
|
|
158
|
-
def play_audio(self, filename: str):
|
|
159
|
-
"""
|
|
160
|
-
Plays an audio file using playsound.
|
|
161
|
-
|
|
162
|
-
Args:
|
|
163
|
-
filename (str): The path to the audio file.
|
|
164
|
-
|
|
165
|
-
Raises:
|
|
166
|
-
RuntimeError: If there is an error playing the audio.
|
|
167
|
-
"""
|
|
168
|
-
try:
|
|
169
|
-
playsound(filename)
|
|
170
|
-
except Exception as e:
|
|
171
|
-
self.logger.error(f"Failed to play audio: {str(e)} 🚨")
|
|
172
|
-
raise RuntimeError(f"Failed to play audio: {str(e)}")
|
|
173
|
-
|
|
174
149
|
# Example usage
|
|
175
150
|
if __name__ == "__main__":
|
|
176
151
|
deepgram = DeepgramTTS()
|
|
177
152
|
text = "This is a test of the DeepgramTTS text-to-speech API. It supports multiple sentences. Let's see how it works!"
|
|
178
153
|
|
|
179
|
-
|
|
180
|
-
audio_file = deepgram.tts(text, voice="
|
|
181
|
-
|
|
182
|
-
deepgram.logger.info("Playing audio...")
|
|
183
|
-
deepgram.play_audio(audio_file)
|
|
154
|
+
print("[debug] Generating audio...")
|
|
155
|
+
audio_file = deepgram.tts(text, voice="Asteria")
|
|
156
|
+
print(f"Audio saved to: {audio_file}")
|