webscout 6.3__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 (85) hide show
  1. webscout/AIauto.py +191 -176
  2. webscout/AIbase.py +0 -197
  3. webscout/AIutel.py +488 -1130
  4. webscout/Bing_search.py +250 -153
  5. webscout/DWEBS.py +151 -19
  6. webscout/Extra/__init__.py +2 -1
  7. webscout/Extra/autocoder/__init__.py +9 -0
  8. webscout/Extra/autocoder/autocoder_utiles.py +121 -0
  9. webscout/Extra/autocoder/rawdog.py +681 -0
  10. webscout/Extra/autollama.py +246 -195
  11. webscout/Extra/gguf.py +441 -416
  12. webscout/LLM.py +206 -43
  13. webscout/Litlogger/__init__.py +681 -0
  14. webscout/Provider/DARKAI.py +1 -1
  15. webscout/Provider/EDITEE.py +1 -1
  16. webscout/Provider/NinjaChat.py +1 -1
  17. webscout/Provider/PI.py +221 -207
  18. webscout/Provider/Perplexity.py +598 -598
  19. webscout/Provider/RoboCoders.py +206 -0
  20. webscout/Provider/TTI/AiForce/__init__.py +22 -0
  21. webscout/Provider/TTI/AiForce/async_aiforce.py +257 -0
  22. webscout/Provider/TTI/AiForce/sync_aiforce.py +242 -0
  23. webscout/Provider/TTI/Nexra/__init__.py +22 -0
  24. webscout/Provider/TTI/Nexra/async_nexra.py +286 -0
  25. webscout/Provider/TTI/Nexra/sync_nexra.py +258 -0
  26. webscout/Provider/TTI/PollinationsAI/__init__.py +23 -0
  27. webscout/Provider/TTI/PollinationsAI/async_pollinations.py +330 -0
  28. webscout/Provider/TTI/PollinationsAI/sync_pollinations.py +285 -0
  29. webscout/Provider/TTI/__init__.py +2 -4
  30. webscout/Provider/TTI/artbit/__init__.py +22 -0
  31. webscout/Provider/TTI/artbit/async_artbit.py +184 -0
  32. webscout/Provider/TTI/artbit/sync_artbit.py +176 -0
  33. webscout/Provider/TTI/blackbox/__init__.py +4 -0
  34. webscout/Provider/TTI/blackbox/async_blackbox.py +212 -0
  35. webscout/Provider/TTI/{blackboximage.py → blackbox/sync_blackbox.py} +199 -153
  36. webscout/Provider/TTI/deepinfra/__init__.py +4 -0
  37. webscout/Provider/TTI/deepinfra/async_deepinfra.py +227 -0
  38. webscout/Provider/TTI/deepinfra/sync_deepinfra.py +199 -0
  39. webscout/Provider/TTI/huggingface/__init__.py +22 -0
  40. webscout/Provider/TTI/huggingface/async_huggingface.py +199 -0
  41. webscout/Provider/TTI/huggingface/sync_huggingface.py +195 -0
  42. webscout/Provider/TTI/imgninza/__init__.py +4 -0
  43. webscout/Provider/TTI/imgninza/async_ninza.py +214 -0
  44. webscout/Provider/TTI/{imgninza.py → imgninza/sync_ninza.py} +209 -136
  45. webscout/Provider/TTI/talkai/__init__.py +4 -0
  46. webscout/Provider/TTI/talkai/async_talkai.py +229 -0
  47. webscout/Provider/TTI/talkai/sync_talkai.py +207 -0
  48. webscout/Provider/__init__.py +146 -139
  49. webscout/Provider/askmyai.py +2 -2
  50. webscout/Provider/cerebras.py +227 -219
  51. webscout/Provider/llama3mitril.py +0 -1
  52. webscout/Provider/mhystical.py +176 -0
  53. webscout/Provider/perplexitylabs.py +265 -0
  54. webscout/Provider/twitterclone.py +251 -245
  55. webscout/Provider/typegpt.py +359 -0
  56. webscout/__init__.py +28 -23
  57. webscout/__main__.py +5 -5
  58. webscout/cli.py +252 -280
  59. webscout/conversation.py +227 -0
  60. webscout/exceptions.py +161 -29
  61. webscout/litagent/__init__.py +172 -0
  62. webscout/litprinter/__init__.py +831 -0
  63. webscout/optimizers.py +270 -0
  64. webscout/prompt_manager.py +279 -0
  65. webscout/swiftcli/__init__.py +810 -0
  66. webscout/transcriber.py +479 -551
  67. webscout/update_checker.py +125 -0
  68. webscout/version.py +1 -1
  69. {webscout-6.3.dist-info → webscout-6.4.dist-info}/METADATA +26 -45
  70. {webscout-6.3.dist-info → webscout-6.4.dist-info}/RECORD +75 -45
  71. webscout/Provider/TTI/AIuncensoredimage.py +0 -103
  72. webscout/Provider/TTI/Nexra.py +0 -120
  73. webscout/Provider/TTI/PollinationsAI.py +0 -138
  74. webscout/Provider/TTI/WebSimAI.py +0 -142
  75. webscout/Provider/TTI/aiforce.py +0 -160
  76. webscout/Provider/TTI/artbit.py +0 -141
  77. webscout/Provider/TTI/deepinfra.py +0 -148
  78. webscout/Provider/TTI/huggingface.py +0 -155
  79. webscout/Provider/TTI/talkai.py +0 -116
  80. webscout/models.py +0 -23
  81. /webscout/{g4f.py → gpt4free.py} +0 -0
  82. {webscout-6.3.dist-info → webscout-6.4.dist-info}/LICENSE.md +0 -0
  83. {webscout-6.3.dist-info → webscout-6.4.dist-info}/WHEEL +0 -0
  84. {webscout-6.3.dist-info → webscout-6.4.dist-info}/entry_points.txt +0 -0
  85. {webscout-6.3.dist-info → webscout-6.4.dist-info}/top_level.txt +0 -0
@@ -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}")
@@ -1,116 +0,0 @@
1
- import uuid
2
- import requests
3
- import json
4
- import os
5
- from typing import Any, Dict, List, Optional
6
-
7
- from webscout.AIbase import ImageProvider
8
- from webscout import exceptions
9
-
10
-
11
- class TalkaiImager(ImageProvider):
12
- """
13
- Image provider for Talkai.info.
14
- """
15
-
16
- def __init__(self, timeout: int = 60, proxies: dict = {}):
17
- """Initializes the TalkaiImager class.
18
-
19
- Args:
20
- timeout (int, optional): HTTP request timeout in seconds. Defaults to 60.
21
- proxies (dict, optional): HTTP request proxies. Defaults to {}.
22
- """
23
- self.api_endpoint = "https://talkai.info/chat/send/"
24
- self.headers = {
25
- 'accept': 'application/json',
26
- 'accept-language': 'en-US,en;q=0.9',
27
- 'content-type': 'application/json',
28
- 'origin': 'https://talkai.info',
29
- 'referer': 'https://talkai.info/image/',
30
- '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',
31
- }
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(self, prompt: str, amount: int = 1) -> List[str]:
40
- """Generates image URLs from a prompt."""
41
- assert bool(prompt), "Prompt cannot be empty."
42
- assert isinstance(amount, int) and amount > 0, "Amount must be a positive integer."
43
-
44
- self.prompt = prompt
45
- image_urls = []
46
-
47
- try:
48
- with self.session.post(self.api_endpoint, json=self._create_payload(prompt), timeout=self.timeout) as response:
49
- response.raise_for_status()
50
- data = response.json()
51
-
52
- if 'data' in data and len(data['data']) > 0 and 'url' in data['data'][0]:
53
- image_urls.append(data['data'][0]['url'])
54
- else:
55
- raise exceptions.InvalidResponseError("No image URL found in API response.")
56
-
57
- except requests.exceptions.RequestException as e:
58
- raise exceptions.APIConnectionError(f"Error making API request: {e}") from e
59
- except json.JSONDecodeError as e:
60
- raise exceptions.InvalidResponseError(f"Invalid JSON response: {e}") from e
61
- except Exception as e:
62
- raise exceptions.FailedToGenerateResponseError(f"An unexpected error occurred: {e}") from e
63
-
64
- return image_urls
65
-
66
- def _create_payload(self, prompt: str) -> Dict[str, Any]:
67
- return {
68
- "type": "image",
69
- "messagesHistory": [
70
- {
71
- "id": str(uuid.uuid4()),
72
- "from": "you",
73
- "content": prompt
74
- }
75
- ],
76
- "settings": {
77
- "model": "gpt-4o-mini" # Or another suitable model if available
78
- }
79
- }
80
-
81
-
82
- def save(
83
- self,
84
- response: List[str],
85
- name: str = None,
86
- dir: str = os.getcwd(),
87
- filenames_prefix: str = "",
88
- ) -> List[str]:
89
- assert isinstance(response, list), f"Response should be a list, not {type(response)}"
90
- name = self.prompt if name is None else name
91
-
92
- filenames = []
93
- for i, url in enumerate(response):
94
- try:
95
- with self.session.get(url, stream=True, timeout=self.timeout) as r:
96
- r.raise_for_status()
97
- filename = f"{filenames_prefix}{name}_{i}.{self.image_extension}"
98
- filepath = os.path.join(dir, filename)
99
- with open(filepath, 'wb') as f:
100
- for chunk in r.iter_content(chunk_size=8192):
101
- f.write(chunk)
102
- filenames.append(filename)
103
- except requests.exceptions.RequestException as e:
104
- print(f"Error downloading image from {url}: {e}")
105
- filenames.append(None) # Indicate failure to download
106
-
107
- return filenames
108
-
109
-
110
- if __name__ == "__main__":
111
- bot = TalkaiImager()
112
- try:
113
- resp = bot.generate("A shiny red sports car speeding down a scenic mountain road", 1)
114
- print(bot.save(resp))
115
- except Exception as e:
116
- 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
File without changes
File without changes