コード例 #1
0
ファイル: views.py プロジェクト: fwenzel/millimeter
def index(request):
    current_site = Site.objects.get_current()

    data = {}
    if request.method == 'POST':
        form = ShortenForm(request.POST)
        if form.is_valid():
            try:
                link = Link.objects.filter(url=form.cleaned_data['url'],
                                           is_autoslug=True)[0]
            except IndexError:
                link = form.save()
            link.users.add(request.user)
            link.save()

            # success data
            data.update({
                'success': True,
                'long_url': form.cleaned_data['url'],
                'short_url': 'http://%s/%s' % (current_site.domain, link.slug)
            })
    else:
        # allow pre-populating url with GET (from bookmarklet)
        initial_url = request.GET.get('url', '')

        # no circular bookmarking...
        if initial_url.startswith('http://%s' % current_site.domain):
            initial_url = ''

        form = ShortenForm(initial={'url': initial_url})

    data.update({'form': form})

    return render(request, 'shortener/index.html', data)
コード例 #2
0
ファイル: run.py プロジェクト: TPNguyen/textSNE
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('inputs', nargs='+',
                        help='either [embedding] or [input.We] [input.words]')
    parser.add_argument('output',
                        help='output filename [outfile.png]')
    parser.add_argument('-l', '--limit', metavar='L', type=int,
                        help='limit to the first L words', default=500)
    parser.add_argument('-n', '--normalize', action='store_true',
                        help='normalize each word vector to unit L2 norm')
    parser.add_argument('-f', '--fast', action='store_true',
                        help='ignore transparency to speed up rendering')
    parser.add_argument('-F', '--font', help='path to font file')
    parser.add_argument('-p', '--pca', type=int, default=0,
                        help='perform PCA with this number of dimensions'
                        'before calling SNE')
    parser.add_argument('-s', '--scale', type=float, default=1.0,
                        help='scale up the image by this factor')
    args = parser.parse_args()

    if len(args.inputs) == 1:
        i_emb = args.inputs[0]
        with open(i_emb, 'rb') as fin:
            print 'Reading combined data from %s ...' % i_emb
            titles, x = read_combined(fin, limit=args.limit)
    elif len(args.inputs) == 2:
        i_We, i_words = args.inputs
        with open(i_words, 'rb') as fwords:
            print 'Reading vocab from %s ...' % i_words
            with open(i_We, 'rb') as fWe:
                print 'Reading vectors from %s ...' % i_We
                titles, x = read_separated(fwords, fWe, limit=args.limit)
    else:
        parser.print_usage()
        exit(1)

    if args.normalize:
        x /= np.sqrt((x ** 2).sum(-1))[:, np.newaxis]
    
    out = calc_tsne.tsne(x, use_pca=bool(args.pca), initial_dims=args.pca)
    data = [(title, point[0], point[1]) for (title, point) in zip(titles, out)]
    render.render(data, args.output, transparency=(0 if args.fast else 0.4),
                  width=int(3000*args.scale), height=int(2000*args.scale),
                  fontfile=args.font)
コード例 #3
0
from os import chdir, path
from time import sleep

# Make this script's directory the current working directory (could be anything else)
# and add it to sys.path (this script runs from blender context)
elmyra_root = path.dirname(path.realpath(__file__))
chdir(elmyra_root)
sys.path.append(elmyra_root)

from lib import common, export, render, version
from lib.context import VISUALIZATIONS_DIR


def parse_custom_args():
    parser = ArgumentParser(prog='Elmyra Render Params')
    parser.add_argument("--id", required=True)
    parser.add_argument('--device', default='CPU')
    parser.add_argument('--target-time', type=int, default=60)

    custom_args = sys.argv[sys.argv.index('--') + 1:]

    return parser.parse_args(custom_args)


args = parse_custom_args()
common.ensure_addons()

