webscout 6.4__py3-none-any.whl → 6.6__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 (116) hide show
  1. webscout/AIutel.py +7 -54
  2. webscout/DWEBS.py +48 -26
  3. webscout/{YTdownloader.py → Extra/YTToolkit/YTdownloader.py} +990 -1103
  4. webscout/Extra/YTToolkit/__init__.py +3 -0
  5. webscout/{transcriber.py → Extra/YTToolkit/transcriber.py} +1 -1
  6. webscout/Extra/YTToolkit/ytapi/__init__.py +6 -0
  7. webscout/Extra/YTToolkit/ytapi/channel.py +307 -0
  8. webscout/Extra/YTToolkit/ytapi/errors.py +13 -0
  9. webscout/Extra/YTToolkit/ytapi/extras.py +45 -0
  10. webscout/Extra/YTToolkit/ytapi/https.py +88 -0
  11. webscout/Extra/YTToolkit/ytapi/patterns.py +61 -0
  12. webscout/Extra/YTToolkit/ytapi/playlist.py +59 -0
  13. webscout/Extra/YTToolkit/ytapi/pool.py +8 -0
  14. webscout/Extra/YTToolkit/ytapi/query.py +37 -0
  15. webscout/Extra/YTToolkit/ytapi/stream.py +60 -0
  16. webscout/Extra/YTToolkit/ytapi/utils.py +62 -0
  17. webscout/Extra/YTToolkit/ytapi/video.py +102 -0
  18. webscout/Extra/__init__.py +2 -1
  19. webscout/Extra/autocoder/autocoder_utiles.py +119 -101
  20. webscout/Extra/autocoder/rawdog.py +679 -680
  21. webscout/Extra/gguf.py +441 -441
  22. webscout/Extra/markdownlite/__init__.py +862 -0
  23. webscout/Extra/weather_ascii.py +2 -2
  24. webscout/Provider/AISEARCH/__init__.py +2 -0
  25. webscout/Provider/AISEARCH/ooai.py +155 -0
  26. webscout/Provider/Amigo.py +70 -85
  27. webscout/Provider/{prefind.py → Jadve.py} +72 -70
  28. webscout/Provider/Netwrck.py +235 -0
  29. webscout/Provider/Openai.py +4 -3
  30. webscout/Provider/PI.py +292 -221
  31. webscout/Provider/PizzaGPT.py +3 -3
  32. webscout/Provider/Reka.py +0 -1
  33. webscout/Provider/TTS/__init__.py +5 -1
  34. webscout/Provider/TTS/deepgram.py +183 -0
  35. webscout/Provider/TTS/elevenlabs.py +137 -0
  36. webscout/Provider/TTS/gesserit.py +151 -0
  37. webscout/Provider/TTS/murfai.py +139 -0
  38. webscout/Provider/TTS/parler.py +134 -107
  39. webscout/Provider/TTS/streamElements.py +360 -275
  40. webscout/Provider/TTS/utils.py +280 -0
  41. webscout/Provider/TTS/voicepod.py +116 -116
  42. webscout/Provider/TeachAnything.py +15 -2
  43. webscout/Provider/Youchat.py +42 -8
  44. webscout/Provider/__init__.py +8 -21
  45. webscout/Provider/meta.py +794 -779
  46. webscout/Provider/multichat.py +230 -0
  47. webscout/Provider/promptrefine.py +2 -2
  48. webscout/Provider/talkai.py +10 -13
  49. webscout/Provider/turboseek.py +5 -4
  50. webscout/Provider/tutorai.py +8 -112
  51. webscout/Provider/typegpt.py +5 -7
  52. webscout/Provider/x0gpt.py +81 -9
  53. webscout/Provider/yep.py +123 -361
  54. webscout/__init__.py +33 -28
  55. webscout/conversation.py +24 -9
  56. webscout/exceptions.py +188 -20
  57. webscout/litprinter/__init__.py +719 -831
  58. webscout/litprinter/colors.py +54 -0
  59. webscout/optimizers.py +420 -270
  60. webscout/prompt_manager.py +279 -279
  61. webscout/scout/__init__.py +8 -0
  62. webscout/scout/core/__init__.py +7 -0
  63. webscout/scout/core/crawler.py +140 -0
  64. webscout/scout/core/scout.py +571 -0
  65. webscout/scout/core/search_result.py +96 -0
  66. webscout/scout/core/text_analyzer.py +63 -0
  67. webscout/scout/core/text_utils.py +277 -0
  68. webscout/scout/core/web_analyzer.py +52 -0
  69. webscout/scout/core.py +884 -0
  70. webscout/scout/element.py +460 -0
  71. webscout/scout/parsers/__init__.py +69 -0
  72. webscout/scout/parsers/html5lib_parser.py +172 -0
  73. webscout/scout/parsers/html_parser.py +236 -0
  74. webscout/scout/parsers/lxml_parser.py +178 -0
  75. webscout/scout/utils.py +38 -0
  76. webscout/update_checker.py +184 -125
  77. webscout/version.py +1 -1
  78. webscout/zeroart/__init__.py +55 -0
  79. webscout/zeroart/base.py +60 -0
  80. webscout/zeroart/effects.py +99 -0
  81. webscout/zeroart/fonts.py +816 -0
  82. webscout/zerodir/__init__.py +225 -0
  83. {webscout-6.4.dist-info → webscout-6.6.dist-info}/METADATA +18 -231
  84. webscout-6.6.dist-info/RECORD +197 -0
  85. webscout-6.6.dist-info/top_level.txt +2 -0
  86. webstoken/__init__.py +30 -0
  87. webstoken/classifier.py +189 -0
  88. webstoken/keywords.py +216 -0
  89. webstoken/language.py +128 -0
  90. webstoken/ner.py +164 -0
  91. webstoken/normalizer.py +35 -0
  92. webstoken/processor.py +77 -0
  93. webstoken/sentiment.py +206 -0
  94. webstoken/stemmer.py +73 -0
  95. webstoken/t.py +75 -0
  96. webstoken/tagger.py +60 -0
  97. webstoken/tokenizer.py +158 -0
  98. webscout/Agents/Onlinesearcher.py +0 -182
  99. webscout/Agents/__init__.py +0 -2
  100. webscout/Agents/functioncall.py +0 -248
  101. webscout/Bing_search.py +0 -251
  102. webscout/Provider/Perplexity.py +0 -599
  103. webscout/Provider/RoboCoders.py +0 -206
  104. webscout/Provider/genspark.py +0 -225
  105. webscout/Provider/perplexitylabs.py +0 -265
  106. webscout/Provider/twitterclone.py +0 -251
  107. webscout/Provider/upstage.py +0 -230
  108. webscout/gpt4free.py +0 -666
  109. webscout/requestsHTMLfix.py +0 -775
  110. webscout/webai.py +0 -2590
  111. webscout-6.4.dist-info/RECORD +0 -154
  112. webscout-6.4.dist-info/top_level.txt +0 -1
  113. /webscout/Provider/{felo_search.py → AISEARCH/felo_search.py} +0 -0
  114. {webscout-6.4.dist-info → webscout-6.6.dist-info}/LICENSE.md +0 -0
  115. {webscout-6.4.dist-info → webscout-6.6.dist-info}/WHEEL +0 -0
  116. {webscout-6.4.dist-info → webscout-6.6.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,280 @@
1
+ """
2
+ Text processing utilities for TTS providers.
3
+ """
4
+ from typing import List, Dict, Tuple, Set, Optional, Pattern
5
+ import re
6
+
7
+
8
+ class SentenceTokenizer:
9
+ """Advanced sentence tokenizer with support for complex cases and proper formatting."""
10
+
11
+ def __init__(self) -> None:
12
+ # Common abbreviations by category
13
+ self.TITLES: Set[str] = {
14
+ 'mr', 'mrs', 'ms', 'dr', 'prof', 'rev', 'sr', 'jr', 'esq',
15
+ 'hon', 'pres', 'gov', 'atty', 'supt', 'det', 'rev', 'col','maj', 'gen', 'capt', 'cmdr',
16
+ 'lt', 'sgt', 'cpl', 'pvt'
17
+ }
18
+
19
+ self.ACADEMIC: Set[str] = {
20
+ 'ph.d', 'phd', 'm.d', 'md', 'b.a', 'ba', 'm.a', 'ma', 'd.d.s', 'dds',
21
+ 'm.b.a', 'mba', 'b.sc', 'bsc', 'm.sc', 'msc', 'llb', 'll.b', 'bl'
22
+ }
23
+
24
+ self.ORGANIZATIONS: Set[str] = {
25
+ 'inc', 'ltd', 'co', 'corp', 'llc', 'llp', 'assn', 'bros', 'plc', 'cos',
26
+ 'intl', 'dept', 'est', 'dist', 'mfg', 'div'
27
+ }
28
+
29
+ self.MONTHS: Set[str] = {
30
+ 'jan', 'feb', 'mar', 'apr', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'
31
+ }
32
+
33
+ self.UNITS: Set[str] = {
34
+ 'oz', 'pt', 'qt', 'gal', 'ml', 'cc', 'km', 'cm', 'mm', 'ft', 'in',
35
+ 'kg', 'lb', 'lbs', 'hz', 'khz', 'mhz', 'ghz', 'kb', 'mb', 'gb', 'tb'
36
+ }
37
+
38
+ self.TECHNOLOGY: Set[str] = {
39
+ 'v', 'ver', 'app', 'sys', 'dir', 'exe', 'lib', 'api', 'sdk', 'url',
40
+ 'cpu', 'gpu', 'ram', 'rom', 'hdd', 'ssd', 'lan', 'wan', 'sql', 'html'
41
+ }
42
+
43
+ self.MISC: Set[str] = {
44
+ 'vs', 'etc', 'ie', 'eg', 'no', 'al', 'ca', 'cf', 'pp', 'est', 'st',
45
+ 'approx', 'appt', 'apt', 'dept', 'depts', 'min', 'max', 'avg'
46
+ }
47
+
48
+ # Combine all abbreviations
49
+ self.all_abbreviations: Set[str] = (
50
+ self.TITLES | self.ACADEMIC | self.ORGANIZATIONS |
51
+ self.MONTHS | self.UNITS | self.TECHNOLOGY | self.MISC
52
+ )
53
+
54
+ # Special patterns
55
+ self.ELLIPSIS: str = r'\.{2,}|…'
56
+ self.URL_PATTERN: str = (
57
+ r'(?:https?:\/\/|www\.)[\w\-\.]+\.[a-zA-Z]{2,}(?:\/[^\s]*)?'
58
+ )
59
+ self.EMAIL_PATTERN: str = r'[\w\.-]+@[\w\.-]+\.\w+'
60
+ self.NUMBER_PATTERN: str = (
61
+ r'\d+(?:\.\d+)?(?:%|°|km|cm|mm|m|kg|g|lb|ft|in|mph|kmh|hz|mhz|ghz)?'
62
+ )
63
+
64
+ # Quote and bracket pairs
65
+ self.QUOTE_PAIRS: Dict[str, str] = {
66
+ '"': '"', "'": "'", '"': '"', "「": "」", "『": "』",
67
+ "«": "»", "‹": "›", "'": "'", "‚": "'"
68
+ }
69
+
70
+ self.BRACKETS: Dict[str, str] = {
71
+ '(': ')', '[': ']', '{': '}', '⟨': '⟩', '「': '」',
72
+ '『': '』', '【': '】', '〖': '〗', '「': '」'
73
+ }
74
+
75
+ # Compile regex patterns
76
+ self._compile_patterns()
77
+
78
+ def _compile_patterns(self) -> None:
79
+ """Compile regex patterns for better performance."""
80
+ # Pattern for finding potential sentence boundaries
81
+ self.SENTENCE_END: Pattern = re.compile(
82
+ r'''
83
+ # Group for sentence endings
84
+ (?:
85
+ # Standard endings with optional quotes/brackets
86
+ (?<=[.!?])[\"\'\)\]\}»›」』\s]*
87
+
88
+ # Ellipsis
89
+ |(?:\.{2,}|…)
90
+
91
+ # Asian-style endings
92
+ |(?<=[。!?」』】\s])
93
+ )
94
+
95
+ # Must be followed by whitespace and capital letter or number
96
+ (?=\s+(?:[A-Z0-9]|["'({[\[「『《‹〈][A-Z]))
97
+ ''',
98
+ re.VERBOSE
99
+ )
100
+
101
+ # Pattern for abbreviations
102
+ abbrev_pattern = '|'.join(re.escape(abbr) for abbr in self.all_abbreviations)
103
+ self.ABBREV_PATTERN: Pattern = re.compile(
104
+ fr'\b(?:{abbrev_pattern})\.?',
105
+ re.IGNORECASE
106
+ )
107
+
108
+ def _protect_special_cases(self, text: str) -> Tuple[str, Dict[str, str]]:
109
+ """Protect URLs, emails, and other special cases from being split."""
110
+ protected = text
111
+ placeholders: Dict[str, str] = {}
112
+ counter = 0
113
+
114
+ # Protect URLs and emails
115
+ for pattern in [self.URL_PATTERN, self.EMAIL_PATTERN]:
116
+ for match in re.finditer(pattern, protected):
117
+ placeholder = f'__PROTECTED_{counter}__'
118
+ placeholders[placeholder] = match.group()
119
+ protected = protected.replace(match.group(), placeholder)
120
+ counter += 1
121
+
122
+ # Protect quoted content
123
+ stack = []
124
+ protected_chars = list(protected)
125
+ i = 0
126
+ while i < len(protected_chars):
127
+ char = protected_chars[i]
128
+ if char in self.QUOTE_PAIRS:
129
+ stack.append((char, i))
130
+ elif stack and char == self.QUOTE_PAIRS[stack[-1][0]]:
131
+ start_quote, start_idx = stack.pop()
132
+ content = ''.join(protected_chars[start_idx:i + 1])
133
+ placeholder = f'__PROTECTED_{counter}__'
134
+ placeholders[placeholder] = content
135
+ protected_chars[start_idx:i + 1] = list(placeholder)
136
+ counter += 1
137
+ i += 1
138
+
139
+ return ''.join(protected_chars), placeholders
140
+
141
+ def _restore_special_cases(self, text: str, placeholders: Dict[str, str]) -> str:
142
+ """Restore protected content."""
143
+ restored = text
144
+ for placeholder, original in placeholders.items():
145
+ restored = restored.replace(placeholder, original)
146
+ return restored
147
+
148
+ def _handle_abbreviations(self, text: str) -> str:
149
+ """Handle abbreviations to prevent incorrect sentence splitting."""
150
+ def replace_abbrev(match: re.Match) -> str:
151
+ abbr = match.group().lower().rstrip('.')
152
+ if abbr in self.all_abbreviations:
153
+ return match.group().replace('.', '__DOT__')
154
+ return match.group()
155
+
156
+ return self.ABBREV_PATTERN.sub(replace_abbrev, text)
157
+
158
+ def _normalize_whitespace(self, text: str) -> str:
159
+ """Normalize whitespace while preserving paragraph breaks."""
160
+ # Replace multiple newlines with special marker
161
+ text = re.sub(r'\n\s*\n', ' __PARA__ ', text)
162
+ # Normalize remaining whitespace
163
+ text = re.sub(r'\s+', ' ', text)
164
+ return text.strip()
165
+
166
+ def _restore_formatting(self, sentences: List[str]) -> List[str]:
167
+ """Restore original formatting and clean up sentences."""
168
+ restored = []
169
+ for sentence in sentences:
170
+ # Restore dots in abbreviations
171
+ sentence = sentence.replace('__DOT__', '.')
172
+
173
+ # Restore paragraph breaks
174
+ sentence = sentence.replace('__PARA__', '\n\n')
175
+
176
+ # Clean up whitespace
177
+ sentence = re.sub(r'\s+', ' ', sentence).strip()
178
+
179
+ # Capitalize first letter if it's lowercase and not an abbreviation
180
+ words = sentence.split()
181
+ if words and words[0].lower() not in self.all_abbreviations:
182
+ sentence = sentence[0].upper() + sentence[1:]
183
+
184
+ if sentence:
185
+ restored.append(sentence)
186
+
187
+ return restored
188
+
189
+ def tokenize(self, text: str) -> List[str]:
190
+ """
191
+ Split text into sentences while handling complex cases.
192
+
193
+ Args:
194
+ text (str): Input text to split into sentences.
195
+
196
+ Returns:
197
+ List[str]: List of properly formatted sentences.
198
+ """
199
+ if not text or not text.strip():
200
+ return []
201
+
202
+ # Step 1: Protect special cases
203
+ protected_text, placeholders = self._protect_special_cases(text)
204
+
205
+ # Step 2: Normalize whitespace
206
+ protected_text = self._normalize_whitespace(protected_text)
207
+
208
+ # Step 3: Handle abbreviations
209
+ protected_text = self._handle_abbreviations(protected_text)
210
+
211
+ # Step 4: Split into potential sentences
212
+ potential_sentences = self.SENTENCE_END.split(protected_text)
213
+
214
+ # Step 5: Process and restore formatting
215
+ sentences = self._restore_formatting(potential_sentences)
216
+
217
+ # Step 6: Restore special cases
218
+ sentences = [self._restore_special_cases(s, placeholders) for s in sentences]
219
+
220
+ # Step 7: Post-process sentences
221
+ final_sentences = []
222
+ current_sentence = []
223
+
224
+ for sentence in sentences:
225
+ # Skip empty sentences
226
+ if not sentence.strip():
227
+ continue
228
+
229
+ # Check if sentence might be continuation of previous
230
+ if current_sentence and sentence[0].islower():
231
+ current_sentence.append(sentence)
232
+ else:
233
+ if current_sentence:
234
+ final_sentences.append(' '.join(current_sentence))
235
+ current_sentence = [sentence]
236
+
237
+ # Add last sentence if exists
238
+ if current_sentence:
239
+ final_sentences.append(' '.join(current_sentence))
240
+
241
+ return final_sentences
242
+
243
+
244
+ def split_sentences(text: str) -> List[str]:
245
+ """
246
+ Convenience function to split text into sentences using SentenceTokenizer.
247
+
248
+ Args:
249
+ text (str): Input text to split into sentences.
250
+
251
+ Returns:
252
+ List[str]: List of properly formatted sentences.
253
+ """
254
+ tokenizer = SentenceTokenizer()
255
+ return tokenizer.tokenize(text)
256
+
257
+
258
+ if __name__ == "__main__":
259
+ # Test text with various challenging cases
260
+ test_text: str = """
261
+ Dr. Smith (Ph.D., M.D.) visited Washington D.C. on Jan. 20, 2024! He met with Prof. Johnson at 3:30 p.m.
262
+ They discussed A.I. and machine learning... "What about the U.S. market?" asked Dr. Smith.
263
+ The meeting ended at 5 p.m. Later, they went to Mr. Wilson's house (located at 123 Main St.) for dinner.
264
+
265
+ Visit our website at https://www.example.com or email us at test@example.com!
266
+ The temperature was 72.5°F (22.5°C). The company's Q3 2023 revenue was $12.5M USD.
267
+
268
+ 「これは日本語の文章です。」This is a mixed-language text! How cool is that?
269
+
270
+ Some technical specs: CPU: 3.5GHz, RAM: 16GB, Storage: 2TB SSD.
271
+ Common abbreviations: etc., i.e., e.g., vs., cf., approx. 100 units.
272
+ """
273
+
274
+ # Process and print each sentence
275
+ sentences: List[str] = split_sentences(test_text)
276
+ print("Detected sentences:")
277
+ print("-" * 80)
278
+ for i, sentence in enumerate(sentences, 1):
279
+ print(f"{i}. {sentence}")
280
+ print("-" * 80)
@@ -1,117 +1,117 @@
1
- import requests
2
- import json
3
- import time
4
- from pathlib import Path
5
- from typing import Generator
6
- from playsound import playsound
7
- from webscout import exceptions
8
- from webscout.AIbase import TTSProvider
9
-
10
- class Voicepods(TTSProvider):
11
- """
12
- A class to interact with the Voicepods text-to-speech API.
13
- """
14
-
15
- def __init__(self, timeout: int = 20, proxies: dict = None):
16
- """
17
- Initializes the Voicepods API client.
18
- """
19
- self.api_endpoint = "https://voicepods-stream.vercel.app/api/resemble"
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
- 'DNT': '1',
26
- 'Origin': 'https://voicepods-stream.vercel.app',
27
- 'Referer': 'https://voicepods-stream.vercel.app/',
28
- 'Sec-CH-UA': '"Chromium";v="128", "Not;A=Brand";v="24", "Microsoft Edge";v="128"',
29
- 'Sec-CH-UA-Mobile': '?0',
30
- 'Sec-CH-UA-Platform': '"Windows"',
31
- 'Sec-Fetch-Dest': 'empty',
32
- 'Sec-Fetch-Mode': 'cors',
33
- 'Sec-Fetch-Site': 'same-origin',
34
- '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',
35
- }
36
- self.session = requests.Session()
37
- self.session.headers.update(self.headers)
38
- if proxies:
39
- self.session.proxies.update(proxies)
40
- self.timeout = timeout
41
- self.audio_cache_dir = Path("./audio_cache")
42
-
43
- def tts(self, text: str) -> str:
44
- """
45
- Converts text to speech using the Voicepods API.
46
-
47
- Args:
48
- text (str): The text to be converted to speech.
49
-
50
- Returns:
51
- str: The filename of the saved audio file.
52
-
53
- Raises:
54
- exceptions.FailedToGenerateResponseError: If there is an error generating or saving the audio.
55
- """
56
- payload = json.dumps({"query": text})
57
- filename = self.audio_cache_dir / f"{int(time.time())}.wav" # Using timestamp for filename
58
-
59
- try:
60
- response = self.session.post(self.api_endpoint, data=payload, timeout=self.timeout)
61
- response.raise_for_status()
62
-
63
- content_type = response.headers.get('Content-Type', '')
64
- if 'audio' not in content_type.lower():
65
- raise ValueError(f"Unexpected content type: {content_type}")
66
-
67
- audio_data = response.content
68
- self._save_audio(audio_data, filename)
69
- return filename.as_posix() # Return the filename as a string
70
-
71
- except requests.exceptions.RequestException as e:
72
- raise exceptions.FailedToGenerateResponseError(f"Error generating audio: {e}")
73
-
74
- def _save_audio(self, audio_data: bytes, filename: Path):
75
- """Saves the audio data to a WAV file in the audio cache directory."""
76
- try:
77
- # Create the audio_cache directory if it doesn't exist
78
- self.audio_cache_dir.mkdir(parents=True, exist_ok=True)
79
-
80
- riff_start = audio_data.find(b'RIFF')
81
- if riff_start == -1:
82
- raise ValueError("RIFF header not found in audio data")
83
-
84
- trimmed_audio_data = audio_data[riff_start:]
85
-
86
- with open(filename, "wb") as f:
87
- f.write(trimmed_audio_data)
88
-
89
- except Exception as e:
90
- raise exceptions.FailedToGenerateResponseError(f"Error saving audio: {e}")
91
-
92
- def play_audio(self, filename: str):
93
- """
94
- Plays an audio file using playsound.
95
-
96
- Args:
97
- filename (str): The path to the audio file.
98
-
99
- Raises:
100
- RuntimeError: If there is an error playing the audio.
101
- """
102
- try:
103
- playsound(filename)
104
- except Exception as e:
105
- raise RuntimeError(f"Error playing audio: {e}")
106
-
107
- # Example usage
108
- if __name__ == "__main__":
109
-
110
- voicepods = Voicepods()
111
- text = "Hello, this is a test of the Voicepods text-to-speech system."
112
-
113
- print("Generating audio...")
114
- audio_file = voicepods.tts(text)
115
-
116
- print("Playing audio...")
1
+ import requests
2
+ import json
3
+ import time
4
+ from pathlib import Path
5
+ from typing import Generator
6
+ from playsound import playsound
7
+ from webscout import exceptions
8
+ from webscout.AIbase import TTSProvider
9
+
10
+ class Voicepods(TTSProvider):
11
+ """
12
+ A class to interact with the Voicepods text-to-speech API.
13
+ """
14
+
15
+ def __init__(self, timeout: int = 20, proxies: dict = None):
16
+ """
17
+ Initializes the Voicepods API client.
18
+ """
19
+ self.api_endpoint = "https://voicepods-stream.vercel.app/api/resemble"
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
+ 'DNT': '1',
26
+ 'Origin': 'https://voicepods-stream.vercel.app',
27
+ 'Referer': 'https://voicepods-stream.vercel.app/',
28
+ 'Sec-CH-UA': '"Chromium";v="128", "Not;A=Brand";v="24", "Microsoft Edge";v="128"',
29
+ 'Sec-CH-UA-Mobile': '?0',
30
+ 'Sec-CH-UA-Platform': '"Windows"',
31
+ 'Sec-Fetch-Dest': 'empty',
32
+ 'Sec-Fetch-Mode': 'cors',
33
+ 'Sec-Fetch-Site': 'same-origin',
34
+ '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',
35
+ }
36
+ self.session = requests.Session()
37
+ self.session.headers.update(self.headers)
38
+ if proxies:
39
+ self.session.proxies.update(proxies)
40
+ self.timeout = timeout
41
+ self.audio_cache_dir = Path("./audio_cache")
42
+
43
+ def tts(self, text: str) -> str:
44
+ """
45
+ Converts text to speech using the Voicepods API.
46
+
47
+ Args:
48
+ text (str): The text to be converted to speech.
49
+
50
+ Returns:
51
+ str: The filename of the saved audio file.
52
+
53
+ Raises:
54
+ exceptions.FailedToGenerateResponseError: If there is an error generating or saving the audio.
55
+ """
56
+ payload = json.dumps({"query": text})
57
+ filename = self.audio_cache_dir / f"{int(time.time())}.wav" # Using timestamp for filename
58
+
59
+ try:
60
+ response = self.session.post(self.api_endpoint, data=payload, timeout=self.timeout)
61
+ response.raise_for_status()
62
+
63
+ content_type = response.headers.get('Content-Type', '')
64
+ if 'audio' not in content_type.lower():
65
+ raise ValueError(f"Unexpected content type: {content_type}")
66
+
67
+ audio_data = response.content
68
+ self._save_audio(audio_data, filename)
69
+ return filename.as_posix() # Return the filename as a string
70
+
71
+ except requests.exceptions.RequestException as e:
72
+ raise exceptions.FailedToGenerateResponseError(f"Error generating audio: {e}")
73
+
74
+ def _save_audio(self, audio_data: bytes, filename: Path):
75
+ """Saves the audio data to a WAV file in the audio cache directory."""
76
+ try:
77
+ # Create the audio_cache directory if it doesn't exist
78
+ self.audio_cache_dir.mkdir(parents=True, exist_ok=True)
79
+
80
+ riff_start = audio_data.find(b'RIFF')
81
+ if riff_start == -1:
82
+ raise ValueError("RIFF header not found in audio data")
83
+
84
+ trimmed_audio_data = audio_data[riff_start:]
85
+
86
+ with open(filename, "wb") as f:
87
+ f.write(trimmed_audio_data)
88
+
89
+ except Exception as e:
90
+ raise exceptions.FailedToGenerateResponseError(f"Error saving audio: {e}")
91
+
92
+ def play_audio(self, filename: str):
93
+ """
94
+ Plays an audio file using playsound.
95
+
96
+ Args:
97
+ filename (str): The path to the audio file.
98
+
99
+ Raises:
100
+ RuntimeError: If there is an error playing the audio.
101
+ """
102
+ try:
103
+ playsound(filename)
104
+ except Exception as e:
105
+ raise RuntimeError(f"Error playing audio: {e}")
106
+
107
+ # Example usage
108
+ if __name__ == "__main__":
109
+
110
+ voicepods = Voicepods()
111
+ text = "Hello, this is a test of the Voicepods text-to-speech system."
112
+
113
+ print("Generating audio...")
114
+ audio_file = voicepods.tts(text)
115
+
116
+ print("Playing audio...")
117
117
  voicepods.play_audio(audio_file)
