def generate_phrase(self, algorithm, params): """Class method to generate Phrase - delegates to Generate. :return: Returns a Phrase object :rtype: Phrase """ self.set_phrase(Generate(algorithm, params).phrase)
def __init__(self, rows, cols, width, height): initgrid=Generate() self.board=initgrid.board self.rows = rows self.cols = cols self.cubes = [[Cube(self.board[i][j], i, j, width, height) for j in range(cols)] for i in range(rows)] self.width = width self.height = height self.model = None self.selected = None
def credentials(): ''' Function to assign username and password ''' generate = Generate() print '[+] Setting credentails' credentials = [ { 'username': '******', 'password': '******' }, #{'username': '******', 'password': ''} ] for credential in credentials: if not credential['password']: credential.update({'password': str(generate.password(6))}) return credentials
def Main(): (major, minor, _, _, _) = sys.version_info if not(major == 2 and minor >= 7): print >> sys.stderr, "This needs at least version 2.7 of python" sys.exit(1) exceptions = readExceptions("mime.exceptions") root = readFile("magic", exceptions) root.pruneTree(exceptions) root.check() if OptDebug: root.printTree() gen = Generate() gen.putRoot(root) gen.writeToFile("mimemagic.c")
#!/usr/bin/python # -*- coding:utf-8 -*- import time from staticblog import app from generate import Generate if __name__ == '__main__': gen = Generate() t = time.time() gen() print('生成完成!!!', time.time() - t) app.run()
data = PrepareData(train) f = open('animal_train.csv', 'wb') for line in data.x: f.write((str(line)).split("[")[1].split("]")[0] + "\n") f.close() print( "Gerando csv detalhado (animal_test.csv) a partir do arquivo test.csv ......................... " ) t = open('animal_test.csv', 'wb') for line in data.PrepareTestFile(test): #f.write((str(line)).split("[")[1].split("]")[0] + "\n") t.write(str(line) + "\n") t.close() print("Trantando dados gerados ......................... ") geracao = Generate(data.x, data.y) if treino != 1: ## TRAIN PREDICT geracao.predict_class(data.x, data.y, "animal_test.csv", epocas, ciclos) if treino == 1: ## RANDOM lines = 0 with open('test.csv', 'rb') as f: for line in f: lines += 1 print("Linhas: ", lines - 1) geracao.random(lines - 1)
from generate import Generate from solve import Solve print(""" =============+ * Suduku * =============+ """) suduku = Generate(Generate.EASY) suduku.generate_grid() suduku.setup_game_grid() print(f" {suduku.failures+1} attemps to generate the grid\n\n") for row in suduku.grid: print("|-----------|-----------|-----------|") print(f"| {' | '.join([str(i) if i != 0 else ' ' for i in row])} |") print("|-----------|-----------|-----------|") print(""" The Game """) for row in suduku.game_grid: print("|-----------|-----------|-----------|") print(f"| {' | '.join([str(i) if i != 0 else ' ' for i in row])} |") print("|-----------|-----------|-----------|")
def generate_text(q, artist): gen = Generate(artist) q.put(gen.generated)
def main(): parser = argparse.ArgumentParser(description='Clip Identification system.') parser.add_argument('inputfile', metavar='file', type=str, nargs='?', help='File to process. If none passed then read from stdin.') parser.add_argument('--sourceid', '-srcid', type=str, required=False, default=None, help='SourceID, if present it\'s added to the Pusher notification (null otherwise).') parser.add_argument('--regionid', '-regid', type=str, required=False, default=None, help='RegionID, if present it\'s added to the Pusher notification (null otherwise).') parser.add_argument('--scheduleid', '-schid', type=str, required=False, default=None, help='ScheduleID, if present it\'s added to the Pusher notification (null otherwise).') parser.add_argument('--programid', '-prgid', type=str, required=False, default=None, help='ProgramID, if present it\'s added to the Pusher notification (null otherwise).') parser.add_argument('--programname', '-pn', type=str, required=False, default=None, help='Program Name, if present it\'s added to the Pusher notification (null otherwise).') parser.add_argument('--logfile', '-log', type=str, help='Log file path. If not defined it will default\ to the tvstation name.log') args=parser.parse_args() if args.inputfile is None: print "Reading from stdin..." recog = Recognize(None, sourceid=args.sourceid, region=args.regionid, programname=args.programname, programid=args.programid, scheduleid=args.scheduleid) recog.recognize() else: print "Reading from file: ", print args.inputfile, print "..." recog = Recognize(args.inputfile, sourceid=args.sourceid, region=args.regionid, programname=args.programname, programid=args.programid, scheduleid=args.scheduleid) recog.recognize() sys.exit(1) if len(sys.argv) == 1: print "Format is \n python main.py -[r/g/l] [labels_file] video_name" raise Exception(INCORRECT_FORMAT_ERROR) elif sys.argv[1] == "-r": # if len(sys.argv) != 3: # print "Format is \n python main.py -[r/g/l] [labels_file] video_name" # raise Exception(INCORRECT_FORMAT_ERROR) # file_type = mimetypes.guess_type(sys.argv[2])[0] # if file_type[:3] != "vid":#The file is not a video file # print "Invalid video file" # raise Exception(INCORRECT_VIDEO_FILE_ERROR) # if len(sys.argv) == 3: print "Recognizing: ", sys.argv[2] recog = Recognize(sys.argv[2]) recog.recognize() if len(sys.argv) == 2: print "Recognizing from stdin" recog = Recognize(None) recog.recognize() else: print "Format is \n python main.py -[r/g/l] [labels_file] video_name" raise Exception(INCORRECT_FORMAT_ERROR) elif sys.argv[1] == "-g": if len(sys.argv) != 4: print "Format is \n python main.py -[r/g/l] [labels_file] video_name" raise Exception(INCORRECT_FORMAT_ERROR) label_file_type = mimetypes.guess_type(sys.argv[2])[0] video_file_type = mimetypes.guess_type(sys.argv[3])[0] if label_file_type[:3] != "tex":#The file is not a labels file print "Invalid labels file" raise Exception(INCORRECT_LABEL_FILE_ERROR) if video_file_type[:3] != "vid":#The file is not a video file print "Invalid video file" raise Exception(INCORRECT_VIDEO_FILE_ERROR) print "Generating db for video: ", sys.argv[3], "\nwith labels file:", sys.argv[2] gen = Generate(sys.argv[2], sys.argv[3]) gen.run() elif sys.argv[1] == "-l": if len(sys.argv) != 4: print "Format is \n python main.py -[r/g/l] [labels_file] video_name" raise Exception(INCORRECT_FORMAT_ERROR) label_file_type = mimetypes.guess_type(sys.argv[2])[0] video_file_type = mimetypes.guess_type(sys.argv[3])[0] if label_file_type[:3] != "tex":#The file is not a labels file return INCORRECT_LABEL_FILE_ERROR if video_file_type[:3] != "vid":#The file is not a video file return INCORRECT_VIDEO_FILE_ERROR print "Learning for video: ", sys.argv[3] video_name = sys.argv[3] ffmpeg.convert_video(video_name) name, extension = video_name[-5:].split('.') name = video_name.split('/')[-1] name = name[:-len(extension)-1] os.system("cp " + sys.argv[2] + " " + WEB_LABELS) os.system("mv " + name + '.webm ' + 'web/output/static/output/' + WEB_VIDEO_NAME) print "Please go to the URL to edit labels" return SUCCESS
y/n on lines once quit, save lines in 'savedlines/' ''' conjunctions = [ 'and', 'but', 'yet', 'or', 'because', 'for', 'nor', 'so', 'rather than', 'as much as' ] compares = [ 'is better than', 'is worse than', 'could never defeat a', 'would win in a fight with a', 'could never f**k a', 'always made me feel like a', 'could never be as good as a' ] createstuff = Generate() createstuff.load_lines() lines = createstuff.lines save_lines = [] for l in lines: os.system("clear") rand_l = random.choice(lines) out_l = l + ' ' + random.choice(compares) + ' ' + rand_l print(out_l, '\n', 'y/n?', '\n')
from generate import Generate Generate()
from flask import Flask, render_template from flask_login import LoginManager from generate import Generate app = Flask(__name__, template_folder='templates') app.config.from_object('config') lm = LoginManager(app) lm.login_view = 'admin.login' lm.login_message = '请先登录,管理员' gen = Generate() # Generate类进行实例化 @app.errorhandler(404) def page_not_found(e): return render_template('404.html'), 404 @app.errorhandler(500) def internal_error(e): return render_template('500.html'), 500 from . import main, api, admin # 在后面导入文件,并且注册蓝图 from .api import api from .admin import admin app.register_blueprint(api, url_prefix='/api') app.register_blueprint(admin, url_prefix='/admin')
def main(): if len(sys.argv) == 1: print "Format is \n python main.py -[r/g/l] [labels_file] video_name" raise Exception(INCORRECT_FORMAT_ERROR) elif sys.argv[1] == "-r": if len(sys.argv) != 3: print "Format is \n python main.py -[r/g/l] [labels_file] video_name" raise Exception(INCORRECT_FORMAT_ERROR) file_type = mimetypes.guess_type(sys.argv[2])[0] if file_type[:3] != "vid": #The file is not a video file print "Invalid video file" raise Exception(INCORRECT_VIDEO_FILE_ERROR) print "Recognizing: ", sys.argv[2] recog = Recognize(sys.argv[2]) recog.recognize() elif sys.argv[1] == "-g": if len(sys.argv) != 4: print "Format is \n python main.py -[r/g/l] [labels_file] video_name" raise Exception(INCORRECT_FORMAT_ERROR) label_file_type = mimetypes.guess_type(sys.argv[2])[0] video_file_type = mimetypes.guess_type(sys.argv[3])[0] if label_file_type[:3] != "tex": #The file is not a labels file print "Invalid labels file" raise Exception(INCORRECT_LABEL_FILE_ERROR) if video_file_type[:3] != "vid": #The file is not a video file print "Invalid video file" raise Exception(INCORRECT_VIDEO_FILE_ERROR) print "Generating db for video: ", sys.argv[ 3], "\nwith labels file:", sys.argv[2] gen = Generate(sys.argv[2], sys.argv[3]) gen.run() elif sys.argv[1] == "-l": if len(sys.argv) != 4: print "Format is \n python main.py -[r/g/l] [labels_file] video_name" raise Exception(INCORRECT_FORMAT_ERROR) label_file_type = mimetypes.guess_type(sys.argv[2])[0] video_file_type = mimetypes.guess_type(sys.argv[3])[0] if label_file_type[:3] != "tex": #The file is not a labels file return INCORRECT_LABEL_FILE_ERROR if video_file_type[:3] != "vid": #The file is not a video file return INCORRECT_VIDEO_FILE_ERROR print "Learning for video: ", sys.argv[3] video_name = sys.argv[3] ffmpeg.convert_video(video_name) name, extension = video_name[-5:].split('.') name = video_name.split('/')[-1] name = name[:-len(extension) - 1] os.system("cp " + sys.argv[2] + " " + WEB_LABELS) os.system("mv " + name + '.webm ' + 'web/output/static/output/' + WEB_VIDEO_NAME) print "Please go to the URL to edit labels" return SUCCESS
random([adj, adv, verb]) + TopicWord once quit, save lines in 'saved/' Parameters ------- n_pairs: int - Number of pairs to generate - Ex: python make_pairs.py 420 ''' n_pairs = 100 if len(sys.argv) > 1: n_pairs = int(sys.argv[1]) pairs = Generate().pairs(n_pairs=n_pairs) pairs = [x[0] + ' ' + x[1] for x in pairs] pairs = list(sorted(pairs)) pairs.sort(key=len) save_lines = [] for p in pairs: os.system('clear') print(p, '\n', 'y/n?', '\n') inp = input() if inp == 'j': save_lines.append(p) os.system('clear') elif inp == 'q':