text
stringlengths
1
93.6k
cmc_pool = all_cmc_pool/10
mAP_pool = all_mAP_pool/10
mINP_pool = all_mINP_pool/10
print('All Average:')
print('POOL: Rank-1: {:.2%} | Rank-5: {:.2%} | Rank-10: {:.2%}| Rank-20: {:.2%}| mAP: {:.2%}| mINP: {:.2%}'.format(
cmc_pool[0], cmc_pool[4], cmc_pool[9], cmc_pool[19], mAP_pool, mINP_pool))
# <FILESEP>
import os
import polars as pl
from transformers import GPT2TokenizerFast
from tqdm import tqdm
def parse(include: "list[str]" = None) -> None:
texts: "list[str]" = []
parsed_text: "list[str]" = []
tokenizer = GPT2TokenizerFast.from_pretrained("gpt2")
for root, _, files in os.walk("ai_generated/dumps"):
file_count = sum(len(files) for _, _, files in os.walk("sources"))
with tqdm(total=file_count, desc="Creating dataset") as pbar:
for file in files:
pbar.update(1)
if include and file not in include or '.gitkeep' in file:
continue
with open(os.path.join(root, file), "r", encoding="utf-8") as rf:
for line in rf:
for word in line.split(". "):
if len(tokenizer.encode(" ".join([*texts, *word.split()]))) <= 256:
texts = [*texts, *word.split()]
else:
parsed_text.append(" ".join(texts))
texts = []
texts = [*texts, *word.split()]
parsed_text.append(" ".join(texts))
texts = []
pl.DataFrame({
"file_name": [file.replace("_dump.txt", "")] * len(parsed_text),
"text": parsed_text,
"token_size": [len(tokenizer.encode(x)) for x in parsed_text],
"embed": [None] * len(parsed_text)
}).write_csv(f"ai_generated/data/{file}.csv")
parsed_text = []
print()
if __name__ == '__main__':
parse()
# <FILESEP>
import random
import time
from typing import List
import aiohttp
import json
import asyncio
from aiohttp import ClientWebSocketResponse
class Voice:
token = ''
channel_id = ''
rtp_url = ''
ws_clients: List[ClientWebSocketResponse] = []
wait_handler_msgs = []
is_exit = False
ssrc = 0
def __init__(self, token: str):
self.token = token
self.ws_clients = []
self.wait_handler_msgs = []
async def get_gateway(self, channel_id: str) -> str:
async with aiohttp.ClientSession() as session:
async with session.get(
f'https://www.kaiheila.cn/api/v3/gateway/voice?channel_id={channel_id}',
headers={'Authorization': f'Bot {self.token}'}) as res:
return (await res.json())['data']['gateway_url']
async def connect_ws(self):
gateway = await self.get_gateway(self.channel_id)
print(gateway)
async with aiohttp.ClientSession() as session:
async with session.ws_connect(gateway) as ws:
self.ws_clients.append(ws)
async for msg in ws:
if msg.type == aiohttp.WSMsgType.TEXT:
if len(self.ws_clients
) != 0 and self.ws_clients[0] == ws:
self.wait_handler_msgs.append(msg.data)
elif msg.type == aiohttp.WSMsgType.ERROR:
break
else:
return
async def ws_msg(self):
while True:
if self.is_exit:
return
if len(self.ws_clients) != 0: