Exemple #1
0
    def reload(self):
        self.tasks = None
        self.derived_input_schema = []
        self.derived_output_schema = {
            'from_name_to_name_type': set(),
            'labels': defaultdict(set)
        }

        self._init()

        self.label_config_full = config_comments_free(
            open(self.config['label_config']).read())
        self.label_config_line = config_line_stripped(self.label_config_full)

        if self.analytics is None:
            self.analytics = Analytics(
                self.label_config_line,
                self.config.get('collect_analytics', True), self.name)
        else:
            self.analytics.update_info(
                self.label_config_line,
                self.config.get('collect_analytics', True), self.name)

        # configure project
        self.project_obj = ProjectObj(label_config=self.label_config_line,
                                      label_config_full=self.label_config_full)

        # configure machine learning backend
        if self.ml_backend is None:
            ml_backend_params = self.config.get('ml_backend')
            if ml_backend_params:
                ml_backend = MLBackend.from_params(ml_backend_params)
                self.project_obj.connect(ml_backend)

        self.converter = Converter(self.label_config_full)
 def prepare_globals():
     # setup session cookie
     if 'session_id' not in session:
         session['session_id'] = str(uuid4())
     g.project = project_get_or_create()
     g.analytics = Analytics(current_app.label_studio.input_args, g.project)
     g.sid = g.analytics.server_id
Exemple #3
0
 def load_analytics(self):
     collect_analytics = os.getenv('collect_analytics')
     if collect_analytics is None:
         collect_analytics = self.config.get('collect_analytics', True)
     collect_analytics = bool(collect_analytics)
     self.analytics = Analytics(self.label_config_line, collect_analytics,
                                self.name, self.context)
def app_before_request_callback():
    # setup session cookie
    if 'session_id' not in session:
        session['session_id'] = str(uuid4())
    g.project = project_get_or_create()
    g.analytics = Analytics(input_args, g.project)
    g.sid = g.analytics.server_id
Exemple #5
0
def reload_config(prompt_inputs=False, force=False):
    global c
    global label_config_line
    global analytics
    global ml_backend
    global project
    global config_path

    # Read config from config.json & input arguments
    c = json.load(open(config_path))
    c['port'] = input_args.port if input_args.port else c['port']
    c['label_config'] = input_args.label_config if input_args.label_config else c[
        'label_config']
    c['input_path'] = input_args.input_path if input_args.input_path else c[
        'input_path']
    c['output_dir'] = input_args.output_dir if input_args.output_dir else c[
        'output_dir']
    c['debug'] = input_args.debug if input_args.debug is not None else c[
        'debug']

    # If specified, prompt user in console about specific inputs
    if prompt_inputs:
        iprompt = LabelStudioConfigPrompt(c)
        c['input_data'] = iprompt.ask_input_path()
        c['output_dir'] = iprompt.ask_output_dir()
        c['label_config'] = iprompt.ask_label_config()

    # Initialize DBs
    db.re_init(c)

    label_config_full = config_comments_free(open(c['label_config']).read())
    label_config_line = config_line_stripped(label_config_full)
    if analytics is None:
        analytics = Analytics(label_config_line,
                              c.get('collect_analytics', True))
    else:
        analytics.update_info(label_config_line,
                              c.get('collect_analytics', True))
    # configure project
    if project is None or force:
        project = Project(label_config=label_config_line,
                          label_config_full=label_config_full)
    # configure machine learning backend
    if ml_backend is None or force:
        ml_backend_params = c.get('ml_backend')
        if ml_backend_params:
            ml_backend = MLBackend.from_params(ml_backend_params)
            project.connect(ml_backend)

    return True