Skip to content

Commit

Permalink
Add app callback
Browse files Browse the repository at this point in the history
  • Loading branch information
EderSantana committed Oct 9, 2015
1 parent 19f54df commit dc474fa
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions agnez/app_callbacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
import requests
import mpld3

from keras.callbacks import Callback
from imgurpython import ImgurClient


class ImgurUploader(Callback):
def __init__(self, generate_img, name='img', position=1, app_url='http://localhost:3000'):
super(ImgurUploader, self).__init__()
self.client_secret = os.environ['IMGUR_SECRET']
self.client_id = os.environ['IMGUR_ID']
self.client = ImgurClient(self.client_id, self.client_secret)
self.app_url = app_url
self.name = name
self.position = position
self.generate_img = generate_img

def on_epoch_end(self, epoch=None, logs={}):
img = self.generate_img()
res = self.client_upload_from_path(img)
return requests.patch(self.app_url, json={
'name': self.name, 'type': 'img', 'value': res['link'],
'pos': self.position})


class PlotHtml(Callback):
def __init__(self, generate_plot, name='plot', position=0, app_url='http://localhost:3000'):
super(PlotHtml, self).__init__()
self.app_url = app_url
self.name = name
self.position = position
self.generate_plot = generate_plot

def on_epoch_end(self, epoch=None, logs={}):
fig = self.generate_plot()
html = mpld3.fig_to_html(fig)
return requests.patch(self.app_url, json={
'name': self.name, 'type': 'html', 'value': html,
'pos': self.position})

0 comments on commit dc474fa

Please sign in to comment.