@@ -2,6 +2,8 @@ import requests
2
2
  from requests.exceptions import RequestException
3
3
  from typing import Any, Dict
4
4
  from webscout.AIutel import Conversation, Optimizers
5
+ from webscout.litagent import LitAgent
6
+ from webscout.prompt_manager import AwesomePrompts
5
7
 
6
8
  class TeachAnything:
7
9
  """
@@ -54,15 +56,26 @@ class TeachAnything:
54
56
  "content-type": "application/json",
55
57
  "origin": "https://www.teach-anything.com",
56
58
  "referer": "https://www.teach-anything.com/",
57
- "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0",
59
+ "user-agent": LitAgent().random(),
58
60
  }
61
+ self.__available_optimizers = (
62
+ method
63
+ for method in dir(Optimizers)
64
+ if callable(getattr(Optimizers, method)) and not method.startswith("__")
65
+ )
59
66
  self.session.headers.update(self.headers)
67
+ Conversation.intro = (
68
+ AwesomePrompts().get_act(
69
+ act, raise_not_found=True, default=None, case_insensitive=True
70
+ )
71
+ if act
72
+ else intro or Conversation.intro
73
+ )
60
74
  self.conversation = Conversation(
61
75
  is_conversation, self.max_tokens_to_sample, filepath, update_file
62
76
  )
63
77
  self.conversation.history_offset = history_offset
64
78
  self.session.proxies = proxies
65
-
66
79
  def ask(
67
80
  self,
68
81
  prompt: str,
@@ -1,4 +1,3 @@
1
-
2
1
  from uuid import uuid4
3
2
  from re import findall
4
3
  import json
@@ -12,12 +11,41 @@ from typing import Any, AsyncGenerator, Dict
12
11
 
13
12
  import cloudscraper
14
13
 
15
-
16
14
  class YouChat(Provider):
17
15
  """
