text
stringlengths
1
93.6k
def _main():
print(f"Classification on {cfg['on_dataset']} dataset!!! class number: {n_class}")
print(f"use MVCNN feature: {cfg['use_mvcnn_feature']}")
print(f"use GVCNN feature: {cfg['use_gvcnn_feature']}")
print(f"use MVCNN feature for structure: {cfg['use_mvcnn_feature_for_structure']}")
print(f"use GVCNN feature for structure: {cfg['use_gvcnn_feature_for_structure']}")
print('Configuration -> Start')
pp.pprint(cfg)
print('Configuration -> End')
model_ft = HGNN(in_ch=fts.shape[1],
n_class=n_class,
n_hid=cfg['n_hid'],
dropout=cfg['drop_out'])
model_ft = model_ft.to(device)
optimizer = optim.Adam(model_ft.parameters(), lr=cfg['lr'],
weight_decay=cfg['weight_decay'])
# optimizer = optim.SGD(model_ft.parameters(), lr=0.01, weight_decay=cfg['weight_decay)
schedular = optim.lr_scheduler.MultiStepLR(optimizer,
milestones=cfg['milestones'],
gamma=cfg['gamma'])
criterion = torch.nn.CrossEntropyLoss()
model_ft = train_model(model_ft, criterion, optimizer, schedular, cfg['max_epoch'], print_freq=cfg['print_freq'])
if __name__ == '__main__':
_main()
# <FILESEP>
import requests
from config import TELEGRAM_SEND_MESSAGE_URL
class TelegramBot:
def __init__(self):
""""
Initializes an instance of the TelegramBot class.
Attributes:
chat_id:str: Chat ID of Telegram chat, used to identify which conversation outgoing messages should be send to.
text:str: Text of Telegram chat
first_name:str: First name of the user who sent the message
last_name:str: Last name of the user who sent the message
"""
self.chat_id = None
self.text = None
self.first_name = None
self.last_name = None
def parse_webhook_data(self, data):
"""
Parses Telegram JSON request from webhook and sets fields for conditional actions
Args:
data:str: JSON string of data
"""
message = data['message']
self.chat_id = message['chat']['id']
self.incoming_message_text = message['text'].lower()
self.first_name = message['from']['first_name']
self.last_name = message['from']['last_name']
def action(self):
"""
Conditional actions based on set webhook data.
Returns:
bool: True if the action was completed successfully else false
"""
success = None
if self.incoming_message_text == '/hello':
self.outgoing_message_text = "Hello {} {}!".format(self.first_name, self.last_name)
success = self.send_message()
if self.incoming_message_text == '/rad':
self.outgoing_message_text = '🤙'
success = self.send_message()
return success
def send_message(self):
"""
Sends message to Telegram servers.
"""
res = requests.get(TELEGRAM_SEND_MESSAGE_URL.format(self.chat_id, self.outgoing_message_text))
return True if res.status_code == 200 else False