linter+fmt
This commit is contained in:
parent
eff5cdb394
commit
21591df427
|
@ -7,7 +7,6 @@ import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_newcomer_message(msg):
|
def get_newcomer_message(msg):
|
||||||
lang = msg["from"].get("language_code", "ru")
|
lang = msg["from"].get("language_code", "ru")
|
||||||
r = "хочет присоединиться к нам здесь" if lang == "ru" else " wants to join us here"
|
r = "хочет присоединиться к нам здесь" if lang == "ru" else " wants to join us here"
|
||||||
|
|
|
@ -8,7 +8,6 @@ from utils.mention import mention
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
positive_reactions = [
|
positive_reactions = [
|
||||||
"👍",
|
"👍",
|
||||||
"❤",
|
"❤",
|
||||||
|
|
|
@ -11,7 +11,6 @@ from nlp.toxicity_detector import detector
|
||||||
logger = logging.getLogger("handlers.messages_routing")
|
logger = logging.getLogger("handlers.messages_routing")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def messages_routing(msg, state):
|
async def messages_routing(msg, state):
|
||||||
cid = msg["chat"]["id"]
|
cid = msg["chat"]["id"]
|
||||||
uid = msg["from"]["id"]
|
uid = msg["from"]["id"]
|
||||||
|
@ -53,13 +52,13 @@ async def messages_routing(msg, state):
|
||||||
# count average between all of messages
|
# count average between all of messages
|
||||||
toxic_pattern = f"toxic:{cid}:{uid}:*"
|
toxic_pattern = f"toxic:{cid}:{uid}:*"
|
||||||
toxic_score = await get_average_pattern(toxic_pattern)
|
toxic_score = await get_average_pattern(toxic_pattern)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# current mesasage toxicity
|
# current mesasage toxicity
|
||||||
if reply_to_msg_id:
|
if reply_to_msg_id:
|
||||||
one_score = await redis.get(f"toxic:{cid}:{uid}:{reply_to_msg_id}")
|
one_score = await redis.get(f"toxic:{cid}:{uid}:{reply_to_msg_id}")
|
||||||
reply_text = ''
|
reply_text = ""
|
||||||
if one_score:
|
if one_score:
|
||||||
logger.debug(one_score)
|
logger.debug(one_score)
|
||||||
reply_text += f"{int(one_score)}% токсичности\n"
|
reply_text += f"{int(one_score)}% токсичности\n"
|
||||||
|
@ -75,7 +74,9 @@ async def messages_routing(msg, state):
|
||||||
if toxic_score > 20
|
if toxic_score > 20
|
||||||
else "😇"
|
else "😇"
|
||||||
)
|
)
|
||||||
reply_text += "Средняя токсичность сообщений: {toxic_score}% {emoji}"
|
reply_text += (
|
||||||
|
f"Средняя токсичность сообщений: {toxic_score}% {emoji}"
|
||||||
|
)
|
||||||
if reply_text:
|
if reply_text:
|
||||||
await telegram_api(
|
await telegram_api(
|
||||||
"sendMessage",
|
"sendMessage",
|
||||||
|
@ -85,12 +86,12 @@ async def messages_routing(msg, state):
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
await telegram_api("deleteMessage", chat_id=cid, message_id=mid)
|
await telegram_api("deleteMessage", chat_id=cid, message_id=mid)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
elif text == "/removed@welcomecenter_bot":
|
elif text == "/removed@welcomecenter_bot":
|
||||||
try:
|
try:
|
||||||
await telegram_api("deleteMessage", chat_id=cid, message_id=mid)
|
await telegram_api("deleteMessage", chat_id=cid, message_id=mid)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
toxic_score = detector(text)
|
toxic_score = detector(text)
|
||||||
|
@ -103,7 +104,7 @@ async def messages_routing(msg, state):
|
||||||
await redis.set(f"removed:{uid}:{cid}:{mid}", text)
|
await redis.set(f"removed:{uid}:{cid}:{mid}", text)
|
||||||
try:
|
try:
|
||||||
await telegram_api("deleteMessage", chat_id=cid, message_id=mid)
|
await telegram_api("deleteMessage", chat_id=cid, message_id=mid)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
await telegram_api(
|
await telegram_api(
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
import torch
|
import torch
|
||||||
from transformers import ByT5Tokenizer, T5ForConditionalGeneration
|
from transformers import ByT5Tokenizer, T5ForConditionalGeneration
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger("nlp.normalize")
|
||||||
|
|
||||||
# Use ByT5 for the ByT5 model
|
# Use ByT5 for the ByT5 model
|
||||||
tokenizer = ByT5Tokenizer.from_pretrained("google/byt5-small")
|
tokenizer = ByT5Tokenizer.from_pretrained("google/byt5-small")
|
||||||
|
@ -48,8 +51,8 @@ def normalize(text):
|
||||||
|
|
||||||
if is_russian_wording(t):
|
if is_russian_wording(t):
|
||||||
# Normalize the text by replacing characters
|
# Normalize the text by replacing characters
|
||||||
normalized_text = (t
|
normalized_text = (
|
||||||
.replace("e", "е")
|
t.replace("e", "е")
|
||||||
.replace("o", "о")
|
.replace("o", "о")
|
||||||
.replace("x", "х")
|
.replace("x", "х")
|
||||||
.replace("a", "а")
|
.replace("a", "а")
|
||||||
|
@ -73,7 +76,7 @@ def normalize(text):
|
||||||
)
|
)
|
||||||
|
|
||||||
return normalized_text
|
return normalized_text
|
||||||
logger.debug('normalized: ', t)
|
logger.debug("normalized: ", t)
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import logging
|
||||||
logger = logging.getLogger("state.redis")
|
logger = logging.getLogger("state.redis")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RedisService:
|
class RedisService:
|
||||||
def __init__(self, uri=REDIS_URL):
|
def __init__(self, uri=REDIS_URL):
|
||||||
self._uri: str = uri
|
self._uri: str = uri
|
||||||
|
|
|
@ -6,7 +6,6 @@ import math
|
||||||
logger = logging.getLogger("state.scan")
|
logger = logging.getLogger("state.scan")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def get_all_pattern(uid):
|
async def get_all_pattern(uid):
|
||||||
pattern = f"removed:{uid}:*"
|
pattern = f"removed:{uid}:*"
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Define SVG code generation function with member_id parameter
|
# Define SVG code generation function with member_id parameter
|
||||||
def generate_chart(members, member_id=None):
|
def generate_chart(members, member_id=None):
|
||||||
if not member_id:
|
if not member_id:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user