Example #1
0
 def make_annotations(ann: dict):
     r = {}
     for k, v in ann.items():
         if isinstance(v, dict):
             r[k] = plac.Annotation(**v)
         elif isinstance(v, (tuple, list)):
             r[k] = plac.Annotation(*v)
         else:
             r[k] = v
     return r
Example #2
0
                while True:
                    src_phrase = " ".join(srctext[i]
                                          for i in range(e_start, e_end + 1))
                    trg_phrase = " ".join(trgtext[i]
                                          for i in range(fs, fe + 1))
                    yield (src_phrase, trg_phrase)

                    fe += 1
                    if fe in f_aligned or fe == trglen:
                        break
                fs -= 1
                if fs in f_aligned or fs < 0:
                    break


@plac.annotations(source_file=plac.Annotation("Source file", 'option', 's',
                                              str),
                  target_file=plac.Annotation("Target file", 'option', 't',
                                              str),
                  aligment_file=plac.Annotation("Alignment file", 'option',
                                                'a', str),
                  output_file=plac.Annotation("Output file", 'option', 'o',
                                              str),
                  max_ngram=plac.Annotation("Max N-gram length", 'option', 'm',
                                            int))
def main(source_file, target_file, aligment_file, output_file, max_ngram=5):
    assert source_file and target_file and aligment_file and output_file, 'missing arguments'

    sources = read_file(source_file)
    targets = read_file(target_file)
    alignments = map(convert_alignment, read_file(aligment_file))
Example #3
0
    '''Loads cross validation dictionaries used for the experiment'''

    filter_fpath = os.path.join(cross_val_folder, 'user_item_filter.dat')
    user_items_to_filter = load_dict_from_file(filter_fpath)

    val_tags_fpath = os.path.join(cross_val_folder, 'user_val_tags.dat')
    user_validation_tags = load_dict_from_file(val_tags_fpath)

    test_tags_fpath = os.path.join(cross_val_folder, 'user_test_tags.dat')
    user_test_tags = load_dict_from_file(test_tags_fpath)

    return user_items_to_filter, user_validation_tags, user_test_tags


@plac.annotations(
    db_fpath=plac.Annotation('H5 database file', type=str),
    db_name=plac.Annotation('H5 database name', type=str),
    cross_val_folder=plac.Annotation('Folder with cross validation files',
                                     type=str),
    param_value=plac.Annotation('Parameter Value', type=float),
    est_name=plac.Annotation('Estimator to perform grid search',
                             type=str,
                             choices=['lda', 'smooth'],
                             kind='option'),
    rand_seed=plac.Annotation('Random seed to use (None = default seed)',
                              type=int,
                              kind='option'),
    num_cores=plac.Annotation('Number of cores to use', type=int))
def main(db_fpath,
         db_name,
         cross_val_folder,
Example #4
0
import os
import sys

import plac  # pylint: disable=F0401

from gossamer.main import dispatch
from gossamer.constant import modes, exits, states, \
    DEFAULT_WEBDRIVER, DEFAULT_TESTFILE, \
    DEFAULT_DIFFCOLOR, DEFAULT_SCREENSIZE, \
    DEFAULT_BROWSER
from gossamer import util, exc
from gossamer import __version__


@plac.annotations(
    names=plac.Annotation('Test case name(s) to use, comma-separated', ),
    postdata=plac.Annotation('File for POST data or - for stdin'),
    testfile=plac.Annotation('Test file(s) to use',
                             'option',
                             'f',
                             str,
                             metavar='GLOB'),
    record=plac.Annotation('Record a new test', 'flag', 'r'),
    rerecord=plac.Annotation('Re-run the test but take new screenshots',
                             'flag', 'rr'),
    selenium=plac.Annotation('Selenium WebDriver URL to use',
                             'option',
                             's',
                             metavar=DEFAULT_WEBDRIVER),
    browser=plac.Annotation(
        'Browser to use, either firefox, chrome, phantomjs, ie, or opera',
Example #5
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#NOTE plac is cool but is an other dependency, should replace by optparse
import plac
import logbook
log = logbook.Logger('Database::Manager')

from neuronquant.data.database import Manager


@plac.annotations(symbols=plac.Annotation("Add provided stocks to db",
                                          'option', 'a'),
                  sync=plac.Annotation("Update quotes stored in db", 'flag',
                                       's'),
                  create=plac.Annotation("Create database from written models",
                                         'flag', 'c'))
def main(sync, create, symbols=None):
    ''' MySQL Stocks database manager '''
    db = Manager()

    if create:
        log.info('Creating database...')
        db.create_database()

    elif sync:
        log.info('Synchronizing quotes database...')
        db.sync_quotes()
# -*- coding: future_fstrings -*-
# Standard modules
import pathlib

# External modules
import plac

# Local modules
from obd_influx.storage import create_recorder


@plac.annotations(
    config_json=plac.Annotation(
        "json configuration file to check",
        type=pathlib.Path)
)
def check_config_json(config_json: pathlib.Path):
    """Verify that config.json file correctly defines Recorder."""
    recorder = create_recorder(config_json=config_json)
    print(
        f"{config_json.resolve()} successfully initialized recorder")
    try:
        recorder.check_settings()
        print("recorder settings check out")
    except ImportError:
        print("recorder has no check_settings method")


if __name__ == '__main__':
    plac.call(check_config_json)
Example #7
0
import os
import cv2
import numpy as np
import plac
import json
from yolo2.frontend import YOLO

#Set environment variables to run it on cpu
os.environ['CUDA_DEVICE_ORDER'] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = "0"


@plac.annotations(weights_path=plac.Annotation("Model path", type=str),
                  image_path=plac.Annotation("Image path", type=str))
def main(weights_path, image_path):
    if not os.path.exists(weights_path):
        raise Exception("The model file doesn't exist in this path " +
                        str(weights_path))

    if not os.path.exists(image_path):
        raise Exception("The image file doesn't exist in this path " +
                        str(image_path))

    with open('config.json') as config_buffer:
        config = json.load(config_buffer)

    yolo = YOLO(backend=config['model']['backend'],
                input_size=config['model']['input_size'],
                labels=config['model']['labels'],
                max_box_per_image=config['model']['max_box_per_image'],
                anchors=config['model']['anchors'])
Example #8
0

def save_dict_to_file(fpath, dict_data):
    '''
    Saves a dict with sets/lists as values to a file. Each line of the file will
    be:
        key - val1, val2, val3 ...
    '''

    with open(fpath, 'w') as out_file:
        for key in dict_data:
            print(key, '-', file=out_file, end=' ')
            print(' '.join(str(x) for x in dict_data[key]), file=out_file)


@plac.annotations(db_fpath=plac.Annotation('H5 database file', type=str),
                  db_name=plac.Annotation('H5 database name', type=str),
                  cross_val_folder=plac.Annotation(
                      'Folder with cross validation files', type=str))
def main(db_fpath, db_name, cross_val_folder):

    user_items_to_filter, user_validation_items, user_test_items = \
            load_train_test_validation(cross_val_folder)

    validation_dict = defaultdict(set)
    test_dict = defaultdict(set)

    with AnnotReader(db_fpath) as reader:
        reader.change_table(db_name)

        #Generate 50 random tags not used by any user in validation or test
Example #9
0
    #validate that the Cloud Network exists
    # if port_check.status_code != 200:
    #     print(f"Could not validate server {cs_id}! Cloud Servers "
    #           f"API returns code {cs_check.status_code}. Exiting!")
    #     exit(1)


# def get_port_ids(cloud_network, cn_endpoint, cs_list, headers):
#     port_ids = []
#     for cs in cs_list:
#


#begin main function
@plac.annotations(
    region=plac.Annotation("Rackspace Cloud Servers region"),
    cs_ids=plac.Annotation("At least 2 Cloud Server IDs, separated by commas"),
    cloud_network=plac.Annotation(
        "Cloud Network or 'public' for Public Network"),
    ip_version=plac.Annotation("IP version", choices=["4", "6"]))
def main(region, cs_ids, cloud_network, ip_version):
    username, password = getset_keyring_credentials()

    auth_token, headers = get_auth_token(username, password)

    cn_endpoint = find_endpoints(auth_token,
                                 headers,
                                 region,
                                 desired_service="cloudNetworks")

    cs_endpoint = find_endpoints(auth_token,
Example #10
0
        print("example upload commands:")
        print("#curl -vX %s \"%s\" --data-binary @%s" %
              (method, temp_url, cf_object))
        print("#curl -vX %s \"%s\" --data-binary @%s" %
              (method, snet_temp_url, cf_object))
    if method == "GET":
        print("example download commands:")
        print("#curl -vX %s \"%s\" -o %s" % (method, temp_url, cf_object))
        print("#curl -vX %s \"%s\" -o %s" % (method, snet_temp_url, cf_object))
    print(
        "Remember, curl tries to put the entire file into memory before copying!"
    )


@plac.annotations(
    method=plac.Annotation("HTTP method : GET or PUT"),
    duration=plac.Annotation(
        "Time to live for TempURL. Use M for Minutes, H for hours and D for days"
    ),
    region=plac.Annotation("Rackspace datacenter"),
    container=plac.Annotation("name of Cloud Files container to use."),
    cf_object=plac.Annotation(
        "name of Cloud Files object that will be uploaded via the tempURL"))
def main(method, duration, region, container, cf_object):
    duration, unit = parse_units(duration)
    duration_in_seconds = calculate_ttl(duration, unit)
    username, password = getset_keyring_credentials()
    auth_token = get_auth_token(username, password)
    cf_endpoint, cf_username = find_endpoint_and_user(auth_token, region)
    temp_url_key = get_temp_url_key(cf_endpoint, cf_username, auth_token)
    object_url = check_and_make_container(method, cf_endpoint, container,
                self.add_execution(
                    # prev + daemonize if in time, now + daemonize if in delay
                    max(prev_time, time.time()) + self.daemons[item[1]],
                    item[1])
            finally:
                self.lock.release()

            return item

        def stop(self):
            self.graceful_stop = True


@plac.annotations(
    cfg_file_path=plac.Annotation('path to the config file', 'option', 'c'),
    resume=plac.Annotation('resume crawling from last process', 'flag'),
    reset_elasticsearch=plac.Annotation('reset Elasticsearch indexes', 'flag'),
    reset_json=plac.Annotation('reset JSON files', 'flag'),
    reset_mysql=plac.Annotation('reset MySQL database', 'flag'),
    reset_all=plac.Annotation('combines all reset options', 'flag'),
    no_confirm=plac.Annotation('skip confirm dialogs', 'flag'))
def cli(cfg_file_path, resume, reset_elasticsearch, reset_mysql, reset_json,
        reset_all, no_confirm):
    "A generic news crawler and extractor."

    if reset_all:
        reset_elasticsearch = True
        reset_json = True
        reset_mysql = True
Example #12
0
        if done:
            eval_rewards.append(reward)
            eval_actions.append(episode_actions)
            eval_summaries.append(info['summary'])
            episode_actions = []
            obs = eval_env.reset()
            n_episodes += 1
            if n_episodes % 100 == 0:
                print(n_episodes)

    return eval_rewards, eval_summaries, eval_actions



@plac.annotations(
    model_path=plac.Annotation("Path to model", type=str),
)
def main(model_path):
    # load model
    class LeadBaselineModel():
        def __init__(self, summary_len: int = 4):
            self.summary_len = summary_len

        def predict(self, obs):
            summary = obs[-self.summary_len:]
            for i in range(len(obs)):
                if sum(summary[min(i, self.summary_len - 1)]) == 0:
                    return i, 0

    if model_path == 'experiments/baseline':
        model = LeadBaselineModel()
#!/usr/bin/env python
import os
import sys
import plac
import importlib

from pathlib import Path
from spacy.util import get_package_path
from spacy.compat import symlink_to


@plac.annotations(lang=plac.Annotation(help='Language code'),
                  lang_path=plac.Annotation(help='Language path'))
def link_lang_spacy(lang, lang_path):
    origin_path = os.path.join(
        str(get_package_path('spacy').resolve()),
        'lang',
        lang,
    )
    try:
        symlink_to(
            Path(origin_path),
            os.path.abspath(lang_path),
        )
        try:
            importlib.import_module('spacy.lang.{}'.format(lang))
            print('link created')
        except Exception as e:
            print('link not created')
            raise e
    except Exception as e:
Example #14
0
        depth_maps.flush()

        logger.log("Saved DNN depth maps to {}.".format(dnn_depth_map_path))

        return depth_maps
    except Exception:
        logger.log(
            "\nError occurred during creation of depth maps - deleting {}.".
            format(dnn_depth_map_path))
        os.remove(dnn_depth_map_path)
        raise


@plac.annotations(
    video_path=plac.Annotation("The path to the input video.",
                               kind="option",
                               type=str,
                               abbrev="i"),
    model_path=plac.Annotation(
        "The path to the depth estimation model weights.",
        kind="option",
        type=str,
        abbrev="m"),
    video_output_path=plac.Annotation("The path to the write the output to.",
                                      kind="option",
                                      type=str,
                                      abbrev="o"),
    batch_size=plac.Annotation(
        "The mini-batch size to use for the depth estimation network.",
        kind="option",
        type=int),
)
Example #15
0
import plac
import spacy

@plac.annotations(
    output_dir=plac.Annotation("Connection string", type=str))
def main(output_dir):
    nlp = spacy.blank('en')
    nlp.add_pipe(nlp.create_pipe('ner'))
    nlp.add_pipe(nlp.create_pipe('sentencizer'))
    nlp.begin_training()
    nlp.to_disk(output_dir)

if __name__ == '__main__':
    plac.call(main)
import re

import nltk
import plac


@plac.annotations(filepath=plac.Annotation('The text file to parse', type=str))
def main(filepath):
    with open(filepath, 'r') as f:
        text = f.read()
    """Create a parser."""
    grammar = r"""
                NBAR:
                    {<DT>?<NN.*|JJ>*<NN.*>} # Nouns and Adjectives, terminated with Nouns

                NP:
                    {<NBAR>(<IN|CC><NBAR>)*}  # Above, connected with in/of/etc...
            """
    chunker = nltk.RegexpParser(grammar)
    pattern = re.compile(r"^(\d(\.\d)*\s+)?[A-Z]\w*(\s(&|\w+))*$",
                         flags=re.MULTILINE)
    sections = []

    for match in re.finditer(pattern, text):
        start, end = match.span()
        sections.append((match.group(0), end + 1))
        # print(match.group(0), match.span(), text[start:end])

    for i, title_index_pair in enumerate(sections):
        section, start = title_index_pair
    mesh = TriangleMesh.create_from_point_cloud_ball_pivoting(
        pcd=point_cloud, radii=o3d.utility.DoubleVector([radius, 2 * radius]))

    logger.log("Created triangle mesh {}/{}.".format(frame_i + 1, num_frames))
    mesh_filename = "{:04d}.ply".format(frame_i)
    mesh_path = os.path.join(output_path, mesh_filename)
    write_triangle_mesh(filename=mesh_path, mesh=mesh)
    logger.log("Saved triangle mesh for frame {}/{} to {}.".format(
        frame_i + 1, num_frames, mesh_path))

    return mesh


@plac.annotations(
    video_path=plac.Annotation('The path to the source video file.',
                               type=str,
                               kind='option',
                               abbrev='i'),
    workspace_path=plac.Annotation(
        "Where to save and load intermediate results to and from.",
        type=str,
        kind="option"))
def main(video_path, workspace_path="workspace"):
    print(dict(
        video_path=video_path,
        workspace_path=workspace_path,
    ))

    video_name = Path(video_path).stem
    workspace_path = os.path.join(os.path.abspath(workspace_path), video_name)
    colmap_path = os.path.join(workspace_path, "parsed_colmap_output.pkl")
Example #18
0
    'firefox': webdriver.Firefox,
    'chrome': webdriver.Chrome,
    'ie': webdriver.Ie,
    'opera': webdriver.Opera
}

CAPABILITIES = {
    'firefox': webdriver.DesiredCapabilities.FIREFOX,
    'chrome': webdriver.DesiredCapabilities.CHROME,
    'ie': webdriver.DesiredCapabilities.INTERNETEXPLORER,
    'opera': webdriver.DesiredCapabilities.OPERA
}


@plac.annotations(
    url=plac.Annotation('URL to hit'),
    filename=plac.Annotation('Test file location'),
    postdata=plac.Annotation('File for POST data or - for stdin'),
    record=plac.Annotation('Record a test', 'flag', 'r', metavar='URL'),
    rerecord=plac.Annotation('Re-run the test but take new screenshots',
                             'flag', 'R'),
    sleepfactor=plac.Annotation('Sleep interval multiplier',
                                'option',
                                'f',
                                float,
                                metavar='FLOAT'),
    browser=plac.Annotation(
        'Browser to use, either firefox, chrome, phantomjs, ie or opera.',
        'option',
        'b',
        str,
Example #19
0
    np.savetxt(rgr_pred_fpath, rgr_pred)
    np.savetxt(rgr_true_fpath, rgr_true)

    print('Micro F1: ', f1_score(clf_true, clf_pred, average='micro'))
    print('Macro F1: ', f1_score(clf_true, clf_pred, average='macro'))
    print()
    print('R2: ', r2_score(rgr_true, rgr_pred))
    print('MAE: ', mae(rgr_true, rgr_pred))
    print('MSE: ', mse(rgr_true, rgr_pred))
    print()
    print_importance(feature_ids,
                     clf_model.best_estimator_.feature_importances_,
                     rgr_model.best_estimator_.feature_importances_)


@plac.annotations(partial_features_fpath=plac.Annotation('Partial Features',
                                                         type=str),
                  tag_categ_fpath=plac.Annotation('Tags file', type=str),
                  tseries_fpath=plac.Annotation('Time series file', type=str),
                  num_days_to_use=plac.Annotation('Num Days Series', type=int),
                  assign_fpath=plac.Annotation('Series assignment file',
                                               type=str),
                  out_foldpath=plac.Annotation('Output folder', type=str))
def main(partial_features_fpath, tag_categ_fpath, tseries_fpath,
         num_days_to_use, assign_fpath, out_foldpath):

    X, feature_ids, feature_names = \
            create_input_table(partial_features_fpath, tseries_fpath,
                               tag_categ_fpath, num_pts = num_days_to_use)

    #Sort X by upload date
    up_date_col = feature_names['A_UPLOAD_DATE']
Example #20
0
vulnerability_specific_columns = [
    'message_score', 'changed_files_score', 'git_diff_score',
    'message_score_reference_content', 'changed_files_score_code_tokens'
]
universal_columns = [
    'n_hunks', 'avg_hunk_size', 'n_changed_files', 'vulnerability_timestamp'
]
columns_to_drop = [
    'path_similarity_score', 'git_diff_score_code_tokens',
    'message_score_code_tokens', 'changed_files_score_reference_content',
    'git_diff_score_reference_content'
]


@plac.annotations(
    vulnerability_id=plac.Annotation("A vulnerability ID (typically a CVE)",
                                     type=str),
    verbose=plac.Annotation(
        "Definition of verbose: containing more words than necessary: WORDY",
        'flag', 'v'),
    description=plac.Annotation("The vulnerability description",
                                "option",
                                type=str),
    published_timestamp=plac.Annotation(
        "The timestamp at which the vulnerability is published (int)",
        "option",
        type=int),
    repo_url=plac.Annotation(
        "The affected repository (typically a GitHub URL)", "option",
        type=str),
    project_name=plac.Annotation(
        "The name of the affected project (typically a GitHub URL)",
Example #21
0
        r = huxleymain(testname,
                       url,
                       filename,
                       postdata,
                       remote=REMOTE_WEBDRIVER_URL,
                       sleepfactor=sleepfactor,
                       autorerecord=not playback_only,
                       save_diff=save_diff,
                       screensize=screensize)
    print
    if r != 0:
        new_screenshots.set_value(True)


@plac.annotations(
    names=plac.Annotation('Test case name(s) to use, comma-separated', ),
    testfile=plac.Annotation('Test file(s) to use',
                             'option',
                             'f',
                             str,
                             metavar='GLOB'),
    record=plac.Annotation('Record a new test', 'flag', 'r'),
    playback_only=plac.Annotation('Don\'t write new screenshots', 'flag', 'p'),
    concurrency=plac.Annotation('Number of tests to run in parallel',
                                'option',
                                'c',
                                int,
                                metavar='NUMBER'),
    save_diff=plac.Annotation(
        'Save information about failures as last.png and diff.png', 'flag',
        'e'),
from statistics import mean
from xml.etree import ElementTree

import plac
import spacy


@plac.annotations(filepath=plac.Annotation(
    'The XML file to calculate the average sentence length for.', type=str))
def main(filepath):
    tree = ElementTree.parse(filepath)
    root = tree.getroot()

    nlp = spacy.load('en')

    sentence_lengths = []

    for section in root.findall('section'):
        section_text = section.find('text').text
        span = nlp(section_text)

        for sent in span.sents:
            sentence_lengths.append(len(sent))

    print('Mean Sentence Length: %.2f' % mean(sentence_lengths))


if __name__ == '__main__':
    plac.call(main)
Example #23
0
from typing import Optional
from xml.dom import minidom
from xml.etree import ElementTree

import plac


@plac.annotations(
    files=plac.Annotation('The list of annotated XML files to merge.',
                          type=str),
    output_path=plac.Annotation(
        'Where to save the output file. '
        'If set to None, the merged file is printed to stdout.',
        type=str,
        kind='option',
        abbrev='o'),
)
def main(output_path: Optional[str] = None, *files):
    """Merge annotations from multiple XML files into a single XML file."""

    if len(files) > 0:
        tree = ElementTree.ElementTree(element=ElementTree.Element('document'))

        document_sections = [
            ElementTree.parse(file).getroot().findall('section')
            for file in files
        ]

        for i, sections in enumerate(zip(*document_sections)):
            for section in sections[1:]:
                annotations = sections[0].find('annotations')
Example #24
0
                                         lexers.JsonLexer(),
                                         formatters.TerminalFormatter())
    data = {}
    data['forms'] = form_urls
    data['compressed'] = compressed_urls
    full_path = '%sreport-%s.json' % (loot_dir, str(now))
    with open(full_path, 'a') as fd:
        _LOGGER.info('* Writing out report')
        json.dump(data, fd, ensure_ascii=False, indent=4)
    print(form_colorful_json)
    print(compressed_colorful_json)


@plac.annotations(
    url=plac.Annotation('URL to navigate to',
                        kind='option',
                        abbrev='url',
                        type=str),
    log_level=plac.Annotation(
        'Logging level [LOG_LEVEL]', 'option', 'l', str,
        ['debug', 'info', 'warn', 'warning', 'error']),  # noqa: E501
    log_format=plac.Annotation('Logging format [LOG_FORMAT]', 'option', 'f',
                               str, ['json', 'text']),
    url_file=plac.Annotation('File with newline separated URLs',
                             kind='option',
                             type=str),
    loot_dir=plac.Annotation('Directory to add loot and logging',
                             kind='option',
                             type=str),
)
def main(url, url_file, loot_dir='loot/', log_level='info', log_format='json'):
Example #25
0
    user_items_to_filter = load_dict_from_file(filter_fpath)
    
    val_tags_fpath = os.path.join(cross_val_folder, 'user_val_tags.dat')
    user_validation_tags = load_dict_from_file(val_tags_fpath)
    
    test_tags_fpath = os.path.join(cross_val_folder, 'user_test_tags.dat')
    user_test_tags = load_dict_from_file(test_tags_fpath)
    
    test_items_fpath = os.path.join(cross_val_folder, 'user_test_items.dat')
    user_test_items = load_dict_from_file(test_items_fpath)
    
    return user_items_to_filter, user_validation_tags, user_test_tags, \
        user_test_items
                
@plac.annotations(
    db_fpath = plac.Annotation('H5 database file', type=str),
    db_name = plac.Annotation('H5 database name', type=str),
    cross_val_folder = plac.Annotation('Folder with cross validation files', 
            type=str),
    probs_folder = plac.Annotation('Probabilities Folder', type=str))

def main(db_fpath, db_name, cross_val_folder, probs_folder):
    
    #get cross validation dicts
    user_items_to_filter, user_validation_tags, user_test_tags, \
            user_test_items = load_train_test_validation(cross_val_folder)

    with AnnotReader(db_fpath) as reader:
        reader.change_table(db_name)
        
        annot_filter = FilteredUserItemAnnotations(user_items_to_filter)
Example #26
0
import torch
from torchvision.transforms import Compose

import loaddata_demo as loaddata
import utils

from models.midas_net import MidasNet
from models.transforms import NormalizeImage, PrepareForNet, Resize

plt.set_cmap("gray")


@plac.annotations(
    image_path=plac.Annotation(
        'The path to an RGB image or a directory containing RGB images.',
        type=str,
        kind='option',
        abbrev='i'),
    model_path=plac.Annotation('The path to the pre-trained model weights.',
                               type=str,
                               kind='option',
                               abbrev='m'),
    output_path=plac.Annotation('The path to save the model output to.',
                                type=str,
                                kind='option',
                                abbrev='o'),
)
def main(image_path, model_path='model.pt', output_path=None):
    print("Loading model...")
    device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
Example #27
0
import plac
from selenium import webdriver
from src.udemy import Udemy
from src.errors import Error, LoginNotFound

import configparser
from config import UDEMY, COUPONS, Config


@plac.annotations(pages=plac.Annotation("Number of pages to scan", "option"),
                  keywords=plac.Annotation("Path to the keywords file",
                                           "option"),
                  driverpath=plac.Annotation("Path to the web driver",
                                             "option"),
                  config=plac.Annotation("Path to the config file", "option"))
def main(pages, keywords, driverpath, config=".config/config.ini"):
    try:
        options = Config(config, pages, keywords, driverpath)
    except configparser.Error:
        print("Impossible to parse the config file")
        exit(1)
    except KeyError:
        print("Invalid configuration file")
        exit(1)
    except ValueError:
        print("Configuration value given is invalid")
        exit(1)

    try:
        keys = list(options.keywords())
    except (IOError, FileNotFoundError):
Example #28
0
from typing import Optional

import plac

from crypto.ciphers.caesar import CaesarCipher, CaesarCipherKey
from crypto.ciphers.utils import is_valid
from crypto.common_attacks import LetterFrequencyAttack, DictionaryAttack, LanguageAnalysisAttack
from crypto.metrics import print_attack_summary
from crypto.strategies import ExhaustiveSampling
from crypto.types import Message


@plac.annotations(key=plac.Annotation(
    "The key to use for the caesar cipher. This is typically an integer in the range [0, 25]."
    "If not specified then a key is chosen at random.",
    kind='option',
    type=int),
                  filename=plac.Annotation(
                      'The name of a file to use as the message.',
                      kind='option',
                      type=str,
                      abbrev='f'))
def main(key: Optional[int] = None, filename: Optional[str] = None) -> int:
    """A demonstration of the Caesar cipher."""

    if filename:
        with open(filename, 'r') as f:
            message = Message(f.read())
    else:
        message = Message(input('Enter a message to encrypt: '))
Example #29
0
import PyPDF2
import os
import json
import plac
from pathlib import Path
import codecs
from io import StringIO
import string
import csv
from modules import cleaner


@plac.annotations(
    command=plac.Annotation("command", type=str),
    input_source=plac.Annotation("Connection string", type=Path),
    output_file=plac.Annotation("Connection string", type=Path),
    label=plac.Annotation("Label",  'option', 'l', type=str),
    extend=plac.Annotation("Extend an exsiting dataset", 'flag', 'e'))
def main(command, input_source, output_file, label, extend):
    output_mode = 'a' if extend else 'w'

    if command == 'pdf':
        # Convert the pdfs of the given directory or if the input is a single file only this file

        with open(str(output_file), output_mode) as jsonl_file:

            if str(input_source).endswith(".pdf"):
                text = pdf_to_text(str(input_source))

                jsonl_file.write(json.dumps({"text": text.strip('\n')}) + '\n')
            else:
Example #30
0
                data = set([spl[1]])
            else:
                data = set(token.strip() for token in spl[2:])

            class_num = classes[curr_line]
            to_cmp[class_num].update(data)

    return to_cmp


def asym_jaccard(first_set, second_set):
    intersect = first_set.intersection(second_set)
    return len(intersect) / len(first_set)


@plac.annotations(features_fpath=plac.Annotation('Tags file', type=str),
                  classes_fpath=plac.Annotation('Video classes file',
                                                type=str),
                  user_users=plac.Annotation('Use user_names instead of tags',
                                             kind='flag',
                                             abbrev='u',
                                             type=bool))
def main(features_fpath, classes_fpath, user_users=False):

    initialize_matplotlib()

    classes = np.loadtxt(classes_fpath)
    num_classes = len(set(classes))

    to_compare = load_text_file(features_fpath, classes, user_users)