Exemple #1
0
def main():
    in_d, out_d,m,n = utils.argsdirs("Most frequent triples",["n"])
    n = int(n)
    tomes = [
        triple.Tome(filename)
        for filename
        in utils.filenames(in_d)
    ]
    
    filename_out = utils.new_filename(out_d,"most_frequent.gz")
    tome_out = triple.Tome(filename_out)
    
    print "joining the tomes.."
    tome_join = triple.Tome(tomes)
    print "grouping/summing (again).."
    tome_join = tome_join.group_sum(m)
    print "sorting the tomes (again).."
    tome_join = tome_join.sort()
    print "getting the first %d.."%n
    tome_join = tome_join.first(n)
    print "writing everything down.."
    writer = tome_out.writer()
    for tr in tome_join:
        writer(tr)
    print "done."
def write_results(tv, mus, out_d):
    frames = np.argmax(mus,axis=0)
    filename_out = utils.new_filename(out_d, "framed_triples.gz")
    tome_out = triple.Tome(filename_out)
    writer = tome_out.writer()
    for tr,frame in zip(tv.triples,frames):
        tr_new = triple.Triple(*(tr.tolist()[:3]+[frame]))
        writer(tr_new)
Exemple #3
0
def save_speckled_wallpaper(settings):
    im = draw_speckled_wallpaper(settings)
    if settings.name:
        filename = settings.name
    else:
        filename = new_filename()
    im.save(filename)
    print("Saved new wallpaper as %s" % filename)
Exemple #4
0
def main():
    in_d, out_d,_ = utils.argsdirs("Sorting")
    
    for filename in utils.filenames(in_d):
        tome_in = triple.Tome(filename)
        filename_out = utils.new_filename(out_d,filename)
        tome_out = triple.Tome(filename_out)
        writer = tome_out.writer()
        for tr in tome_in.sort():
            writer(tr)
Exemple #5
0
def main():
    in_d, out_d, members_groupby = utils.argsdirs("Counting the triples")
    
    for filename in utils.filenames(in_d):
        print "processing file %s.."%filename
        tome_in = triple.Tome(filename)
        filename_out = utils.new_filename(out_d,filename)
        print "writing to %s.."%filename_out
        tome_out = triple.Tome(filename_out)
        
        writer = tome_out.writer()
        for tr in tome_in.group_sum(members_groupby):
            writer(tr)
Exemple #6
0
def main ():
    commandline_parser = argparse.ArgumentParser("Pre-processing of data")

    commandline_parser.add_argument("--data-folder", nargs =1, help="Specifies the path of the folder containing the data.")
    
    commandline_parser.add_argument("--output-folder", nargs =1, help="Specifies the path of the output folder.")
    
    args = vars(commandline_parser.parse_args())
    data_folder = args["data_folder"][0]
    output_folder = args["output_folder"][0]
    output_folder = path.join(output_folder,'dataset')
    if not path.exists(output_folder):
        makedirs(output_folder)
    files = utils.filenames(data_folder)
    for file_path in files:
        output_path = utils.new_filename(output_folder, file_path)
        preprocess(file_path, output_path)
def upload():

    # app.logger.warning(request)
    log_request_info(request)
    # video is a werkzeug.datastructures.FileStorage object
    video = request.files['video-blob']
    app.logger.warning(video)
    # app.logger.warning(video['contents'])
    app.logger.warning(type(video))
    # data = video.read()
    # app.logger.warning(data)
    app.logger.warning("filename: {0}".format(video.filename))
    audio = request.files['audio-blob']
    app.logger.warning(audio)
    # data = audio.read()
    # app.logger.warning(len(data))

    try:
        # Get the name of the uploaded file
        # file = request.files['file']
        video = request.files['video-blob']
        audio = request.files['audio-blob']
    except Exception as e:
        app.logger.warning("error: {0}".format(e))
        raise Exception(e)

    # let's time it
    start = time.time()

    video_filename = ''
    audio_filename = ''

    if video:  # and allowed_file(video.filename):
        # data = video.read()
        # Make the filename safe, remove unsupported chars
        filename = secure_filename(video.filename) + '_video' + '.webm'
        video_filename = filename
        # Move the file form the temporal folder to
        # the upload folder we setup
        #file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        video.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        # Redirect the user to the uploaded_file route, which
        # will basicaly show on the browser the uploaded file
        # return redirect(url_for('uploaded_file',
        #                         filename=filename))
    if audio:
        audio_filename = secure_filename(
            audio.filename) + '_audio' + '.wav'  #.mp3?
        print("AUDIO_1!!!: {0}".format(audio_filename))
        #        audio_filename = new_filename(filename, "_mono")
        audio.save(os.path.join(app.config['UPLOAD_FOLDER'], audio_filename))
        app.logger.warning("filename: {0}".format(audio_filename))
        stereo_to_mono(
            os.path.join(app.config['UPLOAD_FOLDER'], audio_filename))
        audio_filename = new_filename(audio_filename, "_mono")
        audio_filename = os.path.join(app.config['UPLOAD_FOLDER'],
                                      audio_filename)
        outfilename = '/home/ec2-user/flask_attempts/data/test.txt'
        stats = dict()
        # decode the speech in the file
        #ling_stats = decode_speech_driver(filename, outfilename)
        ling_stats = decode_speech(audio_filename)

        end = time.time()
        total_time = round(end - start)

        stats['time_to_analyze'] = total_time
        print("AUDIO_2!!!: {0}".format(audio_filename))
        stats['total speech time'] = get_duration(audio_filename)
        # combine the different stats to display in the template
        stats = dict(stats.items() + ling_stats.items())

        app.logger.warning('stats: {0}'.format(stats))

        # render the speech as text on a different page
        return render_template('decoded_speech.html',
                               stats=stats,
                               video_filename=video_filename,
                               audio_filename=audio_filename)