Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.17 KB | None | 0 0
  1. import requests, json
  2. import datetime as dt
  3. import errno
  4. import uuid
  5. import subprocess
  6.  
  7.  
  8.  
  9. def uID():
  10.     # generate randomrandomrandomrandomrandomrandomrandomrandom numbers for unique user
  11.     randomid = str(uuid.uuid1()).split('-')[4]
  12.     file = open("unique_id.txt", "w")
  13.     file.write(randomid)
  14.     file.write('\n')
  15.     file.close()
  16.     print("Your model's unique ID is --- ", randomod)
  17.     print('Use the ID to verify the model via NightCrawler app.')
  18.  
  19.  
  20.  
  21.  
  22. def teller(iteration='default', itercount='default', maxiter='default', maxepoch='default', epoch='default', trainloss='default', testloss='default',acc='default'):
  23.  
  24.     '''
  25.  
  26.        $iteration argument is for counting iterations. type = int.
  27.  
  28.        $itercount argument is basically a divider, for every how many iterations do you need to update information in the app. type = int.
  29.  
  30.        $maxiter is a maximum of iterations, after which the model finishes training. Make sure to send +1, as long as
  31.        python takes the 'y' from range(x , y) and finishes the loop when technically y = (y - 1). type = int.
  32.  
  33.        $maxepoch is amount of epochs you're shooting for
  34.  
  35.        $epoch counts epochs. type = int.
  36.  
  37.        $trainloss takes train loss as an information. type = float.
  38.  
  39.        $testloss takes test loss as an information. type = float.
  40.        
  41.        $acc takes accuracy as an information. type=float
  42.  
  43.  
  44.    '''
  45.     try:
  46.         f = open("unique_id.txt", "r")
  47.         random = f.read()
  48.  
  49.     except FileNotFoundError:
  50.         subprocess.run('rm unique_id.txt', shell=True)
  51.         print("Unique ID file not found.")
  52.  
  53.     if iteration % itercount == 0:
  54.         r = requests.post("https://nightcrawlerr.herokuapp.com/sendModelData", data= {'Iteration':iteration, 'Maxiter':maxiter, 'Epoch':epoch, 'MaxEpoch':maxepoch, 'Train Loss':trainloss, 'Test Loss':testloss, 'Accuracy':acc, 'ID':random})
  55.     else:
  56.         print("You're not passing Iteration, Distribution and Maxiter variables correctly. Requests won't be sent.")
  57.  
  58. if __name__ == '__main__':
  59.     import requests, json
  60.     import datetime as dt
  61.     from time import sleep
  62.     import random as r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement