webscout 7.5__py3-none-any.whl → 7.7__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/__init__.py +9 -9
- webscout/Extra/autocoder/autocoder_utiles.py +193 -199
- webscout/Extra/autocoder/rawdog.py +789 -677
- webscout/Extra/gguf.py +682 -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 -22
- webscout/Provider/AISEARCH/felo_search.py +0 -1
- webscout/Provider/AllenAI.py +28 -30
- webscout/Provider/C4ai.py +29 -11
- webscout/Provider/ChatGPTClone.py +226 -0
- webscout/Provider/ChatGPTGratis.py +24 -56
- webscout/Provider/DeepSeek.py +25 -17
- webscout/Provider/Deepinfra.py +115 -48
- webscout/Provider/Gemini.py +1 -1
- webscout/Provider/Glider.py +33 -12
- webscout/Provider/HF_space/qwen_qwen2.py +2 -2
- webscout/Provider/HeckAI.py +23 -7
- webscout/Provider/Hunyuan.py +272 -0
- webscout/Provider/Jadve.py +20 -5
- webscout/Provider/LambdaChat.py +391 -0
- webscout/Provider/Netwrck.py +42 -19
- webscout/Provider/OLLAMA.py +256 -32
- webscout/Provider/PI.py +4 -2
- webscout/Provider/Perplexitylabs.py +26 -6
- 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 +179 -206
- webscout/Provider/TTI/FreeAIPlayground/sync_freeaiplayground.py +180 -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/async_aiarta.py +14 -14
- webscout/Provider/TTI/aiarta/sync_aiarta.py +52 -21
- webscout/Provider/TTI/artbit/async_artbit.py +3 -32
- webscout/Provider/TTI/artbit/sync_artbit.py +3 -31
- webscout/Provider/TTI/fastflux/__init__.py +22 -0
- webscout/Provider/TTI/fastflux/async_fastflux.py +261 -0
- webscout/Provider/TTI/fastflux/sync_fastflux.py +252 -0
- webscout/Provider/TTI/piclumen/__init__.py +22 -22
- webscout/Provider/TTI/piclumen/sync_piclumen.py +232 -232
- 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 +25 -8
- webscout/Provider/WebSim.py +227 -0
- webscout/Provider/WiseCat.py +27 -5
- webscout/Provider/Youchat.py +64 -37
- webscout/Provider/__init__.py +12 -7
- webscout/Provider/akashgpt.py +20 -5
- webscout/Provider/flowith.py +33 -7
- webscout/Provider/freeaichat.py +32 -45
- webscout/Provider/koala.py +20 -5
- webscout/Provider/labyrinth.py +239 -0
- webscout/Provider/learnfastai.py +28 -15
- webscout/Provider/llamatutor.py +1 -1
- webscout/Provider/llmchat.py +30 -8
- webscout/Provider/multichat.py +65 -9
- webscout/Provider/sonus.py +208 -0
- webscout/Provider/talkai.py +1 -0
- webscout/Provider/turboseek.py +3 -0
- webscout/Provider/tutorai.py +2 -0
- webscout/Provider/typegpt.py +155 -65
- webscout/Provider/uncovr.py +297 -0
- webscout/Provider/x0gpt.py +3 -1
- webscout/Provider/yep.py +102 -20
- webscout/__init__.py +3 -0
- webscout/cli.py +53 -40
- webscout/conversation.py +1 -10
- webscout/litagent/__init__.py +2 -2
- webscout/litagent/agent.py +356 -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 +1 -3
- webscout/version.py +1 -1
- webscout/webscout_search_async.py +1 -2
- webscout/yep_search.py +297 -297
- {webscout-7.5.dist-info → webscout-7.7.dist-info}/LICENSE.md +4 -4
- {webscout-7.5.dist-info → webscout-7.7.dist-info}/METADATA +127 -405
- {webscout-7.5.dist-info → webscout-7.7.dist-info}/RECORD +118 -117
- webscout/Extra/autollama.py +0 -231
- 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-7.5.dist-info → webscout-7.7.dist-info}/WHEEL +0 -0
- {webscout-7.5.dist-info → webscout-7.7.dist-info}/entry_points.txt +0 -0
- {webscout-7.5.dist-info → webscout-7.7.dist-info}/top_level.txt +0 -0
|
@@ -1,233 +1,233 @@
|
|
|
1
|
-
"""PiclumenImager Synchronous Provider - Your go-to for high-quality AI art! 🔥
|
|
2
|
-
|
|
3
|
-
Examples:
|
|
4
|
-
>>> from webscout import PiclumenImager
|
|
5
|
-
>>> provider = PiclumenImager()
|
|
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="An underwater alien creature with bioluminescent features",
|
|
14
|
-
... amount=3
|
|
15
|
-
... )
|
|
16
|
-
>>> provider.save(images, dir="creatures")
|
|
17
|
-
"""
|
|
18
|
-
|
|
19
|
-
import requests
|
|
20
|
-
import os
|
|
21
|
-
import time
|
|
22
|
-
import json
|
|
23
|
-
from typing import List, Optional, Union
|
|
24
|
-
from datetime import datetime
|
|
25
|
-
from pathlib import Path
|
|
26
|
-
from requests.exceptions import RequestException
|
|
27
|
-
|
|
28
|
-
from webscout.AIbase import ImageProvider
|
|
29
|
-
from webscout.litagent import LitAgent
|
|
30
|
-
|
|
31
|
-
# Get a fresh user agent! 🔄
|
|
32
|
-
agent = LitAgent()
|
|
33
|
-
|
|
34
|
-
class PiclumenImager(ImageProvider):
|
|
35
|
-
"""Your homie for generating fire images using Piclumen! 🎨
|
|
36
|
-
|
|
37
|
-
This provider generates high-quality AI art with built-in retry logic
|
|
38
|
-
and error handling to make sure you get your images no cap! 💯
|
|
39
|
-
|
|
40
|
-
Examples:
|
|
41
|
-
>>> provider = PiclumenImager()
|
|
42
|
-
>>> # Generate one image
|
|
43
|
-
>>> image = provider.generate("A futuristic city")
|
|
44
|
-
>>> provider.save(image, "city.jpg")
|
|
45
|
-
>>>
|
|
46
|
-
>>> # Generate multiple images
|
|
47
|
-
>>> images = provider.generate(
|
|
48
|
-
... prompt="Underwater alien creatures",
|
|
49
|
-
... amount=3
|
|
50
|
-
... )
|
|
51
|
-
>>> provider.save(images, dir="ocean_creatures")
|
|
52
|
-
"""
|
|
53
|
-
|
|
54
|
-
def __init__(
|
|
55
|
-
self,
|
|
56
|
-
timeout: int = 120,
|
|
57
|
-
proxies: Optional[dict] = None
|
|
58
|
-
):
|
|
59
|
-
"""Initialize your PiclumenImager provider with custom settings
|
|
60
|
-
|
|
61
|
-
Examples:
|
|
62
|
-
>>> provider = PiclumenImager(timeout=180)
|
|
63
|
-
>>> provider = PiclumenImager(proxies={"http": "http://proxy:8080"})
|
|
64
|
-
|
|
65
|
-
Args:
|
|
66
|
-
timeout (int): HTTP request timeout in seconds (default: 120)
|
|
67
|
-
proxies (dict, optional): Proxy configuration for requests
|
|
68
|
-
"""
|
|
69
|
-
self.api_endpoint = "https://s9.piclumen.art/comfy/api/generate-image"
|
|
70
|
-
self.headers = {
|
|
71
|
-
"Accept": "application/json",
|
|
72
|
-
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
73
|
-
"Accept-Language": "en-US,en;q=0.9,en-IN;q=0.8",
|
|
74
|
-
"Content-Type": "application/json",
|
|
75
|
-
"DNT": "1",
|
|
76
|
-
"Origin": "https://www.piclumen.com",
|
|
77
|
-
"Referer": "https://s9.piclumen.art/",
|
|
78
|
-
"Sec-Ch-Ua": '"Not(A:Brand";v="99", "Microsoft Edge";v="133", "Chromium";v="133"',
|
|
79
|
-
"Sec-Ch-Ua-Mobile": "?0",
|
|
80
|
-
"Sec-Ch-Ua-Platform": '"Windows"',
|
|
81
|
-
"Sec-Fetch-Dest": "empty",
|
|
82
|
-
"Sec-Fetch-Mode": "cors",
|
|
83
|
-
"Sec-Fetch-Site": "cross-site",
|
|
84
|
-
"Sec-Gpc": "1",
|
|
85
|
-
"User-Agent": agent.random(), # Using our fire random agent! 🔥
|
|
86
|
-
}
|
|
87
|
-
self.session = requests.Session()
|
|
88
|
-
self.session.headers.update(self.headers)
|
|
89
|
-
if proxies:
|
|
90
|
-
self.session.proxies.update(proxies)
|
|
91
|
-
|
|
92
|
-
self.timeout = timeout
|
|
93
|
-
self.prompt: str = "AI-generated image - webscout"
|
|
94
|
-
self.image_extension: str = "jpg"
|
|
95
|
-
|
|
96
|
-
def generate(
|
|
97
|
-
self,
|
|
98
|
-
prompt: str,
|
|
99
|
-
amount: int = 1,
|
|
100
|
-
max_retries: int = 3,
|
|
101
|
-
retry_delay: int = 5
|
|
102
|
-
) -> List[bytes]:
|
|
103
|
-
"""Generate some fire images from your prompt! 🎨
|
|
104
|
-
|
|
105
|
-
Args:
|
|
106
|
-
prompt (str): Your image description
|
|
107
|
-
amount (int): How many images you want (default: 1)
|
|
108
|
-
max_retries (int): Max retry attempts if something fails (default: 3)
|
|
109
|
-
retry_delay (int): Seconds to wait between retries (default: 5)
|
|
110
|
-
|
|
111
|
-
Returns:
|
|
112
|
-
List[bytes]: Your generated images as bytes
|
|
113
|
-
|
|
114
|
-
Raises:
|
|
115
|
-
ValueError: If the inputs ain't valid
|
|
116
|
-
RequestException: If the API calls fail after retries
|
|
117
|
-
"""
|
|
118
|
-
# Input validation
|
|
119
|
-
if not prompt:
|
|
120
|
-
raise ValueError("Yo fam, the prompt can't be empty! 🤔")
|
|
121
|
-
if not isinstance(amount, int) or amount < 1:
|
|
122
|
-
raise ValueError("Amount needs to be a positive number! 📈")
|
|
123
|
-
|
|
124
|
-
self.prompt = prompt
|
|
125
|
-
response = []
|
|
126
|
-
|
|
127
|
-
# Payload with the prompt
|
|
128
|
-
payload = {
|
|
129
|
-
"prompt": prompt
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
for i in range(amount):
|
|
133
|
-
for attempt in range(max_retries):
|
|
134
|
-
try:
|
|
135
|
-
resp = self.session.post(
|
|
136
|
-
self.api_endpoint,
|
|
137
|
-
json=payload,
|
|
138
|
-
timeout=self.timeout
|
|
139
|
-
)
|
|
140
|
-
resp.raise_for_status()
|
|
141
|
-
|
|
142
|
-
# Check if response is an image
|
|
143
|
-
if resp.headers.get('content-type') == 'image/jpeg':
|
|
144
|
-
response.append(resp.content)
|
|
145
|
-
break
|
|
146
|
-
else:
|
|
147
|
-
if attempt == max_retries - 1:
|
|
148
|
-
raise RequestException(f"API returned non-image content: {resp.text[:100]}")
|
|
149
|
-
|
|
150
|
-
except RequestException as e:
|
|
151
|
-
if attempt == max_retries - 1:
|
|
152
|
-
raise
|
|
153
|
-
time.sleep(retry_delay)
|
|
154
|
-
|
|
155
|
-
return response
|
|
156
|
-
|
|
157
|
-
def save(
|
|
158
|
-
self,
|
|
159
|
-
response: List[bytes],
|
|
160
|
-
name: Optional[str] = None,
|
|
161
|
-
dir: Optional[Union[str, Path]] = None,
|
|
162
|
-
filenames_prefix: str = "",
|
|
163
|
-
) -> List[str]:
|
|
164
|
-
"""Save your fire generated images! 💾
|
|
165
|
-
|
|
166
|
-
Examples:
|
|
167
|
-
>>> provider = PiclumenImager()
|
|
168
|
-
>>> images = provider.generate("Cool art")
|
|
169
|
-
>>> # Save with default settings
|
|
170
|
-
>>> paths = provider.save(images)
|
|
171
|
-
>>> # Save with custom name and directory
|
|
172
|
-
>>> paths = provider.save(
|
|
173
|
-
... images,
|
|
174
|
-
... name="my_art",
|
|
175
|
-
... dir="my_images",
|
|
176
|
-
... filenames_prefix="test_"
|
|
177
|
-
... )
|
|
178
|
-
|
|
179
|
-
Args:
|
|
180
|
-
response (List[bytes]): Your generated images
|
|
181
|
-
name (Optional[str]): Custom name for your images
|
|
182
|
-
dir (Optional[Union[str, Path]]): Where to save the images (default: current directory)
|
|
183
|
-
filenames_prefix (str): Prefix for your image files
|
|
184
|
-
|
|
185
|
-
Returns:
|
|
186
|
-
List[str]: Paths to your saved images
|
|
187
|
-
"""
|
|
188
|
-
save_dir = dir if dir else os.getcwd()
|
|
189
|
-
if not os.path.exists(save_dir):
|
|
190
|
-
os.makedirs(save_dir)
|
|
191
|
-
|
|
192
|
-
saved_paths = []
|
|
193
|
-
timestamp = int(time.time())
|
|
194
|
-
|
|
195
|
-
# Clean up name for filename use
|
|
196
|
-
safe_name = ""
|
|
197
|
-
if name:
|
|
198
|
-
safe_name = "".join(c if c.isalnum() or c in "_-" else "_" for c in name)
|
|
199
|
-
|
|
200
|
-
# Use prompt-based name if no name is provided
|
|
201
|
-
if not safe_name and self.prompt:
|
|
202
|
-
# Clean and truncate prompt for filename
|
|
203
|
-
prompt_words = self.prompt.split()[:5] # First 5 words
|
|
204
|
-
safe_name = "_".join("".join(c if c.isalnum() else "_" for c in word) for word in prompt_words).lower()
|
|
205
|
-
|
|
206
|
-
for i, image_bytes in enumerate(response):
|
|
207
|
-
if safe_name:
|
|
208
|
-
filename = f"{filenames_prefix}{safe_name}_{i}.{self.image_extension}"
|
|
209
|
-
else:
|
|
210
|
-
filename = f"{filenames_prefix}piclumen_{timestamp}_{i}.{self.image_extension}"
|
|
211
|
-
|
|
212
|
-
filepath = os.path.join(save_dir, filename)
|
|
213
|
-
|
|
214
|
-
with open(filepath, "wb") as f:
|
|
215
|
-
f.write(image_bytes)
|
|
216
|
-
|
|
217
|
-
saved_paths.append(filepath)
|
|
218
|
-
|
|
219
|
-
return saved_paths
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if __name__ == "__main__":
|
|
223
|
-
# Example usage
|
|
224
|
-
provider = PiclumenImager()
|
|
225
|
-
try:
|
|
226
|
-
images = provider.generate(
|
|
227
|
-
prompt="underwater macro photography, alien-like sea creature, translucent body, feathery appendages, glowing orbs, bioluminescent, ethereal, surreal",
|
|
228
|
-
amount=1
|
|
229
|
-
)
|
|
230
|
-
paths = provider.save(images, dir="generated_images")
|
|
231
|
-
print(f"Successfully saved images to: {paths}")
|
|
232
|
-
except Exception as e:
|
|
1
|
+
"""PiclumenImager Synchronous Provider - Your go-to for high-quality AI art! 🔥
|
|
2
|
+
|
|
3
|
+
Examples:
|
|
4
|
+
>>> from webscout import PiclumenImager
|
|
5
|
+
>>> provider = PiclumenImager()
|
|
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="An underwater alien creature with bioluminescent features",
|
|
14
|
+
... amount=3
|
|
15
|
+
... )
|
|
16
|
+
>>> provider.save(images, dir="creatures")
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import requests
|
|
20
|
+
import os
|
|
21
|
+
import time
|
|
22
|
+
import json
|
|
23
|
+
from typing import List, Optional, Union
|
|
24
|
+
from datetime import datetime
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
from requests.exceptions import RequestException
|
|
27
|
+
|
|
28
|
+
from webscout.AIbase import ImageProvider
|
|
29
|
+
from webscout.litagent import LitAgent
|
|
30
|
+
|
|
31
|
+
# Get a fresh user agent! 🔄
|
|
32
|
+
agent = LitAgent()
|
|
33
|
+
|
|
34
|
+
class PiclumenImager(ImageProvider):
|
|
35
|
+
"""Your homie for generating fire images using Piclumen! 🎨
|
|
36
|
+
|
|
37
|
+
This provider generates high-quality AI art with built-in retry logic
|
|
38
|
+
and error handling to make sure you get your images no cap! 💯
|
|
39
|
+
|
|
40
|
+
Examples:
|
|
41
|
+
>>> provider = PiclumenImager()
|
|
42
|
+
>>> # Generate one image
|
|
43
|
+
>>> image = provider.generate("A futuristic city")
|
|
44
|
+
>>> provider.save(image, "city.jpg")
|
|
45
|
+
>>>
|
|
46
|
+
>>> # Generate multiple images
|
|
47
|
+
>>> images = provider.generate(
|
|
48
|
+
... prompt="Underwater alien creatures",
|
|
49
|
+
... amount=3
|
|
50
|
+
... )
|
|
51
|
+
>>> provider.save(images, dir="ocean_creatures")
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(
|
|
55
|
+
self,
|
|
56
|
+
timeout: int = 120,
|
|
57
|
+
proxies: Optional[dict] = None
|
|
58
|
+
):
|
|
59
|
+
"""Initialize your PiclumenImager provider with custom settings
|
|
60
|
+
|
|
61
|
+
Examples:
|
|
62
|
+
>>> provider = PiclumenImager(timeout=180)
|
|
63
|
+
>>> provider = PiclumenImager(proxies={"http": "http://proxy:8080"})
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
timeout (int): HTTP request timeout in seconds (default: 120)
|
|
67
|
+
proxies (dict, optional): Proxy configuration for requests
|
|
68
|
+
"""
|
|
69
|
+
self.api_endpoint = "https://s9.piclumen.art/comfy/api/generate-image"
|
|
70
|
+
self.headers = {
|
|
71
|
+
"Accept": "application/json",
|
|
72
|
+
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
73
|
+
"Accept-Language": "en-US,en;q=0.9,en-IN;q=0.8",
|
|
74
|
+
"Content-Type": "application/json",
|
|
75
|
+
"DNT": "1",
|
|
76
|
+
"Origin": "https://www.piclumen.com",
|
|
77
|
+
"Referer": "https://s9.piclumen.art/",
|
|
78
|
+
"Sec-Ch-Ua": '"Not(A:Brand";v="99", "Microsoft Edge";v="133", "Chromium";v="133"',
|
|
79
|
+
"Sec-Ch-Ua-Mobile": "?0",
|
|
80
|
+
"Sec-Ch-Ua-Platform": '"Windows"',
|
|
81
|
+
"Sec-Fetch-Dest": "empty",
|
|
82
|
+
"Sec-Fetch-Mode": "cors",
|
|
83
|
+
"Sec-Fetch-Site": "cross-site",
|
|
84
|
+
"Sec-Gpc": "1",
|
|
85
|
+
"User-Agent": agent.random(), # Using our fire random agent! 🔥
|
|
86
|
+
}
|
|
87
|
+
self.session = requests.Session()
|
|
88
|
+
self.session.headers.update(self.headers)
|
|
89
|
+
if proxies:
|
|
90
|
+
self.session.proxies.update(proxies)
|
|
91
|
+
|
|
92
|
+
self.timeout = timeout
|
|
93
|
+
self.prompt: str = "AI-generated image - webscout"
|
|
94
|
+
self.image_extension: str = "jpg"
|
|
95
|
+
|
|
96
|
+
def generate(
|
|
97
|
+
self,
|
|
98
|
+
prompt: str,
|
|
99
|
+
amount: int = 1,
|
|
100
|
+
max_retries: int = 3,
|
|
101
|
+
retry_delay: int = 5
|
|
102
|
+
) -> List[bytes]:
|
|
103
|
+
"""Generate some fire images from your prompt! 🎨
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
prompt (str): Your image description
|
|
107
|
+
amount (int): How many images you want (default: 1)
|
|
108
|
+
max_retries (int): Max retry attempts if something fails (default: 3)
|
|
109
|
+
retry_delay (int): Seconds to wait between retries (default: 5)
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
List[bytes]: Your generated images as bytes
|
|
113
|
+
|
|
114
|
+
Raises:
|
|
115
|
+
ValueError: If the inputs ain't valid
|
|
116
|
+
RequestException: If the API calls fail after retries
|
|
117
|
+
"""
|
|
118
|
+
# Input validation
|
|
119
|
+
if not prompt:
|
|
120
|
+
raise ValueError("Yo fam, the prompt can't be empty! 🤔")
|
|
121
|
+
if not isinstance(amount, int) or amount < 1:
|
|
122
|
+
raise ValueError("Amount needs to be a positive number! 📈")
|
|
123
|
+
|
|
124
|
+
self.prompt = prompt
|
|
125
|
+
response = []
|
|
126
|
+
|
|
127
|
+
# Payload with the prompt
|
|
128
|
+
payload = {
|
|
129
|
+
"prompt": prompt
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
for i in range(amount):
|
|
133
|
+
for attempt in range(max_retries):
|
|
134
|
+
try:
|
|
135
|
+
resp = self.session.post(
|
|
136
|
+
self.api_endpoint,
|
|
137
|
+
json=payload,
|
|
138
|
+
timeout=self.timeout
|
|
139
|
+
)
|
|
140
|
+
resp.raise_for_status()
|
|
141
|
+
|
|
142
|
+
# Check if response is an image
|
|
143
|
+
if resp.headers.get('content-type') == 'image/jpeg':
|
|
144
|
+
response.append(resp.content)
|
|
145
|
+
break
|
|
146
|
+
else:
|
|
147
|
+
if attempt == max_retries - 1:
|
|
148
|
+
raise RequestException(f"API returned non-image content: {resp.text[:100]}")
|
|
149
|
+
|
|
150
|
+
except RequestException as e:
|
|
151
|
+
if attempt == max_retries - 1:
|
|
152
|
+
raise
|
|
153
|
+
time.sleep(retry_delay)
|
|
154
|
+
|
|
155
|
+
return response
|
|
156
|
+
|
|
157
|
+
def save(
|
|
158
|
+
self,
|
|
159
|
+
response: List[bytes],
|
|
160
|
+
name: Optional[str] = None,
|
|
161
|
+
dir: Optional[Union[str, Path]] = None,
|
|
162
|
+
filenames_prefix: str = "",
|
|
163
|
+
) -> List[str]:
|
|
164
|
+
"""Save your fire generated images! 💾
|
|
165
|
+
|
|
166
|
+
Examples:
|
|
167
|
+
>>> provider = PiclumenImager()
|
|
168
|
+
>>> images = provider.generate("Cool art")
|
|
169
|
+
>>> # Save with default settings
|
|
170
|
+
>>> paths = provider.save(images)
|
|
171
|
+
>>> # Save with custom name and directory
|
|
172
|
+
>>> paths = provider.save(
|
|
173
|
+
... images,
|
|
174
|
+
... name="my_art",
|
|
175
|
+
... dir="my_images",
|
|
176
|
+
... filenames_prefix="test_"
|
|
177
|
+
... )
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
response (List[bytes]): Your generated images
|
|
181
|
+
name (Optional[str]): Custom name for your images
|
|
182
|
+
dir (Optional[Union[str, Path]]): Where to save the images (default: current directory)
|
|
183
|
+
filenames_prefix (str): Prefix for your image files
|
|
184
|
+
|
|
185
|
+
Returns:
|
|
186
|
+
List[str]: Paths to your saved images
|
|
187
|
+
"""
|
|
188
|
+
save_dir = dir if dir else os.getcwd()
|
|
189
|
+
if not os.path.exists(save_dir):
|
|
190
|
+
os.makedirs(save_dir)
|
|
191
|
+
|
|
192
|
+
saved_paths = []
|
|
193
|
+
timestamp = int(time.time())
|
|
194
|
+
|
|
195
|
+
# Clean up name for filename use
|
|
196
|
+
safe_name = ""
|
|
197
|
+
if name:
|
|
198
|
+
safe_name = "".join(c if c.isalnum() or c in "_-" else "_" for c in name)
|
|
199
|
+
|
|
200
|
+
# Use prompt-based name if no name is provided
|
|
201
|
+
if not safe_name and self.prompt:
|
|
202
|
+
# Clean and truncate prompt for filename
|
|
203
|
+
prompt_words = self.prompt.split()[:5] # First 5 words
|
|
204
|
+
safe_name = "_".join("".join(c if c.isalnum() else "_" for c in word) for word in prompt_words).lower()
|
|
205
|
+
|
|
206
|
+
for i, image_bytes in enumerate(response):
|
|
207
|
+
if safe_name:
|
|
208
|
+
filename = f"{filenames_prefix}{safe_name}_{i}.{self.image_extension}"
|
|
209
|
+
else:
|
|
210
|
+
filename = f"{filenames_prefix}piclumen_{timestamp}_{i}.{self.image_extension}"
|
|
211
|
+
|
|
212
|
+
filepath = os.path.join(save_dir, filename)
|
|
213
|
+
|
|
214
|
+
with open(filepath, "wb") as f:
|
|
215
|
+
f.write(image_bytes)
|
|
216
|
+
|
|
217
|
+
saved_paths.append(filepath)
|
|
218
|
+
|
|
219
|
+
return saved_paths
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
if __name__ == "__main__":
|
|
223
|
+
# Example usage
|
|
224
|
+
provider = PiclumenImager()
|
|
225
|
+
try:
|
|
226
|
+
images = provider.generate(
|
|
227
|
+
prompt="underwater macro photography, alien-like sea creature, translucent body, feathery appendages, glowing orbs, bioluminescent, ethereal, surreal",
|
|
228
|
+
amount=1
|
|
229
|
+
)
|
|
230
|
+
paths = provider.save(images, dir="generated_images")
|
|
231
|
+
print(f"Successfully saved images to: {paths}")
|
|
232
|
+
except Exception as e:
|
|
233
233
|
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}")
|