webscout 6.3__py3-none-any.whl → 6.5__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 +0 -197
- webscout/AIutel.py +441 -1130
- webscout/DWEBS.py +189 -35
- webscout/{YTdownloader.py → Extra/YTToolkit/YTdownloader.py} +990 -1103
- webscout/Extra/YTToolkit/__init__.py +3 -0
- webscout/{transcriber.py → Extra/YTToolkit/transcriber.py} +479 -551
- webscout/Extra/YTToolkit/ytapi/__init__.py +6 -0
- webscout/Extra/YTToolkit/ytapi/channel.py +307 -0
- webscout/Extra/YTToolkit/ytapi/errors.py +13 -0
- webscout/Extra/YTToolkit/ytapi/extras.py +45 -0
- webscout/Extra/YTToolkit/ytapi/https.py +88 -0
- webscout/Extra/YTToolkit/ytapi/patterns.py +61 -0
- webscout/Extra/YTToolkit/ytapi/playlist.py +59 -0
- webscout/Extra/YTToolkit/ytapi/pool.py +8 -0
- webscout/Extra/YTToolkit/ytapi/query.py +37 -0
- webscout/Extra/YTToolkit/ytapi/stream.py +60 -0
- webscout/Extra/YTToolkit/ytapi/utils.py +62 -0
- webscout/Extra/YTToolkit/ytapi/video.py +102 -0
- webscout/Extra/__init__.py +3 -1
- webscout/Extra/autocoder/__init__.py +9 -0
- webscout/Extra/autocoder/autocoder_utiles.py +121 -0
- webscout/Extra/autocoder/rawdog.py +680 -0
- webscout/Extra/autollama.py +246 -195
- webscout/Extra/gguf.py +81 -56
- webscout/Extra/markdownlite/__init__.py +862 -0
- webscout/Extra/weather_ascii.py +2 -2
- webscout/LLM.py +206 -43
- webscout/Litlogger/__init__.py +681 -0
- webscout/Provider/DARKAI.py +1 -1
- webscout/Provider/EDITEE.py +1 -1
- webscout/Provider/NinjaChat.py +1 -1
- webscout/Provider/PI.py +120 -35
- webscout/Provider/Perplexity.py +590 -598
- webscout/Provider/Reka.py +0 -1
- 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 +2 -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/TTS/__init__.py +5 -1
- webscout/Provider/TTS/deepgram.py +183 -0
- webscout/Provider/TTS/elevenlabs.py +137 -0
- webscout/Provider/TTS/gesserit.py +151 -0
- webscout/Provider/TTS/murfai.py +139 -0
- webscout/Provider/TTS/parler.py +134 -107
- webscout/Provider/TTS/streamElements.py +360 -275
- webscout/Provider/TTS/utils.py +280 -0
- webscout/Provider/TTS/voicepod.py +116 -116
- webscout/Provider/__init__.py +8 -1
- webscout/Provider/askmyai.py +2 -2
- webscout/Provider/cerebras.py +227 -219
- webscout/Provider/llama3mitril.py +0 -1
- webscout/Provider/meta.py +794 -779
- webscout/Provider/mhystical.py +176 -0
- webscout/Provider/perplexitylabs.py +265 -0
- webscout/Provider/twitterclone.py +251 -245
- webscout/Provider/typegpt.py +358 -0
- webscout/__init__.py +9 -8
- webscout/__main__.py +5 -5
- webscout/cli.py +252 -280
- webscout/conversation.py +227 -0
- webscout/exceptions.py +161 -29
- webscout/litagent/__init__.py +172 -0
- webscout/litprinter/__init__.py +832 -0
- webscout/optimizers.py +270 -0
- webscout/prompt_manager.py +279 -0
- webscout/scout/__init__.py +11 -0
- webscout/scout/core.py +884 -0
- webscout/scout/element.py +459 -0
- webscout/scout/parsers/__init__.py +69 -0
- webscout/scout/parsers/html5lib_parser.py +172 -0
- webscout/scout/parsers/html_parser.py +236 -0
- webscout/scout/parsers/lxml_parser.py +178 -0
- webscout/scout/utils.py +38 -0
- webscout/swiftcli/__init__.py +810 -0
- webscout/update_checker.py +125 -0
- webscout/version.py +1 -1
- webscout/zeroart/__init__.py +55 -0
- webscout/zeroart/base.py +61 -0
- webscout/zeroart/effects.py +99 -0
- webscout/zeroart/fonts.py +816 -0
- webscout/zerodir/__init__.py +225 -0
- {webscout-6.3.dist-info → webscout-6.5.dist-info}/METADATA +37 -112
- webscout-6.5.dist-info/RECORD +179 -0
- webscout/Agents/Onlinesearcher.py +0 -182
- webscout/Agents/__init__.py +0 -2
- webscout/Agents/functioncall.py +0 -248
- webscout/Bing_search.py +0 -154
- webscout/Provider/TTI/AIuncensoredimage.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/Provider/TTI/talkai.py +0 -116
- webscout/g4f.py +0 -666
- webscout/models.py +0 -23
- webscout/requestsHTMLfix.py +0 -775
- webscout/webai.py +0 -2590
- webscout-6.3.dist-info/RECORD +0 -124
- {webscout-6.3.dist-info → webscout-6.5.dist-info}/LICENSE.md +0 -0
- {webscout-6.3.dist-info → webscout-6.5.dist-info}/WHEEL +0 -0
- {webscout-6.3.dist-info → webscout-6.5.dist-info}/entry_points.txt +0 -0
- {webscout-6.3.dist-info → webscout-6.5.dist-info}/top_level.txt +0 -0
webscout/Bing_search.py
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
from bs4 import BeautifulSoup
|
|
2
|
-
import requests
|
|
3
|
-
from typing import Dict, List, Optional, Union
|
|
4
|
-
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
5
|
-
from urllib.parse import quote, urlparse, parse_qs
|
|
6
|
-
import base64
|
|
7
|
-
import urllib3
|
|
8
|
-
|
|
9
|
-
# Disable SSL warnings
|
|
10
|
-
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
11
|
-
|
|
12
|
-
class BingS:
|
|
13
|
-
"""Bing search class to get search results from bing.com."""
|
|
14
|
-
|
|
15
|
-
_executor: ThreadPoolExecutor = ThreadPoolExecutor(max_workers=10)
|
|
16
|
-
|
|
17
|
-
def __init__(
|
|
18
|
-
self,
|
|
19
|
-
headers: Optional[Dict[str, str]] = None,
|
|
20
|
-
proxy: Optional[str] = None,
|
|
21
|
-
timeout: Optional[int] = 10,
|
|
22
|
-
) -> None:
|
|
23
|
-
"""Initialize the BingS object."""
|
|
24
|
-
self.proxy: Optional[str] = proxy
|
|
25
|
-
self.headers = headers if headers else {
|
|
26
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
|
27
|
-
}
|
|
28
|
-
self.headers["Referer"] = "https://www.bing.com/"
|
|
29
|
-
self.client = requests.Session()
|
|
30
|
-
self.client.headers.update(self.headers)
|
|
31
|
-
self.client.proxies.update({"http": self.proxy, "https": self.proxy})
|
|
32
|
-
self.timeout = timeout
|
|
33
|
-
|
|
34
|
-
def __enter__(self) -> "BingS":
|
|
35
|
-
return self
|
|
36
|
-
|
|
37
|
-
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
38
|
-
self.client.close()
|
|
39
|
-
|
|
40
|
-
def _get_url(
|
|
41
|
-
self,
|
|
42
|
-
method: str,
|
|
43
|
-
url: str,
|
|
44
|
-
params: Optional[Dict[str, str]] = None,
|
|
45
|
-
data: Optional[Union[Dict[str, str], bytes]] = None,
|
|
46
|
-
) -> bytes:
|
|
47
|
-
try:
|
|
48
|
-
resp = self.client.request(method, url, params=params, data=data, timeout=self.timeout, verify=False)
|
|
49
|
-
except Exception as ex:
|
|
50
|
-
raise Exception(f"{url} {type(ex).__name__}: {ex}") from ex
|
|
51
|
-
if resp.status_code == 200:
|
|
52
|
-
return resp.content
|
|
53
|
-
raise Exception(f"{resp.url} returned status code {resp.status_code}. {params=} {data=}")
|
|
54
|
-
|
|
55
|
-
def extract_text_from_webpage(self, html_content, max_characters=None):
|
|
56
|
-
"""Extracts visible text from HTML content using BeautifulSoup."""
|
|
57
|
-
soup = BeautifulSoup(html_content, "html.parser")
|
|
58
|
-
# Remove unwanted tags
|
|
59
|
-
for tag in soup(["script", "style", "header", "footer", "nav"]):
|
|
60
|
-
tag.extract()
|
|
61
|
-
# Get the remaining visible text
|
|
62
|
-
visible_text = soup.get_text(separator=' ', strip=True)
|
|
63
|
-
if max_characters:
|
|
64
|
-
visible_text = visible_text[:max_characters]
|
|
65
|
-
return visible_text
|
|
66
|
-
|
|
67
|
-
def search(
|
|
68
|
-
self,
|
|
69
|
-
keywords: str,
|
|
70
|
-
max_results: Optional[int] = 10,
|
|
71
|
-
extract_webpage_text: bool = False,
|
|
72
|
-
max_extract_characters: Optional[int] = 100,
|
|
73
|
-
) -> List[Dict[str, str]]:
|
|
74
|
-
"""Bing text search."""
|
|
75
|
-
assert keywords, "keywords is mandatory"
|
|
76
|
-
|
|
77
|
-
results = []
|
|
78
|
-
futures = []
|
|
79
|
-
start = 1
|
|
80
|
-
while len(results) < max_results:
|
|
81
|
-
params = {
|
|
82
|
-
"q": keywords,
|
|
83
|
-
"first": start
|
|
84
|
-
}
|
|
85
|
-
futures.append(self._executor.submit(self._get_url, "GET", "https://www.bing.com/search", params=params))
|
|
86
|
-
start += 10
|
|
87
|
-
|
|
88
|
-
for future in as_completed(futures):
|
|
89
|
-
try:
|
|
90
|
-
resp_content = future.result()
|
|
91
|
-
soup = BeautifulSoup(resp_content, "html.parser")
|
|
92
|
-
result_block = soup.select('li.b_algo')
|
|
93
|
-
|
|
94
|
-
if not result_block:
|
|
95
|
-
break
|
|
96
|
-
|
|
97
|
-
for result in result_block:
|
|
98
|
-
try:
|
|
99
|
-
link = result.select_one('h2 a')
|
|
100
|
-
title = link.text if link else ""
|
|
101
|
-
url = link['href'] if link else ""
|
|
102
|
-
abstract = result.select_one('.b_caption p')
|
|
103
|
-
description = abstract.text if abstract else ""
|
|
104
|
-
|
|
105
|
-
# Remove "WEB" from the beginning of the description if it exists
|
|
106
|
-
if description.startswith("WEB"):
|
|
107
|
-
description = description[3:].strip()
|
|
108
|
-
|
|
109
|
-
visible_text = ""
|
|
110
|
-
if extract_webpage_text:
|
|
111
|
-
try:
|
|
112
|
-
actual_url = self._decode_bing_url(url)
|
|
113
|
-
page_content = self._get_url("GET", actual_url)
|
|
114
|
-
visible_text = self.extract_text_from_webpage(
|
|
115
|
-
page_content, max_characters=max_extract_characters
|
|
116
|
-
)
|
|
117
|
-
except Exception as e:
|
|
118
|
-
print(f"Error extracting text from {url}: {e}")
|
|
119
|
-
|
|
120
|
-
results.append({
|
|
121
|
-
"title": title,
|
|
122
|
-
"href": url,
|
|
123
|
-
"abstract": description,
|
|
124
|
-
"index": len(results),
|
|
125
|
-
"type": "web",
|
|
126
|
-
"visible_text": visible_text,
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
if len(results) >= max_results:
|
|
130
|
-
return results
|
|
131
|
-
|
|
132
|
-
except Exception as e:
|
|
133
|
-
print(f"Error extracting result: {e}")
|
|
134
|
-
|
|
135
|
-
except Exception as e:
|
|
136
|
-
print(f"Error fetching URL: {e}")
|
|
137
|
-
|
|
138
|
-
return results
|
|
139
|
-
|
|
140
|
-
def _decode_bing_url(self, url):
|
|
141
|
-
if 'bing.com/ck/a' in url:
|
|
142
|
-
parsed_url = urlparse(url)
|
|
143
|
-
query_params = parse_qs(parsed_url.query)
|
|
144
|
-
if 'u' in query_params:
|
|
145
|
-
encoded_url = query_params['u'][0]
|
|
146
|
-
return base64.b64decode(encoded_url).decode('utf-8')
|
|
147
|
-
return url
|
|
148
|
-
|
|
149
|
-
if __name__ == "__main__":
|
|
150
|
-
from rich import print
|
|
151
|
-
searcher = BingS()
|
|
152
|
-
results = searcher.search("Python development tools", max_results=5, extract_webpage_text=True, max_extract_characters=2000)
|
|
153
|
-
for result in results:
|
|
154
|
-
print(result)
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
import json
|
|
3
|
-
import os
|
|
4
|
-
from datetime import datetime
|
|
5
|
-
from typing import List, Dict, Optional
|
|
6
|
-
|
|
7
|
-
from webscout.AIbase import ImageProvider
|
|
8
|
-
from webscout import exceptions
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class AIUncensoredImager(ImageProvider):
|
|
12
|
-
"""
|
|
13
|
-
Image provider for AIUncensored.info.
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
def __init__(self, timeout: int = 60, proxies: dict = {}):
|
|
17
|
-
"""Initializes the AIUncensoredImager class."""
|
|
18
|
-
self.url = "https://twitterclone-i0wr.onrender.com/api/image"
|
|
19
|
-
self.headers = {
|
|
20
|
-
"Content-Type": "application/json",
|
|
21
|
-
"Accept": "*/*",
|
|
22
|
-
"Origin": "https://www.aiuncensored.info",
|
|
23
|
-
"Referer": "https://www.aiuncensored.info/",
|
|
24
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0",
|
|
25
|
-
}
|
|
26
|
-
self.session = requests.Session()
|
|
27
|
-
self.session.headers.update(self.headers)
|
|
28
|
-
self.session.proxies.update(proxies)
|
|
29
|
-
self.timeout = timeout
|
|
30
|
-
self.prompt = "AI-generated image - webscout"
|
|
31
|
-
self.image_extension = "jpg"
|
|
32
|
-
|
|
33
|
-
def generate(self, prompt: str, amount: int = 1) -> List[str]:
|
|
34
|
-
"""Generates image URLs from a prompt."""
|
|
35
|
-
|
|
36
|
-
assert bool(prompt), "Prompt cannot be null"
|
|
37
|
-
assert isinstance(amount, int) and amount > 0, "Amount must be a positive integer"
|
|
38
|
-
self.prompt = prompt
|
|
39
|
-
|
|
40
|
-
payload = {"prompt": prompt}
|
|
41
|
-
image_urls = []
|
|
42
|
-
|
|
43
|
-
try:
|
|
44
|
-
with self.session.post(self.url, json=payload, timeout=self.timeout) as response:
|
|
45
|
-
response.raise_for_status() # Raise HTTPError for bad responses
|
|
46
|
-
data = response.json()
|
|
47
|
-
image_url = data.get("image_url")
|
|
48
|
-
|
|
49
|
-
if not image_url:
|
|
50
|
-
raise exceptions.InvalidResponseError("No image URL in API response")
|
|
51
|
-
|
|
52
|
-
image_urls.append(image_url) # Only one image returned for now
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
except requests.exceptions.RequestException as e:
|
|
56
|
-
raise exceptions.APIConnectionError(f"Error during request: {e}")
|
|
57
|
-
except json.JSONDecodeError as e:
|
|
58
|
-
raise exceptions.InvalidResponseError(f"Invalid JSON response: {e}")
|
|
59
|
-
except Exception as e:
|
|
60
|
-
raise exceptions.FailedToGenerateResponseError(f"Unexpected error: {e}")
|
|
61
|
-
|
|
62
|
-
return image_urls
|
|
63
|
-
|
|
64
|
-
def save(
|
|
65
|
-
self,
|
|
66
|
-
response: List[str],
|
|
67
|
-
name: str = None,
|
|
68
|
-
dir: str = os.getcwd(),
|
|
69
|
-
filenames_prefix: str = "",
|
|
70
|
-
) -> List[str]:
|
|
71
|
-
"""Saves generated images."""
|
|
72
|
-
|
|
73
|
-
assert isinstance(response, list), f"Response should be a list, not {type(response)}"
|
|
74
|
-
name = self.prompt if name is None else name
|
|
75
|
-
os.makedirs(dir, exist_ok=True) #Create dir if needed
|
|
76
|
-
|
|
77
|
-
filenames = []
|
|
78
|
-
for i, img_url in enumerate(response):
|
|
79
|
-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
80
|
-
filename = f"{dir}/{name}_{i + 1}_{timestamp}.{self.image_extension}"
|
|
81
|
-
filenames.append(filenames_prefix + os.path.basename(filename))
|
|
82
|
-
|
|
83
|
-
try:
|
|
84
|
-
with self.session.get(img_url, stream=True, timeout=self.timeout) as img_response:
|
|
85
|
-
img_response.raise_for_status()
|
|
86
|
-
with open(filename, "wb") as f:
|
|
87
|
-
for chunk in img_response.iter_content(chunk_size=8192):
|
|
88
|
-
f.write(chunk)
|
|
89
|
-
except requests.exceptions.RequestException as e:
|
|
90
|
-
raise exceptions.FailedToSaveImageError(f"Error downloading/saving image: {e}")
|
|
91
|
-
|
|
92
|
-
return filenames
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if __name__ == "__main__":
|
|
96
|
-
imager = AIUncensoredImager()
|
|
97
|
-
prompt = "a photo of a cat sitting in a basket"
|
|
98
|
-
try:
|
|
99
|
-
image_urls = imager.generate(prompt, amount=1)
|
|
100
|
-
saved_filenames = imager.save(image_urls)
|
|
101
|
-
print(f"Saved filenames: {saved_filenames}")
|
|
102
|
-
except Exception as e:
|
|
103
|
-
print(f"An error occurred: {e}")
|
webscout/Provider/TTI/Nexra.py
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
import json
|
|
3
|
-
import os
|
|
4
|
-
import time
|
|
5
|
-
from typing import List, Optional
|
|
6
|
-
from requests.exceptions import RequestException
|
|
7
|
-
|
|
8
|
-
from webscout.AIbase import ImageProvider
|
|
9
|
-
|
|
10
|
-
class NexraImager(ImageProvider):
|
|
11
|
-
"""Image provider for Nexra API"""
|
|
12
|
-
|
|
13
|
-
AVAILABLE_MODELS = {
|
|
14
|
-
"standard": ["emi", "stablediffusion-1.5", "stablediffusion-2.1", "sdxl-lora", "dalle", "dalle2", "dalle-mini", "flux", "midjourney"],
|
|
15
|
-
"prodia": [
|
|
16
|
-
"dreamshaperXL10_alpha2.safetensors [c8afe2ef]",
|
|
17
|
-
"dynavisionXL_0411.safetensors [c39cc051]",
|
|
18
|
-
"juggernautXL_v45.safetensors [e75f5471]",
|
|
19
|
-
"realismEngineSDXL_v10.safetensors [af771c3f]",
|
|
20
|
-
"sd_xl_base_1.0.safetensors [be9edd61]",
|
|
21
|
-
"animagineXLV3_v30.safetensors [75f2f05b]",
|
|
22
|
-
"sd_xl_base_1.0_inpainting_0.1.safetensors [5679a81a]",
|
|
23
|
-
"turbovisionXL_v431.safetensors [78890989]",
|
|
24
|
-
"devlishphotorealism_sdxl15.safetensors [77cba69f]",
|
|
25
|
-
"realvisxlV40.safetensors [f7fdcb51]"
|
|
26
|
-
]
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
def __init__(self, timeout: int = 60, proxies: dict = {}):
|
|
30
|
-
self.url = "https://nexra.aryahcr.cc/api/image/complements"
|
|
31
|
-
self.headers = {"Content-Type": "application/json"}
|
|
32
|
-
self.session = requests.Session()
|
|
33
|
-
self.session.headers.update(self.headers)
|
|
34
|
-
self.session.proxies.update(proxies)
|
|
35
|
-
self.timeout = timeout
|
|
36
|
-
self.prompt: str = "AI-generated image - webscout"
|
|
37
|
-
self.image_extension: str = "png"
|
|
38
|
-
|
|
39
|
-
def generate(
|
|
40
|
-
self, prompt: str, model: str = "flux", amount: int = 1,
|
|
41
|
-
max_retries: int = 3, retry_delay: int = 5,
|
|
42
|
-
additional_params: Optional[dict] = None
|
|
43
|
-
) -> List[bytes]:
|
|
44
|
-
assert bool(prompt), "Prompt cannot be null"
|
|
45
|
-
assert isinstance(amount, int) and amount > 0, "Amount should be a positive integer"
|
|
46
|
-
|
|
47
|
-
self.prompt = prompt
|
|
48
|
-
response = []
|
|
49
|
-
|
|
50
|
-
payload = {
|
|
51
|
-
"prompt": prompt,
|
|
52
|
-
"model": "prodia" if model in self.AVAILABLE_MODELS["prodia"] else model,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if model in self.AVAILABLE_MODELS["prodia"]:
|
|
56
|
-
payload["data"] = {
|
|
57
|
-
"model": model,
|
|
58
|
-
"steps": 25,
|
|
59
|
-
"cfg_scale": 7,
|
|
60
|
-
"sampler": "DPM++ 2M Karras",
|
|
61
|
-
"negative_prompt": ""
|
|
62
|
-
}
|
|
63
|
-
if additional_params:
|
|
64
|
-
payload.update(additional_params)
|
|
65
|
-
|
|
66
|
-
for _ in range(max_retries):
|
|
67
|
-
try:
|
|
68
|
-
resp = self.session.post(self.url, json=payload, timeout=self.timeout)
|
|
69
|
-
resp.raise_for_status()
|
|
70
|
-
|
|
71
|
-
# Remove leading underscores and then parse JSON
|
|
72
|
-
response_data = json.loads(resp.text.lstrip("_"))
|
|
73
|
-
|
|
74
|
-
if response_data.get("status") and "images" in response_data:
|
|
75
|
-
for image_url in response_data["images"]:
|
|
76
|
-
img_resp = requests.get(image_url)
|
|
77
|
-
img_resp.raise_for_status()
|
|
78
|
-
response.append(img_resp.content)
|
|
79
|
-
break
|
|
80
|
-
else:
|
|
81
|
-
raise Exception("Failed to generate image: " + str(response_data))
|
|
82
|
-
except json.JSONDecodeError as json_err:
|
|
83
|
-
print(f"JSON Decode Error: {json_err}")
|
|
84
|
-
print(f"Raw response: {resp.text}")
|
|
85
|
-
if _ == max_retries - 1:
|
|
86
|
-
raise
|
|
87
|
-
except RequestException as e:
|
|
88
|
-
print(f"Request Exception: {e}")
|
|
89
|
-
if _ == max_retries - 1:
|
|
90
|
-
raise
|
|
91
|
-
print(f"Retrying in {retry_delay} seconds...")
|
|
92
|
-
time.sleep(retry_delay)
|
|
93
|
-
|
|
94
|
-
return response
|
|
95
|
-
|
|
96
|
-
def save(
|
|
97
|
-
self,
|
|
98
|
-
response: List[bytes],
|
|
99
|
-
name: str = None,
|
|
100
|
-
dir: str = os.getcwd(),
|
|
101
|
-
filenames_prefix: str = "",
|
|
102
|
-
) -> List[str]:
|
|
103
|
-
assert isinstance(response, list), f"Response should be a list, not {type(response)}"
|
|
104
|
-
name = self.prompt if name is None else name
|
|
105
|
-
|
|
106
|
-
filenames = []
|
|
107
|
-
for i, image in enumerate(response):
|
|
108
|
-
filename = f"{filenames_prefix}{name}_{i}.{self.image_extension}"
|
|
109
|
-
filepath = os.path.join(dir, filename)
|
|
110
|
-
|
|
111
|
-
with open(filepath, "wb") as fh:
|
|
112
|
-
fh.write(image)
|
|
113
|
-
filenames.append(filename)
|
|
114
|
-
|
|
115
|
-
return filenames
|
|
116
|
-
|
|
117
|
-
if __name__ == "__main__":
|
|
118
|
-
bot = NexraImager()
|
|
119
|
-
resp_standard = bot.generate("AI-generated image - webscout", "midjourney", 1)
|
|
120
|
-
print(bot.save(resp_standard))
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
import os
|
|
3
|
-
import time
|
|
4
|
-
from typing import List
|
|
5
|
-
from string import punctuation
|
|
6
|
-
from random import choice
|
|
7
|
-
from requests.exceptions import RequestException
|
|
8
|
-
|
|
9
|
-
from webscout.AIbase import ImageProvider
|
|
10
|
-
|
|
11
|
-
class PollinationsAI(ImageProvider):
|
|
12
|
-
"""Image provider for pollinations.ai"""
|
|
13
|
-
|
|
14
|
-
def __init__(self, timeout: int = 60, proxies: dict = {}):
|
|
15
|
-
"""Initializes the PollinationsAI class.
|
|
16
|
-
|
|
17
|
-
Args:
|
|
18
|
-
timeout (int, optional): HTTP request timeout in seconds. Defaults to 60.
|
|
19
|
-
proxies (dict, optional): HTTP request proxies (socks). Defaults to {}.
|
|
20
|
-
"""
|
|
21
|
-
self.image_gen_endpoint = "https://image.pollinations.ai/prompt/{prompt}?width={width}&height={height}&model={model}"
|
|
22
|
-
self.headers = {
|
|
23
|
-
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
|
24
|
-
"Accept-Language": "en-US,en;q=0.5",
|
|
25
|
-
"Accept-Encoding": "gzip, deflate",
|
|
26
|
-
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0",
|
|
27
|
-
}
|
|
28
|
-
self.session = requests.Session()
|
|
29
|
-
self.session.headers.update(self.headers)
|
|
30
|
-
self.session.proxies.update(proxies)
|
|
31
|
-
self.timeout = timeout
|
|
32
|
-
self.prompt: str = "AI-generated image - webscout"
|
|
33
|
-
self.image_extension: str = "jpeg"
|
|
34
|
-
|
|
35
|
-
def generate(
|
|
36
|
-
self, prompt: str, amount: int = 1, additives: bool = True,
|
|
37
|
-
width: int = 768, height: int = 768, model: str = "flux",
|
|
38
|
-
max_retries: int = 3, retry_delay: int = 5
|
|
39
|
-
) -> List[bytes]:
|
|
40
|
-
"""Generate image from prompt
|
|
41
|
-
|
|
42
|
-
Args:
|
|
43
|
-
prompt (str): Image description.
|
|
44
|
-
amount (int): Total images to be generated. Defaults to 1.
|
|
45
|
-
additives (bool, optional): Try to make each prompt unique. Defaults to True.
|
|
46
|
-
width (int, optional): Width of the generated image. Defaults to 768.
|
|
47
|
-
height (int, optional): Height of the generated image. Defaults to 768.
|
|
48
|
-
model (str, optional): The model to use for image generation. Defaults to "flux".
|
|
49
|
-
max_retries (int, optional): Maximum number of retry attempts. Defaults to 3.
|
|
50
|
-
retry_delay (int, optional): Delay between retries in seconds. Defaults to 5.
|
|
51
|
-
|
|
52
|
-
Returns:
|
|
53
|
-
List[bytes]: List of generated images as bytes.
|
|
54
|
-
"""
|
|
55
|
-
assert bool(prompt), "Prompt cannot be null"
|
|
56
|
-
assert isinstance(amount, int), f"Amount should be an integer only not {type(amount)}"
|
|
57
|
-
assert amount > 0, "Amount should be greater than 0"
|
|
58
|
-
|
|
59
|
-
ads = lambda: (
|
|
60
|
-
""
|
|
61
|
-
if not additives
|
|
62
|
-
else choice(punctuation)
|
|
63
|
-
+ choice(punctuation)
|
|
64
|
-
+ choice(punctuation)
|
|
65
|
-
+ choice(punctuation)
|
|
66
|
-
+ choice(punctuation)
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
self.prompt = prompt
|
|
70
|
-
response = []
|
|
71
|
-
for _ in range(amount):
|
|
72
|
-
url = self.image_gen_endpoint.format(
|
|
73
|
-
prompt=prompt + ads(), width=width, height=height, model=model
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
for attempt in range(max_retries):
|
|
77
|
-
try:
|
|
78
|
-
resp = self.session.get(url, timeout=self.timeout)
|
|
79
|
-
resp.raise_for_status()
|
|
80
|
-
response.append(resp.content)
|
|
81
|
-
break
|
|
82
|
-
except RequestException as e:
|
|
83
|
-
if attempt == max_retries - 1:
|
|
84
|
-
print(f"Failed to generate image after {max_retries} attempts: {e}")
|
|
85
|
-
raise
|
|
86
|
-
else:
|
|
87
|
-
print(f"Attempt {attempt + 1} failed. Retrying in {retry_delay} seconds...")
|
|
88
|
-
time.sleep(retry_delay)
|
|
89
|
-
|
|
90
|
-
return response
|
|
91
|
-
|
|
92
|
-
def save(
|
|
93
|
-
self,
|
|
94
|
-
response: List[bytes],
|
|
95
|
-
name: str = None,
|
|
96
|
-
dir: str = os.getcwd(),
|
|
97
|
-
filenames_prefix: str = "",
|
|
98
|
-
) -> List[str]:
|
|
99
|
-
"""Save generated images
|
|
100
|
-
|
|
101
|
-
Args:
|
|
102
|
-
response (List[bytes]): List of generated images as bytes.
|
|
103
|
-
name (str): Filename for the images. Defaults to the last prompt.
|
|
104
|
-
dir (str, optional): Directory for saving images. Defaults to os.getcwd().
|
|
105
|
-
filenames_prefix (str, optional): String to be prefixed at each filename to be returned.
|
|
106
|
-
|
|
107
|
-
Returns:
|
|
108
|
-
List[str]: List of saved filenames.
|
|
109
|
-
"""
|
|
110
|
-
assert isinstance(response, list), f"Response should be of {list} not {type(response)}"
|
|
111
|
-
name = self.prompt if name is None else name
|
|
112
|
-
|
|
113
|
-
filenames = []
|
|
114
|
-
count = 0
|
|
115
|
-
for image in response:
|
|
116
|
-
def complete_path():
|
|
117
|
-
count_value = "" if count == 0 else f"_{count}"
|
|
118
|
-
return os.path.join(dir, name + count_value + "." + self.image_extension)
|
|
119
|
-
|
|
120
|
-
while os.path.isfile(complete_path()):
|
|
121
|
-
count += 1
|
|
122
|
-
|
|
123
|
-
absolute_path_to_file = complete_path()
|
|
124
|
-
filenames.append(filenames_prefix + os.path.split(absolute_path_to_file)[1])
|
|
125
|
-
|
|
126
|
-
with open(absolute_path_to_file, "wb") as fh:
|
|
127
|
-
fh.write(image)
|
|
128
|
-
|
|
129
|
-
return filenames
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if __name__ == "__main__":
|
|
133
|
-
bot = PollinationsAI()
|
|
134
|
-
try:
|
|
135
|
-
resp = bot.generate("AI-generated image - webscout", 1)
|
|
136
|
-
print(bot.save(resp))
|
|
137
|
-
except Exception as e:
|
|
138
|
-
print(f"An error occurred: {e}")
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
import os
|
|
3
|
-
from typing import List
|
|
4
|
-
|
|
5
|
-
from webscout.AIbase import ImageProvider
|
|
6
|
-
|
|
7
|
-
class WebSimAI(ImageProvider):
|
|
8
|
-
"""
|
|
9
|
-
Image provider for WebSim.ai.
|
|
10
|
-
"""
|
|
11
|
-
|
|
12
|
-
def __init__(self, timeout: int = 60, proxies: dict = {}):
|
|
13
|
-
"""Initializes the WebSimAI class.
|
|
14
|
-
|
|
15
|
-
Args:
|
|
16
|
-
timeout (int, optional): HTTP request timeout in seconds. Defaults to 60.
|
|
17
|
-
proxies (dict, optional): HTTP request proxies (socks). Defaults to {}.
|
|
18
|
-
"""
|
|
19
|
-
self.url = "https://websim.ai/api/image_gen"
|
|
20
|
-
self.headers = {
|
|
21
|
-
"Accept": "*/*",
|
|
22
|
-
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
23
|
-
"Accept-Language": "en-US,en;q=0.9,en-IN;q=0.8",
|
|
24
|
-
"Content-Type": "application/json",
|
|
25
|
-
"User-Agent": (
|
|
26
|
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
|
27
|
-
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
|
28
|
-
"Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0"
|
|
29
|
-
),
|
|
30
|
-
"Origin": "https://websim.ai",
|
|
31
|
-
"Referer": "https://websim.ai/p/a5yvwmtj8qz6ayx4tlg1"
|
|
32
|
-
}
|
|
33
|
-
self.session = requests.Session()
|
|
34
|
-
self.session.headers.update(self.headers)
|
|
35
|
-
self.session.proxies.update(proxies)
|
|
36
|
-
self.timeout = timeout
|
|
37
|
-
self.prompt: str = "AI-generated image - Webscout"
|
|
38
|
-
self.image_extension: str = "png"
|
|
39
|
-
|
|
40
|
-
def generate(
|
|
41
|
-
self,
|
|
42
|
-
prompt: str,
|
|
43
|
-
amount: int = 1,
|
|
44
|
-
width: int = 1024,
|
|
45
|
-
height: int = 756
|
|
46
|
-
) -> List[bytes]:
|
|
47
|
-
"""Generate image from prompt
|
|
48
|
-
|
|
49
|
-
Args:
|
|
50
|
-
prompt (str): Image description.
|
|
51
|
-
amount (int, optional): Total images to be generated. Defaults to 1.
|
|
52
|
-
width (int, optional): Width of the generated image. Defaults to 1024.
|
|
53
|
-
height (int, optional): Height of the generated image. Defaults to 756.
|
|
54
|
-
|
|
55
|
-
Returns:
|
|
56
|
-
List[bytes]: List of generated images as bytes.
|
|
57
|
-
"""
|
|
58
|
-
assert bool(prompt), "Prompt cannot be null"
|
|
59
|
-
assert isinstance(amount, int), f"Amount should be an integer only, not {type(amount)}"
|
|
60
|
-
assert amount > 0, "Amount should be greater than 0"
|
|
61
|
-
|
|
62
|
-
self.prompt = prompt
|
|
63
|
-
response = []
|
|
64
|
-
|
|
65
|
-
for _ in range(amount):
|
|
66
|
-
payload = {
|
|
67
|
-
"prompt": prompt,
|
|
68
|
-
"width": width,
|
|
69
|
-
"height": height,
|
|
70
|
-
"site_id": "KcWvHOHNBP2PmWUYZ",
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
try:
|
|
74
|
-
resp = self.session.post(self.url, headers=self.headers, json=payload, timeout=self.timeout)
|
|
75
|
-
resp.raise_for_status() # Raises HTTPError for bad responses
|
|
76
|
-
|
|
77
|
-
response_data = resp.json()
|
|
78
|
-
image_url = response_data.get("url")
|
|
79
|
-
if not image_url:
|
|
80
|
-
print("No image URL found in the response.")
|
|
81
|
-
continue
|
|
82
|
-
|
|
83
|
-
image_response = requests.get(image_url)
|
|
84
|
-
image_response.raise_for_status()
|
|
85
|
-
response.append(image_response.content)
|
|
86
|
-
|
|
87
|
-
except requests.exceptions.HTTPError as http_err:
|
|
88
|
-
print(f"HTTP error occurred: {http_err} - {response.text}")
|
|
89
|
-
return [] # Return an empty list on error
|
|
90
|
-
except requests.exceptions.RequestException as req_err:
|
|
91
|
-
print(f"Request error occurred: {req_err}")
|
|
92
|
-
return [] # Return an empty list on error
|
|
93
|
-
|
|
94
|
-
return response
|
|
95
|
-
|
|
96
|
-
def save(
|
|
97
|
-
self,
|
|
98
|
-
response: List[bytes],
|
|
99
|
-
name: str = None,
|
|
100
|
-
dir: str = os.getcwd(),
|
|
101
|
-
filenames_prefix: str = "",
|
|
102
|
-
) -> List[str]:
|
|
103
|
-
"""Save generated images
|
|
104
|
-
|
|
105
|
-
Args:
|
|
106
|
-
response (List[bytes]): List of generated images as bytes.
|
|
107
|
-
name (str): Filename for the images. Defaults to the last prompt.
|
|
108
|
-
dir (str, optional): Directory for saving images. Defaults to os.getcwd().
|
|
109
|
-
filenames_prefix (str, optional): String to be prefixed at each filename to be returned.
|
|
110
|
-
|
|
111
|
-
Returns:
|
|
112
|
-
List[str]: List of saved filenames.
|
|
113
|
-
"""
|
|
114
|
-
assert isinstance(response, list), f"Response should be of {list} not {type(response)}"
|
|
115
|
-
name = self.prompt if name is None else name
|
|
116
|
-
|
|
117
|
-
filenames = []
|
|
118
|
-
count = 0
|
|
119
|
-
for image in response:
|
|
120
|
-
def complete_path():
|
|
121
|
-
count_value = "" if count == 0 else f"_{count}"
|
|
122
|
-
return os.path.join(dir, name + count_value + "." + self.image_extension)
|
|
123
|
-
|
|
124
|
-
while os.path.isfile(complete_path()):
|
|
125
|
-
count += 1
|
|
126
|
-
|
|
127
|
-
absolute_path_to_file = complete_path()
|
|
128
|
-
filenames.append(filenames_prefix + os.path.split(absolute_path_to_file)[1])
|
|
129
|
-
|
|
130
|
-
with open(absolute_path_to_file, "wb") as fh:
|
|
131
|
-
fh.write(image)
|
|
132
|
-
|
|
133
|
-
return filenames
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if __name__ == "__main__":
|
|
137
|
-
bot = WebSimAI()
|
|
138
|
-
try:
|
|
139
|
-
resp = bot.generate("A shiny red sports car speeding down a scenic mountain road", 1)
|
|
140
|
-
print(bot.save(resp))
|
|
141
|
-
except Exception as e:
|
|
142
|
-
print(f"An error occurred: {e}")
|