if version.open_latest(path.join(VISUALIZATIONS_DIR, args.id)):
    render.render(args.target_time, args.device)
    export.export()
コード例 #4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('inputs',
                        nargs='+',
                        help='either [embedding] or [input.We] [input.words]')
    parser.add_argument('output', help='output filename [outfile.png]')
    parser.add_argument('-l',
                        '--limit',
                        metavar='L',
                        type=int,
                        help='limit to the first L words',
                        default=500)
    parser.add_argument('-n',
                        '--normalize',
                        action='store_true',
                        help='normalize each word vector to unit L2 norm')
    parser.add_argument('-f',
                        '--fast',
                        action='store_true',
                        help='ignore transparency to speed up rendering')
    parser.add_argument('-F', '--font', help='path to font file')
    parser.add_argument('-p',
                        '--pca',
                        type=int,
                        default=0,
                        help='perform PCA with this number of dimensions'
                        'before calling SNE')
    parser.add_argument('-s',
                        '--scale',
                        type=float,
                        default=1.0,
                        help='scale up the image by this factor')
    args = parser.parse_args()

    if len(args.inputs) == 1:
        i_emb = args.inputs[0]
        with open(i_emb, 'rb') as fin:
            print 'Reading combined data from %s ...' % i_emb
            titles, x = read_combined(fin, limit=args.limit)
    elif len(args.inputs) == 2:
        i_We, i_words = args.inputs
        with open(i_words, 'rb') as fwords:
            print 'Reading vocab from %s ...' % i_words
            with open(i_We, 'rb') as fWe:
                print 'Reading vectors from %s ...' % i_We
                titles, x = read_separated(fwords, fWe, limit=args.limit)
    else:
        parser.print_usage()
        exit(1)

    if args.normalize:
        x /= np.sqrt((x**2).sum(-1))[:, np.newaxis]

    out = calc_tsne.tsne(x, use_pca=bool(args.pca), initial_dims=args.pca)
    data = [(title, point[0], point[1]) for (title, point) in zip(titles, out)]
    render.render(data,
                  args.output,
                  transparency=(0 if args.fast else 0.4),
                  width=int(3000 * args.scale),
                  height=int(2000 * args.scale),
                  fontfile=args.font)
コード例 #5
0
#!/usr/bin/env python3

import argparse
import os
import sys

from lib.util import DOCDIR
from lib.render import render

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-t", "--theme", help="theme name, defaults to 'default'", default="default")
    parser.add_argument(
        "-o",
        "--output",
        help="output directory, defaults to 'docs/html' in the repository",
        default=os.path.join(DOCDIR, "html"),
    )
    parser.add_argument(
        "-f", "--overwrite", help="allow overwriting output directory when it exists", action="store_true"
    )
    parser.add_argument("-b", "--build", help="set build ID information", default=None)

    ns = parser.parse_args()

    if os.path.exists(ns.output) and not ns.overwrite:
        print(f"Error: output path {ns.output} exists, pass --overwrite to overwrite")
        sys.exit(1)

    render(ns.theme, ns.output, ns.build)
コード例 #6
0
    parser = argparse.ArgumentParser()
    parser.add_argument("-t",
                        "--theme",
                        help="theme name, defaults to 'default'",
                        default="default")
    parser.add_argument(
        "-o",
        "--output",
        help="output directory, defaults to 'docs/html' in the repository",
        default=os.path.join(DOCDIR, "html"),
    )
    parser.add_argument(
        "-f",
        "--overwrite",
        help="allow overwriting output directory when it exists",
        action="store_true")
    parser.add_argument("-b",
                        "--build",
                        help="set build ID information",
                        default=None)

    ns = parser.parse_args()

    if os.path.exists(ns.output) and not ns.overwrite:
        print(
            f"Error: output path {ns.output} exists, pass --overwrite to overwrite"
        )
        sys.exit(1)

    render(Store(), ns.theme, ns.output, ns.build)