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/Provider/TTI/aiforce.py
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
import os
|
|
3
|
-
import time
|
|
4
|
-
from typing import List, Optional
|
|
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 AiForceimager(ImageProvider):
|
|
12
|
-
"""Image provider for Airforce API"""
|
|
13
|
-
|
|
14
|
-
AVAILABLE_MODELS = [
|
|
15
|
-
"flux",
|
|
16
|
-
"flux-realism",
|
|
17
|
-
"flux-anime",
|
|
18
|
-
"flux-3d",
|
|
19
|
-
"flux-disney",
|
|
20
|
-
"flux-pixel",
|
|
21
|
-
"flux-4o",
|
|
22
|
-
"any-dark"
|
|
23
|
-
]
|
|
24
|
-
|
|
25
|
-
def __init__(self, timeout: int = 60, proxies: dict = {}):
|
|
26
|
-
"""Initializes the AiForceimagger class.
|
|
27
|
-
|
|
28
|
-
Args:
|
|
29
|
-
api_token (str, optional): Your Airforce API token. If None, it will use the environment variable "AIRFORCE_API_TOKEN".
|
|
30
|
-
Defaults to None.
|
|
31
|
-
timeout (int, optional): HTTP request timeout in seconds. Defaults to 60.
|
|
32
|
-
proxies (dict, optional): HTTP request proxies (socks). Defaults to {}.
|
|
33
|
-
"""
|
|
34
|
-
self.api_endpoint = "https://api.airforce/imagine2"
|
|
35
|
-
self.headers = {
|
|
36
|
-
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
|
37
|
-
"Accept-Language": "en-US,en;q=0.5",
|
|
38
|
-
"Accept-Encoding": "gzip, deflate",
|
|
39
|
-
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0",
|
|
40
|
-
}
|
|
41
|
-
self.session = requests.Session()
|
|
42
|
-
self.session.headers.update(self.headers)
|
|
43
|
-
self.session.proxies.update(proxies)
|
|
44
|
-
self.timeout = timeout
|
|
45
|
-
self.prompt: str = "AI-generated image - webscout"
|
|
46
|
-
self.image_extension: str = "png"
|
|
47
|
-
|
|
48
|
-
def generate(
|
|
49
|
-
self,
|
|
50
|
-
prompt: str,
|
|
51
|
-
amount: int = 1,
|
|
52
|
-
additives: bool = True,
|
|
53
|
-
model: str = "flux-realism",
|
|
54
|
-
width: int = 768,
|
|
55
|
-
height: int = 768,
|
|
56
|
-
seed: Optional[int] = None,
|
|
57
|
-
max_retries: int = 3,
|
|
58
|
-
retry_delay: int = 5
|
|
59
|
-
) -> List[bytes]:
|
|
60
|
-
"""Generate image from prompt
|
|
61
|
-
|
|
62
|
-
Args:
|
|
63
|
-
prompt (str): Image description.
|
|
64
|
-
amount (int, optional): Total images to be generated. Defaults to 1.
|
|
65
|
-
additives (bool, optional): Try to make each prompt unique. Defaults to True.
|
|
66
|
-
model (str, optional): The model to use for image generation.
|
|
67
|
-
Defaults to "flux". Available options: "flux", "flux-realism".
|
|
68
|
-
width (int, optional): Width of the generated image. Defaults to 768.
|
|
69
|
-
height (int, optional): Height of the generated image. Defaults to 768.
|
|
70
|
-
seed (int, optional): Seed for the random number generator. Defaults to None.
|
|
71
|
-
max_retries (int, optional): Maximum number of retry attempts. Defaults to 3.
|
|
72
|
-
retry_delay (int, optional): Delay between retries in seconds. Defaults to 5.
|
|
73
|
-
|
|
74
|
-
Returns:
|
|
75
|
-
List[bytes]: List of generated images as bytes.
|
|
76
|
-
"""
|
|
77
|
-
assert bool(prompt), "Prompt cannot be null"
|
|
78
|
-
assert isinstance(amount, int), f"Amount should be an integer only not {type(amount)}"
|
|
79
|
-
assert amount > 0, "Amount should be greater than 0"
|
|
80
|
-
assert model in self.AVAILABLE_MODELS, f"Model should be one of {self.AVAILABLE_MODELS}"
|
|
81
|
-
|
|
82
|
-
ads = lambda: (
|
|
83
|
-
""
|
|
84
|
-
if not additives
|
|
85
|
-
else choice(punctuation)
|
|
86
|
-
+ choice(punctuation)
|
|
87
|
-
+ choice(punctuation)
|
|
88
|
-
+ choice(punctuation)
|
|
89
|
-
+ choice(punctuation)
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
self.prompt = prompt
|
|
93
|
-
response = []
|
|
94
|
-
for _ in range(amount):
|
|
95
|
-
url = f"{self.api_endpoint}?model={model}&prompt={prompt}&size={width}:{height}"
|
|
96
|
-
if seed:
|
|
97
|
-
url += f"&seed={seed}"
|
|
98
|
-
|
|
99
|
-
for attempt in range(max_retries):
|
|
100
|
-
try:
|
|
101
|
-
resp = self.session.get(url, timeout=self.timeout)
|
|
102
|
-
resp.raise_for_status()
|
|
103
|
-
response.append(resp.content)
|
|
104
|
-
break
|
|
105
|
-
except RequestException as e:
|
|
106
|
-
if attempt == max_retries - 1:
|
|
107
|
-
print(f"Failed to generate image after {max_retries} attempts: {e}")
|
|
108
|
-
raise
|
|
109
|
-
else:
|
|
110
|
-
print(f"Attempt {attempt + 1} failed. Retrying in {retry_delay} seconds...")
|
|
111
|
-
time.sleep(retry_delay)
|
|
112
|
-
|
|
113
|
-
return response
|
|
114
|
-
|
|
115
|
-
def save(
|
|
116
|
-
self,
|
|
117
|
-
response: List[bytes],
|
|
118
|
-
name: str = None,
|
|
119
|
-
dir: str = os.getcwd(),
|
|
120
|
-
filenames_prefix: str = "",
|
|
121
|
-
) -> List[str]:
|
|
122
|
-
"""Save generated images
|
|
123
|
-
|
|
124
|
-
Args:
|
|
125
|
-
response (List[bytes]): List of generated images as bytes.
|
|
126
|
-
name (str): Filename for the images. Defaults to the last prompt.
|
|
127
|
-
dir (str, optional): Directory for saving images. Defaults to os.getcwd().
|
|
128
|
-
filenames_prefix (str, optional): String to be prefixed at each filename to be returned.
|
|
129
|
-
|
|
130
|
-
Returns:
|
|
131
|
-
List[str]: List of saved filenames.
|
|
132
|
-
"""
|
|
133
|
-
assert isinstance(response, list), f"Response should be of {list} not {type(response)}"
|
|
134
|
-
name = self.prompt if name is None else name
|
|
135
|
-
|
|
136
|
-
filenames = []
|
|
137
|
-
count = 0
|
|
138
|
-
for image in response:
|
|
139
|
-
def complete_path():
|
|
140
|
-
count_value = "" if count == 0 else f"_{count}"
|
|
141
|
-
return os.path.join(dir, name + count_value + "." + self.image_extension)
|
|
142
|
-
|
|
143
|
-
while os.path.isfile(complete_path()):
|
|
144
|
-
count += 1
|
|
145
|
-
|
|
146
|
-
absolute_path_to_file = complete_path()
|
|
147
|
-
filenames.append(filenames_prefix + os.path.split(absolute_path_to_file)[1])
|
|
148
|
-
|
|
149
|
-
with open(absolute_path_to_file, "wb") as fh:
|
|
150
|
-
fh.write(image)
|
|
151
|
-
|
|
152
|
-
return filenames
|
|
153
|
-
|
|
154
|
-
if __name__ == "__main__":
|
|
155
|
-
bot = AiForceimager()
|
|
156
|
-
try:
|
|
157
|
-
resp = bot.generate("A shiny red sports car speeding down a scenic mountain road", 1, model="flux-realism")
|
|
158
|
-
print(bot.save(resp))
|
|
159
|
-
except Exception as e:
|
|
160
|
-
print(f"An error occurred: {e}")
|
webscout/Provider/TTI/artbit.py
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import cloudscraper
|
|
2
|
-
import os
|
|
3
|
-
import requests
|
|
4
|
-
|
|
5
|
-
from typing import List
|
|
6
|
-
|
|
7
|
-
from webscout.AIbase import ImageProvider
|
|
8
|
-
|
|
9
|
-
class ArtbitImager(ImageProvider):
|
|
10
|
-
"""
|
|
11
|
-
Image provider for Artbit.ai.
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
def __init__(self, timeout: int = 60, proxies: dict = {}):
|
|
15
|
-
"""Initializes the ArtbitImager class.
|
|
16
|
-
|
|
17
|
-
Args:
|
|
18
|
-
timeout (int, optional): HTTP request timeout in seconds. Defaults to 60.
|
|
19
|
-
proxies (dict, optional): HTTP request proxies. Defaults to {}.
|
|
20
|
-
"""
|
|
21
|
-
self.url = "https://artbit.ai/api/generateImage"
|
|
22
|
-
self.scraper = cloudscraper.create_scraper()
|
|
23
|
-
self.scraper.proxies.update(proxies)
|
|
24
|
-
self.timeout = timeout
|
|
25
|
-
self.prompt: str = "AI-generated image - webscout"
|
|
26
|
-
self.image_extension: str = "png"
|
|
27
|
-
|
|
28
|
-
def generate(
|
|
29
|
-
self,
|
|
30
|
-
prompt: str,
|
|
31
|
-
amount: int = 1,
|
|
32
|
-
caption_model: str = "sdxl",
|
|
33
|
-
selected_ratio: str = "1024",
|
|
34
|
-
negative_prompt: str = ""
|
|
35
|
-
) -> List[str]:
|
|
36
|
-
"""Generate image from prompt
|
|
37
|
-
|
|
38
|
-
Args:
|
|
39
|
-
prompt (str): Image description.
|
|
40
|
-
amount (int, optional): Total images to be generated. Defaults to 1.
|
|
41
|
-
caption_model (str, optional): Caption model to use. Defaults to "sdxl".
|
|
42
|
-
selected_ratio (str, optional): Image ratio. Defaults to "1024".
|
|
43
|
-
negative_prompt (str, optional): Negative prompt. Defaults to "".
|
|
44
|
-
|
|
45
|
-
Returns:
|
|
46
|
-
List[str]: List of generated image URLs.
|
|
47
|
-
"""
|
|
48
|
-
assert bool(prompt), "Prompt cannot be null"
|
|
49
|
-
assert isinstance(amount, int), f"Amount should be an integer only not {type(amount)}"
|
|
50
|
-
assert amount > 0, "Amount should be greater than 0"
|
|
51
|
-
|
|
52
|
-
self.prompt = prompt
|
|
53
|
-
response: List[str] = []
|
|
54
|
-
|
|
55
|
-
payload = {
|
|
56
|
-
"captionInput": prompt,
|
|
57
|
-
"captionModel": caption_model,
|
|
58
|
-
"selectedRatio": selected_ratio,
|
|
59
|
-
"selectedSamples": str(amount),
|
|
60
|
-
"negative_prompt": negative_prompt
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
try:
|
|
64
|
-
# Sending the POST request using CloudScraper
|
|
65
|
-
resp = self.scraper.post(self.url, json=payload, timeout=self.timeout)
|
|
66
|
-
resp.raise_for_status() # Check for HTTP errors
|
|
67
|
-
|
|
68
|
-
# Parsing the JSON response
|
|
69
|
-
response_data = resp.json()
|
|
70
|
-
|
|
71
|
-
# Extracting image URLs from the response
|
|
72
|
-
imgs = response_data.get("imgs", [])
|
|
73
|
-
if imgs:
|
|
74
|
-
response.extend(imgs)
|
|
75
|
-
else:
|
|
76
|
-
print("No images found in the response.")
|
|
77
|
-
|
|
78
|
-
except requests.RequestException as e:
|
|
79
|
-
print(f"An error occurred while making the request: {e}")
|
|
80
|
-
raise
|
|
81
|
-
|
|
82
|
-
return response
|
|
83
|
-
|
|
84
|
-
def save(
|
|
85
|
-
self,
|
|
86
|
-
response: List[str], # List of image URLs
|
|
87
|
-
name: str = None,
|
|
88
|
-
dir: str = os.getcwd(),
|
|
89
|
-
filenames_prefix: str = "",
|
|
90
|
-
) -> List[str]:
|
|
91
|
-
"""Save generated images
|
|
92
|
-
|
|
93
|
-
Args:
|
|
94
|
-
response (List[str]): List of generated image URLs.
|
|
95
|
-
name (str): Filename for the images. Defaults to the last prompt.
|
|
96
|
-
dir (str, optional): Directory for saving images. Defaults to os.getcwd().
|
|
97
|
-
filenames_prefix (str, optional): String to be prefixed at each filename to be returned.
|
|
98
|
-
|
|
99
|
-
Returns:
|
|
100
|
-
List[str]: List of saved filenames.
|
|
101
|
-
"""
|
|
102
|
-
assert isinstance(response, list), f"Response should be of {list} not {type(response)}"
|
|
103
|
-
name = self.prompt if name is None else name
|
|
104
|
-
|
|
105
|
-
filenames = []
|
|
106
|
-
count = 0
|
|
107
|
-
for img_url in response:
|
|
108
|
-
def complete_path():
|
|
109
|
-
count_value = "" if count == 0 else f"_{count}"
|
|
110
|
-
return os.path.join(dir, name + count_value + "." + self.image_extension)
|
|
111
|
-
|
|
112
|
-
while os.path.isfile(complete_path()):
|
|
113
|
-
count += 1
|
|
114
|
-
|
|
115
|
-
absolute_path_to_file = complete_path()
|
|
116
|
-
filenames.append(filenames_prefix + os.path.split(absolute_path_to_file)[1])
|
|
117
|
-
|
|
118
|
-
# Download and save the image
|
|
119
|
-
try:
|
|
120
|
-
img_response = requests.get(img_url, stream=True, timeout=self.timeout)
|
|
121
|
-
img_response.raise_for_status()
|
|
122
|
-
|
|
123
|
-
with open(absolute_path_to_file, "wb") as fh:
|
|
124
|
-
for chunk in img_response.iter_content(chunk_size=8192):
|
|
125
|
-
fh.write(chunk)
|
|
126
|
-
except requests.exceptions.RequestException as e:
|
|
127
|
-
print(f"An error occurred while downloading image from {img_url}: {e}")
|
|
128
|
-
raise
|
|
129
|
-
|
|
130
|
-
return filenames
|
|
131
|
-
|
|
132
|
-
if __name__ == "__main__":
|
|
133
|
-
bot = ArtbitImager()
|
|
134
|
-
try:
|
|
135
|
-
resp = bot.generate(
|
|
136
|
-
"A shiny red sports car speeding down a scenic mountain road with a clear blue sky in the background, surrounded by lush green trees.",
|
|
137
|
-
amount=3
|
|
138
|
-
)
|
|
139
|
-
print(bot.save(resp))
|
|
140
|
-
except Exception as e:
|
|
141
|
-
print(f"An error occurred: {e}")
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
import os
|
|
3
|
-
from typing import List
|
|
4
|
-
from string import punctuation
|
|
5
|
-
from random import choice
|
|
6
|
-
from random import randint
|
|
7
|
-
import base64
|
|
8
|
-
|
|
9
|
-
from webscout.AIbase import ImageProvider
|
|
10
|
-
|
|
11
|
-
class DeepInfraImager(ImageProvider):
|
|
12
|
-
"""DeepInfra Image provider"""
|
|
13
|
-
|
|
14
|
-
def __init__(
|
|
15
|
-
self,
|
|
16
|
-
model: str = "black-forest-labs/FLUX-1-schnell",
|
|
17
|
-
timeout: int = 60,
|
|
18
|
-
proxies: dict = {},
|
|
19
|
-
):
|
|
20
|
-
"""Initializes `DeepInfraImager`
|
|
21
|
-
|
|
22
|
-
Args:
|
|
23
|
-
model (str, optional): The name of the DeepInfra model to use.
|
|
24
|
-
Defaults to "black-forest-labs/FLUX-1-schnell".
|
|
25
|
-
timeout (int, optional): Http request timeout. Defaults to 60 seconds.
|
|
26
|
-
proxies (dict, optional): Http request proxies (socks). Defaults to {}.
|
|
27
|
-
"""
|
|
28
|
-
self.image_gen_endpoint: str = f"https://api.deepinfra.com/v1/inference/{model}"
|
|
29
|
-
self.headers = {
|
|
30
|
-
"Accept": "application/json, text/plain, */*",
|
|
31
|
-
"Accept-Language": "en-US,en;q=0.9,en-IN;q=0.8",
|
|
32
|
-
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
33
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0",
|
|
34
|
-
"DNT": "1",
|
|
35
|
-
"Origin": "https://deepinfra.com",
|
|
36
|
-
"Referer": "https://deepinfra.com/",
|
|
37
|
-
"Sec-CH-UA": '"Chromium";v="128", "Not;A=Brand";v="24", "Microsoft Edge";v="128"',
|
|
38
|
-
"Sec-CH-UA-Mobile": "?0",
|
|
39
|
-
"Sec-CH-UA-Platform": '"Windows"',
|
|
40
|
-
"Sec-Fetch-Dest": "empty",
|
|
41
|
-
"Sec-Fetch-Mode": "cors",
|
|
42
|
-
"Sec-Fetch-Site": "same-site"
|
|
43
|
-
}
|
|
44
|
-
self.session = requests.Session()
|
|
45
|
-
self.session.headers.update(self.headers)
|
|
46
|
-
self.session.proxies.update(proxies)
|
|
47
|
-
self.timeout = timeout
|
|
48
|
-
self.prompt: str = "AI-generated image - webscout"
|
|
49
|
-
self.image_extension: str = "png"
|
|
50
|
-
|
|
51
|
-
def generate(
|
|
52
|
-
self, prompt: str, amount: int = 1, additives: bool = True,
|
|
53
|
-
num_inference_steps: int = 25, guidance_scale: float = 7.5,
|
|
54
|
-
width: int = 1024, height: int = 1024, seed: int = None
|
|
55
|
-
) -> list[bytes]:
|
|
56
|
-
"""Generate image from prompt
|
|
57
|
-
|
|
58
|
-
Args:
|
|
59
|
-
prompt (str): Image description.
|
|
60
|
-
amount (int): Total images to be generated. Defaults to 1.
|
|
61
|
-
additives (bool, optional): Try to make each prompt unique. Defaults to True.
|
|
62
|
-
num_inference_steps (int, optional): Number of inference steps. Defaults to 39.
|
|
63
|
-
guidance_scale (float, optional): Guidance scale for image generation. Defaults to 13.3.
|
|
64
|
-
width (int, optional): Width of the generated image. Defaults to 1024.
|
|
65
|
-
height (int, optional): Height of the generated image. Defaults to 1024.
|
|
66
|
-
seed (int, optional): Random seed for image generation. If None, a random seed is used.
|
|
67
|
-
Defaults to None.
|
|
68
|
-
|
|
69
|
-
Returns:
|
|
70
|
-
list[bytes]: List of generated images as bytes.
|
|
71
|
-
"""
|
|
72
|
-
assert bool(prompt), "Prompt cannot be null"
|
|
73
|
-
assert isinstance(amount, int), f"Amount should be an integer only not {type(amount)}"
|
|
74
|
-
assert amount > 0, "Amount should be greater than 0"
|
|
75
|
-
|
|
76
|
-
ads = lambda: (
|
|
77
|
-
""
|
|
78
|
-
if not additives
|
|
79
|
-
else choice(punctuation)
|
|
80
|
-
+ choice(punctuation)
|
|
81
|
-
+ choice(punctuation)
|
|
82
|
-
+ choice(punctuation)
|
|
83
|
-
+ choice(punctuation)
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
self.prompt = prompt
|
|
87
|
-
response = []
|
|
88
|
-
for _ in range(amount):
|
|
89
|
-
payload = {
|
|
90
|
-
"prompt": prompt + ads(),
|
|
91
|
-
"num_inference_steps": num_inference_steps,
|
|
92
|
-
"guidance_scale": guidance_scale,
|
|
93
|
-
"width": width,
|
|
94
|
-
"height": height,
|
|
95
|
-
"seed": seed if seed is not None else randint(1, 10000),
|
|
96
|
-
}
|
|
97
|
-
resp = self.session.post(url=self.image_gen_endpoint, json=payload, timeout=self.timeout)
|
|
98
|
-
resp.raise_for_status()
|
|
99
|
-
# Extract base64 encoded image data and decode it
|
|
100
|
-
image_data = resp.json()['images'][0].split(",")[1]
|
|
101
|
-
image_bytes = base64.b64decode(image_data)
|
|
102
|
-
response.append(image_bytes)
|
|
103
|
-
|
|
104
|
-
return response
|
|
105
|
-
|
|
106
|
-
def save(
|
|
107
|
-
self,
|
|
108
|
-
response: list[bytes],
|
|
109
|
-
name: str = None,
|
|
110
|
-
dir: str = os.getcwd(),
|
|
111
|
-
filenames_prefix: str = "",
|
|
112
|
-
) -> list[str]:
|
|
113
|
-
"""Save generated images
|
|
114
|
-
|
|
115
|
-
Args:
|
|
116
|
-
response (list[bytes]): List of generated images as bytes.
|
|
117
|
-
name (str): Filename for the images. Defaults to last prompt.
|
|
118
|
-
dir (str, optional): Directory for saving images. Defaults to os.getcwd().
|
|
119
|
-
filenames_prefix (str, optional): String to be prefixed at each filename to be returned.
|
|
120
|
-
"""
|
|
121
|
-
assert isinstance(response, list), f"Response should be of {list} not {type(response)}"
|
|
122
|
-
name = self.prompt if name is None else name
|
|
123
|
-
|
|
124
|
-
filenames: list = []
|
|
125
|
-
count = 0
|
|
126
|
-
for image in response:
|
|
127
|
-
def complete_path():
|
|
128
|
-
count_value = "" if count == 0 else f"_{count}"
|
|
129
|
-
return os.path.join(
|
|
130
|
-
dir, name + count_value + "." + self.image_extension
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
while os.path.isfile(complete_path()):
|
|
134
|
-
count += 1
|
|
135
|
-
|
|
136
|
-
absolute_path_to_file = complete_path()
|
|
137
|
-
filenames.append(filenames_prefix + os.path.split(absolute_path_to_file)[1])
|
|
138
|
-
|
|
139
|
-
with open(absolute_path_to_file, "wb") as fh:
|
|
140
|
-
fh.write(image)
|
|
141
|
-
|
|
142
|
-
return filenames
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if __name__ == "__main__":
|
|
146
|
-
bot = DeepInfraImager()
|
|
147
|
-
resp = bot.generate("AI-generated image - webscout", 1)
|
|
148
|
-
print(bot.save(resp))
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import requests
|
|
3
|
-
import io
|
|
4
|
-
from PIL import Image
|
|
5
|
-
from typing import Any, List, Optional, Dict
|
|
6
|
-
from webscout.AIbase import ImageProvider
|
|
7
|
-
|
|
8
|
-
class HFimager(ImageProvider):
|
|
9
|
-
"""
|
|
10
|
-
Image provider for Hugging Face Inference API.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
def __init__(
|
|
14
|
-
self,
|
|
15
|
-
api_token: str = None,
|
|
16
|
-
timeout: int = 60,
|
|
17
|
-
proxies: dict = {}
|
|
18
|
-
):
|
|
19
|
-
"""Initializes the HFimager class.
|
|
20
|
-
|
|
21
|
-
Args:
|
|
22
|
-
api_token (str, optional): Hugging Face API token. If None, it will use the environment variable "HUGGINGFACE_API_TOKEN".
|
|
23
|
-
Defaults to None.
|
|
24
|
-
timeout (int, optional): HTTP request timeout in seconds. Defaults to 60.
|
|
25
|
-
proxies (dict, optional): HTTP request proxies. Defaults to {}.
|
|
26
|
-
"""
|
|
27
|
-
self.base_url = "https://api-inference.huggingface.co/models/"
|
|
28
|
-
self.api_token = api_token or os.environ["HUGGINGFACE_API_TOKEN"]
|
|
29
|
-
self.headers = {"Authorization": f"Bearer {self.api_token}"}
|
|
30
|
-
self.session = requests.Session()
|
|
31
|
-
self.session.headers.update(self.headers)
|
|
32
|
-
self.session.proxies.update(proxies)
|
|
33
|
-
self.timeout = timeout
|
|
34
|
-
self.prompt: str = "AI-generated image - webscout"
|
|
35
|
-
self.image_extension: str = "jpg"
|
|
36
|
-
|
|
37
|
-
def generate(
|
|
38
|
-
self,
|
|
39
|
-
prompt: str,
|
|
40
|
-
amount: int = 1,
|
|
41
|
-
model: str = "black-forest-labs/FLUX.1-dev",
|
|
42
|
-
guidance_scale: Optional[float] = None,
|
|
43
|
-
negative_prompt: Optional[str] = None,
|
|
44
|
-
num_inference_steps: Optional[int] = None,
|
|
45
|
-
width: Optional[int] = None,
|
|
46
|
-
height: Optional[int] = None,
|
|
47
|
-
scheduler: Optional[str] = None,
|
|
48
|
-
seed: Optional[int] = None,
|
|
49
|
-
) -> List[bytes]:
|
|
50
|
-
"""
|
|
51
|
-
Generate image from prompt.
|
|
52
|
-
|
|
53
|
-
Args:
|
|
54
|
-
prompt (str): Image description.
|
|
55
|
-
amount (int): Total images to be generated. Defaults to 1.
|
|
56
|
-
model (str): Hugging Face model name. Defaults to "black-forest-labs/FLUX.1-dev".
|
|
57
|
-
guidance_scale (float, optional): Guidance scale value. Defaults to None.
|
|
58
|
-
negative_prompt (str, optional): Negative prompt. Defaults to None.
|
|
59
|
-
num_inference_steps (int, optional): Number of inference steps. Defaults to None.
|
|
60
|
-
width (int, optional): Width of the output image. Defaults to None.
|
|
61
|
-
height (int, optional): Height of the output image. Defaults to None.
|
|
62
|
-
scheduler (str, optional): Scheduler to use. Defaults to None.
|
|
63
|
-
seed (int, optional): Seed for random number generator. Defaults to None.
|
|
64
|
-
|
|
65
|
-
Returns:
|
|
66
|
-
List[bytes]: List of generated images as bytes.
|
|
67
|
-
"""
|
|
68
|
-
assert bool(prompt), "Prompt cannot be null"
|
|
69
|
-
assert isinstance(amount, int), f"Amount should be an integer only not {type(amount)}"
|
|
70
|
-
assert amount > 0, "Amount should be greater than 0"
|
|
71
|
-
|
|
72
|
-
self.prompt = prompt
|
|
73
|
-
response = []
|
|
74
|
-
|
|
75
|
-
for _ in range(amount):
|
|
76
|
-
url = self.base_url + model
|
|
77
|
-
|
|
78
|
-
# Create the base payload with the prompt
|
|
79
|
-
payload: Dict[str, Any] = {"inputs": prompt}
|
|
80
|
-
|
|
81
|
-
# Add optional parameters to the payload if provided
|
|
82
|
-
parameters = {}
|
|
83
|
-
if guidance_scale is not None:
|
|
84
|
-
parameters["guidance_scale"] = guidance_scale
|
|
85
|
-
if negative_prompt is not None:
|
|
86
|
-
parameters["negative_prompt"] = negative_prompt
|
|
87
|
-
if num_inference_steps is not None:
|
|
88
|
-
parameters["num_inference_steps"] = num_inference_steps
|
|
89
|
-
if width is not None and height is not None:
|
|
90
|
-
parameters["target_size"] = {"width": width, "height": height}
|
|
91
|
-
if scheduler is not None:
|
|
92
|
-
parameters["scheduler"] = scheduler
|
|
93
|
-
if seed is not None:
|
|
94
|
-
parameters["seed"] = seed
|
|
95
|
-
|
|
96
|
-
# Add the parameters to the payload if any are set
|
|
97
|
-
if parameters:
|
|
98
|
-
payload["parameters"] = parameters
|
|
99
|
-
|
|
100
|
-
try:
|
|
101
|
-
resp = self.session.post(url, headers=self.headers, json=payload, timeout=self.timeout)
|
|
102
|
-
resp.raise_for_status()
|
|
103
|
-
response.append(resp.content)
|
|
104
|
-
except requests.RequestException as e:
|
|
105
|
-
print(f"Failed to generate image: {e}")
|
|
106
|
-
raise
|
|
107
|
-
|
|
108
|
-
return response
|
|
109
|
-
|
|
110
|
-
def save(
|
|
111
|
-
self,
|
|
112
|
-
response: List[bytes],
|
|
113
|
-
name: str = None,
|
|
114
|
-
dir: str = os.getcwd(),
|
|
115
|
-
filenames_prefix: str = "",
|
|
116
|
-
) -> List[str]:
|
|
117
|
-
"""Save generated images
|
|
118
|
-
|
|
119
|
-
Args:
|
|
120
|
-
response (List[bytes]): List of generated images as bytes.
|
|
121
|
-
name (str): Filename for the images. Defaults to the last prompt.
|
|
122
|
-
dir (str, optional): Directory for saving images. Defaults to os.getcwd().
|
|
123
|
-
filenames_prefix (str, optional): String to be prefixed at each filename to be returned.
|
|
124
|
-
|
|
125
|
-
Returns:
|
|
126
|
-
List[str]: List of saved filenames.
|
|
127
|
-
"""
|
|
128
|
-
assert isinstance(response, list), f"Response should be of {list} not {type(response)}"
|
|
129
|
-
name = self.prompt if name is None else name
|
|
130
|
-
|
|
131
|
-
filenames = []
|
|
132
|
-
count = 0
|
|
133
|
-
for image_bytes in response:
|
|
134
|
-
def complete_path():
|
|
135
|
-
count_value = "" if count == 0 else f"_{count}"
|
|
136
|
-
return os.path.join(dir, name + count_value + "." + self.image_extension)
|
|
137
|
-
|
|
138
|
-
while os.path.isfile(complete_path()):
|
|
139
|
-
count += 1
|
|
140
|
-
|
|
141
|
-
absolute_path_to_file = complete_path()
|
|
142
|
-
filenames.append(filenames_prefix + os.path.split(absolute_path_to_file)[1])
|
|
143
|
-
|
|
144
|
-
with open(absolute_path_to_file, "wb") as fh:
|
|
145
|
-
fh.write(image_bytes)
|
|
146
|
-
|
|
147
|
-
return filenames
|
|
148
|
-
|
|
149
|
-
if __name__ == "__main__":
|
|
150
|
-
bot = HFimager(api_token='your huggingface API')
|
|
151
|
-
try:
|
|
152
|
-
resp = bot.generate("A shiny red sports car speeding down a scenic mountain road with a clear blue sky in the background, surrounded by lush green trees.", 1)
|
|
153
|
-
print(bot.save(resp, name="test"))
|
|
154
|
-
except Exception as e:
|
|
155
|
-
print(f"An error occurred: {e}")
|