webscout 6.2b0__py3-none-any.whl → 6.4__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.

Files changed (97) hide show
  1. webscout/AIauto.py +191 -176
  2. webscout/AIbase.py +112 -239
  3. webscout/AIutel.py +488 -1130
  4. webscout/Agents/functioncall.py +248 -198
  5. webscout/Bing_search.py +250 -153
  6. webscout/DWEBS.py +454 -178
  7. webscout/Extra/__init__.py +2 -1
  8. webscout/Extra/autocoder/__init__.py +9 -0
  9. webscout/Extra/autocoder/autocoder_utiles.py +121 -0
  10. webscout/Extra/autocoder/rawdog.py +681 -0
  11. webscout/Extra/autollama.py +246 -195
  12. webscout/Extra/gguf.py +441 -226
  13. webscout/Extra/weather.py +172 -67
  14. webscout/LLM.py +442 -100
  15. webscout/Litlogger/__init__.py +681 -0
  16. webscout/Local/formats.py +4 -2
  17. webscout/Provider/Amigo.py +19 -10
  18. webscout/Provider/Andi.py +0 -33
  19. webscout/Provider/Blackboxai.py +4 -204
  20. webscout/Provider/DARKAI.py +1 -1
  21. webscout/Provider/EDITEE.py +1 -1
  22. webscout/Provider/Llama3.py +1 -1
  23. webscout/Provider/Marcus.py +137 -0
  24. webscout/Provider/NinjaChat.py +1 -1
  25. webscout/Provider/PI.py +221 -207
  26. webscout/Provider/Perplexity.py +598 -598
  27. webscout/Provider/RoboCoders.py +206 -0
  28. webscout/Provider/TTI/AiForce/__init__.py +22 -0
  29. webscout/Provider/TTI/AiForce/async_aiforce.py +257 -0
  30. webscout/Provider/TTI/AiForce/sync_aiforce.py +242 -0
  31. webscout/Provider/TTI/Nexra/__init__.py +22 -0
  32. webscout/Provider/TTI/Nexra/async_nexra.py +286 -0
  33. webscout/Provider/TTI/Nexra/sync_nexra.py +258 -0
  34. webscout/Provider/TTI/PollinationsAI/__init__.py +23 -0
  35. webscout/Provider/TTI/PollinationsAI/async_pollinations.py +330 -0
  36. webscout/Provider/TTI/PollinationsAI/sync_pollinations.py +285 -0
  37. webscout/Provider/TTI/__init__.py +3 -4
  38. webscout/Provider/TTI/artbit/__init__.py +22 -0
  39. webscout/Provider/TTI/artbit/async_artbit.py +184 -0
  40. webscout/Provider/TTI/artbit/sync_artbit.py +176 -0
  41. webscout/Provider/TTI/blackbox/__init__.py +4 -0
  42. webscout/Provider/TTI/blackbox/async_blackbox.py +212 -0
  43. webscout/Provider/TTI/{blackboximage.py → blackbox/sync_blackbox.py} +199 -153
  44. webscout/Provider/TTI/deepinfra/__init__.py +4 -0
  45. webscout/Provider/TTI/deepinfra/async_deepinfra.py +227 -0
  46. webscout/Provider/TTI/deepinfra/sync_deepinfra.py +199 -0
  47. webscout/Provider/TTI/huggingface/__init__.py +22 -0
  48. webscout/Provider/TTI/huggingface/async_huggingface.py +199 -0
  49. webscout/Provider/TTI/huggingface/sync_huggingface.py +195 -0
  50. webscout/Provider/TTI/imgninza/__init__.py +4 -0
  51. webscout/Provider/TTI/imgninza/async_ninza.py +214 -0
  52. webscout/Provider/TTI/{imgninza.py → imgninza/sync_ninza.py} +209 -136
  53. webscout/Provider/TTI/talkai/__init__.py +4 -0
  54. webscout/Provider/TTI/talkai/async_talkai.py +229 -0
  55. webscout/Provider/TTI/talkai/sync_talkai.py +207 -0
  56. webscout/Provider/__init__.py +146 -132
  57. webscout/Provider/askmyai.py +158 -0
  58. webscout/Provider/cerebras.py +227 -206
  59. webscout/Provider/geminiapi.py +208 -198
  60. webscout/Provider/llama3mitril.py +180 -0
  61. webscout/Provider/llmchat.py +203 -0
  62. webscout/Provider/mhystical.py +176 -0
  63. webscout/Provider/perplexitylabs.py +265 -0
  64. webscout/Provider/talkai.py +196 -0
  65. webscout/Provider/twitterclone.py +251 -244
  66. webscout/Provider/typegpt.py +359 -0
  67. webscout/__init__.py +28 -23
  68. webscout/__main__.py +5 -5
  69. webscout/cli.py +327 -347
  70. webscout/conversation.py +227 -0
  71. webscout/exceptions.py +161 -29
  72. webscout/litagent/__init__.py +172 -0
  73. webscout/litprinter/__init__.py +831 -0
  74. webscout/optimizers.py +270 -0
  75. webscout/prompt_manager.py +279 -0
  76. webscout/swiftcli/__init__.py +810 -0
  77. webscout/transcriber.py +479 -551
  78. webscout/update_checker.py +125 -0
  79. webscout/version.py +1 -1
  80. webscout-6.4.dist-info/LICENSE.md +211 -0
  81. {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/METADATA +34 -55
  82. webscout-6.4.dist-info/RECORD +154 -0
  83. webscout/Provider/TTI/AIuncensored.py +0 -103
  84. webscout/Provider/TTI/Nexra.py +0 -120
  85. webscout/Provider/TTI/PollinationsAI.py +0 -138
  86. webscout/Provider/TTI/WebSimAI.py +0 -142
  87. webscout/Provider/TTI/aiforce.py +0 -160
  88. webscout/Provider/TTI/artbit.py +0 -141
  89. webscout/Provider/TTI/deepinfra.py +0 -148
  90. webscout/Provider/TTI/huggingface.py +0 -155
  91. webscout/models.py +0 -23
  92. webscout-6.2b0.dist-info/LICENSE.md +0 -50
  93. webscout-6.2b0.dist-info/RECORD +0 -118
  94. /webscout/{g4f.py → gpt4free.py} +0 -0
  95. {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/WHEEL +0 -0
  96. {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/entry_points.txt +0 -0
  97. {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/top_level.txt +0 -0
@@ -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}")
@@ -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}")
webscout/models.py DELETED
@@ -1,23 +0,0 @@
1
- from dataclasses import dataclass
2
- from typing import Dict, Optional
3
-
4
-
5
- @dataclass
6
- class MapsResult:
7
- """Represents a result from the maps search."""
8
-
9
- title: Optional[str] = None
10
- address: Optional[str] = None
11
- country_code: Optional[str] = None
12
- latitude: Optional[str] = None
13
- longitude: Optional[str] = None
14
- url: Optional[str] = None
15
- desc: Optional[str] = None
16
- phone: Optional[str] = None
17
- image: Optional[str] = None
18
- source: Optional[str] = None
19
- hours: Optional[Dict[str, str]] = None
20
- category: Optional[str] = None
21
- facebook: Optional[str] = None
22
- instagram: Optional[str] = None
23
- twitter: Optional[str] = None
@@ -1,50 +0,0 @@
1
- ************************************************
2
- **** HelpingAI License ****
3
- ************************************************
4
-
5
- Version 2.0
6
-
7
- Developed by Abhay Koul
8
-
9
- ### Preamble
10
-
11
- The HelpingAI License governs the use of HelpingAI's digital assets, including but not limited to software, scripts, datasets, documents, images, audio recordings, videos. The HelpingAI License aims to provide clear, comprehensive terms for accessing, modifying, and sharing resources, while promoting ethical development practices.
12
-
13
- ### Grant of Rights
14
-
15
- Under the HelpingAI License, HelpingAI grants you the rights to copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Content, provided you comply with the terms and conditions outlined in this document.
16
-
17
- ### Terms and Conditions
18
-
19
- To exercise the rights granted in the previous section, you must adhere to the following terms and conditions:
20
-
21
- 2.1. **Redistribution of Source Code.**
22
- If you redistribute the Source Code, you must include the complete HelpingAI License with your distribution. You must also add clear notifications in all modified files stating:
23
-
24
- > "This Work is released under the HelpingAI License v2.0."
25
-
26
- 2.2. **Distribution in Binary Form.**
27
- If you distribute Binaries derived from the Source Code, you must include the following statement in your distribution:
28
-
29
- > "This Work is based on the HelpingAI Licensed Work, under the HelpingAI License v2.0."
30
-
31
- 2.3. **Notification of Changes.**
32
- You must clearly indicate any modifications you make to the Source Code or Documentation, including detailed comments about the nature and extent of the changes. Include the date and originator of the modifications.
33
-
34
- 2.4. **Branding Attribution.**
35
- You must not remove or alter any HelpingAI branding, logos, or notices included in the Content without explicit prior consent from HelpingAI.
36
-
37
- 2.5. **Disclaimer of Warranty.**
38
- The Content is provided "AS IS," without any implied warranties, including but not limited to warranties of merchantability, fitness for a particular purpose, and non-infringement.
39
-
40
- 2.6. **Limitation of Liability.**
41
- To the maximum extent permitted by law, neither HelpingAI nor any contributor shall be liable for any loss, personal injury, property damage, or any indirect, special, incidental, or consequential damages arising from or related to the use of the Content.
42
-
43
- 2.7. **Governing Law.**
44
- This HelpingAI License shall be governed and construed in accordance with the laws of the jurisdiction where HelpingAI primarily operates.
45
-
46
- ### Definitions
47
-
48
- 3.1. **"Source Code"** refers to the preferred form for making modifications to the Content, typically represented by human-readable programming languages, scripts, or documentation formats.
49
-
50
- 3.2. **"Binaries"** refers to compiled forms of the Source Code, such as executables, libraries, or similar artifacts produced from the Source Code.