webscout 7.7__py3-none-any.whl → 7.9__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/AIutel.py +2 -1
- webscout/Bard.py +12 -29
- webscout/DWEBS.py +477 -461
- webscout/Extra/__init__.py +2 -0
- webscout/Extra/autocoder/__init__.py +9 -9
- webscout/Extra/autocoder/{rawdog.py → autocoder.py} +849 -790
- webscout/Extra/autocoder/autocoder_utiles.py +332 -194
- webscout/Extra/gguf.py +682 -682
- webscout/Extra/tempmail/__init__.py +26 -0
- webscout/Extra/tempmail/async_utils.py +141 -0
- webscout/Extra/tempmail/base.py +156 -0
- webscout/Extra/tempmail/cli.py +187 -0
- webscout/Extra/tempmail/mail_tm.py +361 -0
- webscout/Extra/tempmail/temp_mail_io.py +292 -0
- webscout/Provider/AI21.py +1 -1
- webscout/Provider/AISEARCH/DeepFind.py +2 -2
- webscout/Provider/AISEARCH/ISou.py +2 -2
- webscout/Provider/AISEARCH/felo_search.py +6 -6
- webscout/Provider/AISEARCH/genspark_search.py +1 -1
- webscout/Provider/Aitopia.py +292 -0
- webscout/Provider/AllenAI.py +1 -1
- webscout/Provider/Andi.py +3 -3
- webscout/Provider/C4ai.py +1 -1
- webscout/Provider/ChatGPTES.py +3 -5
- webscout/Provider/ChatGPTGratis.py +4 -4
- webscout/Provider/Chatify.py +2 -2
- webscout/Provider/Cloudflare.py +3 -2
- webscout/Provider/DeepSeek.py +2 -2
- webscout/Provider/Deepinfra.py +288 -286
- webscout/Provider/ElectronHub.py +709 -634
- webscout/Provider/ExaChat.py +325 -0
- webscout/Provider/Free2GPT.py +2 -2
- webscout/Provider/Gemini.py +167 -179
- webscout/Provider/GithubChat.py +1 -1
- webscout/Provider/Glider.py +4 -4
- webscout/Provider/Groq.py +41 -27
- webscout/Provider/HF_space/qwen_qwen2.py +1 -1
- webscout/Provider/HeckAI.py +1 -1
- webscout/Provider/HuggingFaceChat.py +1 -1
- webscout/Provider/Hunyuan.py +1 -1
- webscout/Provider/Jadve.py +3 -3
- webscout/Provider/Koboldai.py +3 -3
- webscout/Provider/LambdaChat.py +3 -2
- webscout/Provider/Llama.py +3 -5
- webscout/Provider/Llama3.py +4 -12
- webscout/Provider/Marcus.py +3 -3
- webscout/Provider/OLLAMA.py +8 -8
- webscout/Provider/Openai.py +7 -3
- webscout/Provider/PI.py +1 -1
- webscout/Provider/Perplexitylabs.py +1 -1
- webscout/Provider/Phind.py +1 -1
- webscout/Provider/PizzaGPT.py +1 -1
- webscout/Provider/QwenLM.py +4 -7
- webscout/Provider/TTI/FreeAIPlayground/async_freeaiplayground.py +3 -1
- webscout/Provider/TTI/FreeAIPlayground/sync_freeaiplayground.py +3 -3
- webscout/Provider/TTI/ImgSys/__init__.py +23 -0
- webscout/Provider/TTI/ImgSys/async_imgsys.py +202 -0
- webscout/Provider/TTI/ImgSys/sync_imgsys.py +195 -0
- webscout/Provider/TTI/__init__.py +3 -1
- webscout/Provider/TTI/artbit/async_artbit.py +1 -1
- webscout/Provider/TTI/artbit/sync_artbit.py +1 -1
- webscout/Provider/TTI/huggingface/async_huggingface.py +1 -1
- webscout/Provider/TTI/huggingface/sync_huggingface.py +1 -1
- webscout/Provider/TTI/piclumen/__init__.py +22 -22
- webscout/Provider/TTI/piclumen/sync_piclumen.py +232 -232
- webscout/Provider/TTI/pixelmuse/__init__.py +4 -0
- webscout/Provider/TTI/pixelmuse/async_pixelmuse.py +249 -0
- webscout/Provider/TTI/pixelmuse/sync_pixelmuse.py +182 -0
- webscout/Provider/TTI/talkai/sync_talkai.py +1 -1
- webscout/Provider/TTS/utils.py +1 -1
- webscout/Provider/TeachAnything.py +1 -1
- webscout/Provider/TextPollinationsAI.py +232 -230
- webscout/Provider/TwoAI.py +1 -2
- webscout/Provider/Venice.py +4 -2
- webscout/Provider/VercelAI.py +234 -0
- webscout/Provider/WebSim.py +3 -2
- webscout/Provider/WiseCat.py +10 -12
- webscout/Provider/Youchat.py +1 -1
- webscout/Provider/__init__.py +10 -4
- webscout/Provider/ai4chat.py +1 -1
- webscout/Provider/aimathgpt.py +2 -6
- webscout/Provider/akashgpt.py +1 -1
- webscout/Provider/askmyai.py +4 -4
- webscout/Provider/{DARKAI.py → asksteve.py} +56 -77
- webscout/Provider/bagoodex.py +2 -2
- webscout/Provider/cerebras.py +1 -1
- webscout/Provider/chatglm.py +4 -4
- webscout/Provider/cleeai.py +1 -0
- webscout/Provider/copilot.py +21 -9
- webscout/Provider/elmo.py +1 -1
- webscout/Provider/flowith.py +1 -1
- webscout/Provider/freeaichat.py +64 -31
- webscout/Provider/gaurish.py +3 -5
- webscout/Provider/geminiprorealtime.py +1 -1
- webscout/Provider/granite.py +4 -4
- webscout/Provider/hermes.py +5 -5
- webscout/Provider/julius.py +1 -1
- webscout/Provider/koala.py +1 -1
- webscout/Provider/lepton.py +1 -1
- webscout/Provider/llama3mitril.py +4 -4
- webscout/Provider/llamatutor.py +1 -1
- webscout/Provider/llmchat.py +3 -3
- webscout/Provider/meta.py +1 -1
- webscout/Provider/multichat.py +10 -10
- webscout/Provider/promptrefine.py +1 -1
- webscout/Provider/searchchat.py +293 -0
- webscout/Provider/sonus.py +2 -2
- webscout/Provider/talkai.py +2 -2
- webscout/Provider/turboseek.py +1 -1
- webscout/Provider/tutorai.py +1 -1
- webscout/Provider/typegpt.py +5 -42
- webscout/Provider/uncovr.py +312 -297
- webscout/Provider/x0gpt.py +1 -1
- webscout/Provider/yep.py +64 -12
- webscout/__init__.py +3 -1
- webscout/cli.py +59 -98
- webscout/conversation.py +350 -17
- webscout/litprinter/__init__.py +59 -667
- webscout/optimizers.py +419 -419
- webscout/tempid.py +11 -11
- webscout/update_checker.py +14 -12
- webscout/utils.py +2 -2
- webscout/version.py +1 -1
- webscout/webscout_search.py +146 -87
- webscout/webscout_search_async.py +148 -27
- {webscout-7.7.dist-info → webscout-7.9.dist-info}/METADATA +92 -66
- webscout-7.9.dist-info/RECORD +248 -0
- webscout/Provider/EDITEE.py +0 -192
- webscout/litprinter/colors.py +0 -54
- webscout-7.7.dist-info/RECORD +0 -234
- {webscout-7.7.dist-info → webscout-7.9.dist-info}/LICENSE.md +0 -0
- {webscout-7.7.dist-info → webscout-7.9.dist-info}/WHEEL +0 -0
- {webscout-7.7.dist-info → webscout-7.9.dist-info}/entry_points.txt +0 -0
- {webscout-7.7.dist-info → webscout-7.9.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}")
|