18
16
  This class provides methods for interacting with the You.com chat API in a consistent provider structure.
19
17
  """
20
18
 
19
+ AVAILABLE_MODELS = [
20
+ "openai_o1",
21
+ "openai_o1_mini",
22
+ "gpt_4o_mini",
23
+ "gpt_4o",
24
+ "gpt_4_turbo",
25
+ "gpt_4",
26
+ "claude_3_5_sonnet",
27
+ "claude_3_opus",
28
+ "claude_3_sonnet",
29
+ "claude_3_5_haiku",
30
+ "claude_3_haiku",
31
+ "llama3_3_70b",
32
+ "llama3_2_90b",
33
+ "llama3_2_11b",
34
+ "llama3_1_405b",
35
+ "llama3_1_70b",
36
+ "llama3",
37
+ "mistral_large_2",
38
+ "gemini_1_5_flash",
39
+ "gemini_1_5_pro",
40
+ "databricks_dbrx_instruct",
41
+ "qwen2p5_72b",
42
+ "qwen2p5_coder_32b",
43
+ "command_r",
44
+ "command_r_plus",
45
+ "solar_1_mini",
46
+ "dolphin_2_5"
47
+ ]
48
+
21
49
  def __init__(
22
50
  self,
23
51
  is_conversation: bool = True,
@@ -29,6 +57,7 @@ class YouChat(Provider):
29
57
  proxies: dict = {},
30
58
  history_offset: int = 10250,
31
59
  act: str = None,
60
+ model: str = "claude_3_5_haiku", # Default model set to claude_3_5_haiku
32
61
  ):
33
62
  """Instantiates YouChat
