Last active
April 11, 2020 17:33
-
-
Save sadimanna/eafa633f27f88cafc5228210bfd73731 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
access_token = '***ENTER YOUR ACCESS TOKEN HERE***' | |
class botCallback(tf.keras.callbacks.Callback): | |
def __init__(self,access_token): | |
self.access_token = access_token | |
self.ping_url = 'https://api.telegram.org/bot'+str(self.access_token)+'/getUpdates' | |
self.response = requests.get(self.ping_url).json() | |
self.chat_id = self.response['result'][0]['message']['chat']['id'] | |
def send_message(self,message): | |
self.ping_url = 'https://api.telegram.org/bot'+str(self.access_token)+'/sendMessage?'+\ | |
'chat_id='+str(self.chat_id)+\ | |
'&parse_mode=Markdown'+\ | |
'&text='+message | |
self.response = requests.get(self.ping_url) | |
def send_photo(self,filepath): | |
file_ = open(filepath,'rb') | |
file_dict = {'photo':file_} | |
self.ping_url = 'https://api.telegram.org/bot'+str(self.access_token)+'/sendPhoto?'+\ | |
'chat_id='+str(self.chat_id) | |
self.response = requests.post(self.ping_url,files = file_dict) | |
file_.close() | |
def on_train_batch_begin(self, batch, logs=None): | |
pass | |
def on_train_batch_end(self, batch, logs=None): | |
message = ' Iteration/Batch {}\n Training Accuracy : {:7.2f}\n Training Loss : {:7.2f}\n'.format(batch,logs['accuracy'],logs['loss']) | |
message += ' Validation Accuracy : {:7.2f}\n Validation Loss : {:7.2f}\n'.format(logs['val_accuracy'],logs['val_loss']) | |
self.send_message(message) | |
def on_test_batch_begin(self, batch, logs=None): | |
pass | |
def on_test_batch_end(self, batch, logs=None): | |
message = ' Iteration/Batch {}\n Training Accuracy : {:7.2f}\n Training Loss : {:7.2f}\n'.format(batch,logs['accuracy'],logs['loss']) | |
message += ' Validation Accuracy : {:7.2f}\n Validation Loss : {:7.2f}\n'.format(logs['val_accuracy'],logs['val_loss']) | |
self.send_message(message) | |
def on_epoch_begin(self, epoch, logs=None): | |
pass | |
def on_epoch_end(self, epoch, logs=None): | |
message = ' Epoch {}\n Training Accuracy : {:7.2f}\n Training Loss : {:7.2f}\n'.format(epoch,logs['accuracy'],logs['loss']) | |
message += ' Validation Accuracy : {:7.2f}\n Validation Loss : {:7.2f}\n'.format(logs['val_accuracy'],logs['val_loss']) | |
self.send_message(message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment