Spaces:
Paused
Paused
Update webscout.py
Browse files- webscout.py +49 -1
webscout.py
CHANGED
|
@@ -27,6 +27,13 @@ from math import atan2, cos, radians, sin, sqrt
|
|
| 27 |
from typing import Any, Dict, List, Union
|
| 28 |
from urllib.parse import unquote
|
| 29 |
import orjson
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
REGEX_STRIP_TAGS = re.compile("<.*?>")
|
|
@@ -1640,4 +1647,45 @@ class transcriber(object):
|
|
| 1640 |
raise CookiesInvalidError(video_id)
|
| 1641 |
return cookie_jar
|
| 1642 |
except:
|
| 1643 |
-
raise CookiePathInvalidError(video_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
from typing import Any, Dict, List, Union
|
| 28 |
from urllib.parse import unquote
|
| 29 |
import orjson
|
| 30 |
+
import requests
|
| 31 |
+
import base64
|
| 32 |
+
from typing import List, Dict, Union
|
| 33 |
+
import json
|
| 34 |
+
import requests
|
| 35 |
+
import base64
|
| 36 |
+
from typing import List, Dict, Union
|
| 37 |
|
| 38 |
|
| 39 |
REGEX_STRIP_TAGS = re.compile("<.*?>")
|
|
|
|
| 1647 |
raise CookiesInvalidError(video_id)
|
| 1648 |
return cookie_jar
|
| 1649 |
except:
|
| 1650 |
+
raise CookiePathInvalidError(video_id)
|
| 1651 |
+
|
| 1652 |
+
class LLM:
|
| 1653 |
+
def __init__(self, model: str, system_message: str = "You are a Helpful AI."):
|
| 1654 |
+
self.model = model
|
| 1655 |
+
self.conversation_history = [{"role": "system", "content": system_message}]
|
| 1656 |
+
|
| 1657 |
+
def chat(self, messages: List[Dict[str, str]]) -> Union[str, None]:
|
| 1658 |
+
url = "https://api.deepinfra.com/v1/openai/chat/completions"
|
| 1659 |
+
headers = {
|
| 1660 |
+
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
|
| 1661 |
+
'Accept-Language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
|
| 1662 |
+
'Cache-Control': 'no-cache',
|
| 1663 |
+
'Connection': 'keep-alive',
|
| 1664 |
+
'Content-Type': 'application/json',
|
| 1665 |
+
'Origin': 'https://deepinfra.com',
|
| 1666 |
+
'Pragma': 'no-cache',
|
| 1667 |
+
'Referer': 'https://deepinfra.com/',
|
| 1668 |
+
'Sec-Fetch-Dest': 'empty',
|
| 1669 |
+
'Sec-Fetch-Mode': 'cors',
|
| 1670 |
+
'Sec-Fetch-Site': 'same-site',
|
| 1671 |
+
'X-Deepinfra-Source': 'web-embed',
|
| 1672 |
+
'accept': 'text/event-stream',
|
| 1673 |
+
'sec-ch-ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
|
| 1674 |
+
'sec-ch-ua-mobile': '?0',
|
| 1675 |
+
'sec-ch-ua-platform': '"macOS"'
|
| 1676 |
+
}
|
| 1677 |
+
data = json.dumps(
|
| 1678 |
+
{
|
| 1679 |
+
'model': self.model,
|
| 1680 |
+
'messages': messages,
|
| 1681 |
+
'temperature': 0.7,
|
| 1682 |
+
'max_tokens': 8028,
|
| 1683 |
+
'stop': [],
|
| 1684 |
+
'stream': False #dont change it
|
| 1685 |
+
}, separators=(',', ':')
|
| 1686 |
+
)
|
| 1687 |
+
try:
|
| 1688 |
+
result = requests.post(url=url, data=data, headers=headers)
|
| 1689 |
+
return result.json()['choices'][0]['message']['content']
|
| 1690 |
+
except:
|
| 1691 |
+
return None
|