34
63
 
@@ -42,7 +71,11 @@ class YouChat(Provider):
42
71
  proxies (dict, optional): Http request proxies. Defaults to {}.
43
72
  history_offset (int, optional): Limit conversation history to this number of last texts. Defaults to 10250.
44
73
  act (str|int, optional): Awesome prompt key or index. (Used as intro). Defaults to None.
74
+ model (str, optional): Model to use. Defaults to "claude_3_5_haiku".
45
75
  """
76
+ if model not in self.AVAILABLE_MODELS:
77
+ raise ValueError(f"Invalid model: {model}. Choose from: {self.AVAILABLE_MODELS}")
78
+
46
79
  self.session = cloudscraper.create_scraper() # Create a Cloudscraper session
47
80
  self.is_conversation = is_conversation
48
81
  self.max_tokens_to_sample = max_tokens
@@ -50,6 +83,7 @@ class YouChat(Provider):
50
83
  self.stream_chunk_size = 64
51
84
  self.timeout = timeout
52
85
  self.last_response = {}
86
+ self.model = model
53
87
  self.headers = {
54
88
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0",
55
89
  "Accept": "text/event-stream",
@@ -123,18 +157,18 @@ class YouChat(Provider):
123
157
 
124
158
  payload = {
125
159
  "q": conversation_prompt,
126
- "page": 1,
127
- "count": 10,
160
+ "page": 2,
161
+ "count": 20,
128
162
  "safeSearch": "Moderate",
129
163
  "mkt": "en-IN",
130
164
  "domain": "youchat",
131
- "use_personalization_extraction": "true",
165
+ "use_personalization_extraction": "false",
132
166
  "queryTraceId": str(uuid4()),
133
167
  "chatId": str(uuid4()),
134
168
  "conversationTurnId": str(uuid4()),
135
169
  "pastChatLength": 0,
136
170
  "isSmallMediumDevice": "true",
137
- "selectedChatMode": "default",
171
+ "selectedChatMode": self.model, # Use the selected model
138
172
  "traceId": str(uuid4()),
139
173
  "chat": "[]"
140
174
  }
@@ -224,6 +258,6 @@ class YouChat(Provider):
224
258
  if __name__ == '__main__':
225
259
  from rich import print
226
260
  ai = YouChat(timeout=5000)
227
- response = ai.chat("Who is Abhay Koul in AI?", stream=True)
261
+ response = ai.chat("hi", stream=True)
228
262
  for chunk in response:
229
- print(chunk, end="", flush=True)
263
+ print(chunk, end="", flush=True)