Skip to content

Commit

Permalink
cleaned imports and arguments, fixed wrongdoing with warning, changed…
Browse files Browse the repository at this point in the history
… `credit` label back to `credits`

- clamsproject/mmif#188 (comment)
- clamsproject/app-role-filler-binder#2 (comment)
- importing `app.py` from `metadata.py` requires the entire dependencies to be in place. I change the dependency direction so that `metadata.py` can run just with `clams-python` dependency
  • Loading branch information
keighrim committed Jun 26, 2024
1 parent dede3ef commit 7ebfb54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
14 changes: 5 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,23 @@
"""

import time
import argparse
import logging
from pathlib import Path
import time
import warnings
from typing import Union

import yaml
from clams import ClamsApp, Restifier
from mmif import Mmif, View, AnnotationTypes, DocumentTypes
from mmif.utils import video_document_helper as vdh

from metadata import default_model_storage
from modeling import classify, stitch, negative_label, FRAME_TYPES

default_model_storage = Path(__file__).parent / 'modeling/models'


class SwtDetection(ClamsApp):

def __init__(self, preconf_fname: str = None, log_to_file: bool = False) -> None:
def __init__(self, log_to_file: bool = False) -> None:
super().__init__()
if log_to_file:
fh = logging.FileHandler(f'{self.__class__.__name__}.log')
Expand All @@ -49,8 +47,7 @@ def _annotate(self, mmif: Union[str, dict, Mmif], **parameters) -> Mmif:

videos = mmif.get_documents_by_type(DocumentTypes.VideoDocument)
if not videos:
warning = Warning('There were no video documents referenced in the MMIF file')
classifier_view.metadata.add_warnings(warning)
warnings.warn('There were no video documents referenced in the MMIF file', UserWarning)
return mmif
video = videos[0]
self.logger.info(f"Processing video {video.id} at {video.location_path()}")
Expand Down Expand Up @@ -184,7 +181,6 @@ def transform(classification: dict, postbin: dict):
for postlabel, prelabels in postbin.items():
transformed[postlabel] = sum([classification[lbl] for lbl in prelabels])
return transformed



if __name__ == "__main__":
Expand Down
11 changes: 5 additions & 6 deletions metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
Metadata for the Scenes-with-text app.
"""

import pathlib
import sys
import yaml
from pathlib import Path

from clams.app import ClamsApp
from clams.appmetadata import AppMetadata
from mmif import DocumentTypes, AnnotationTypes
from app import default_model_storage

from modeling import FRAME_TYPES

default_model_storage = Path(__file__).parent / 'modeling/models'


def appmetadata() -> AppMetadata:
"""
Expand All @@ -33,7 +32,7 @@ def appmetadata() -> AppMetadata:
"S:slate", "S-H:slate", "S-C:slate", "S-D:slate", "S-G:slate",
"W:other_opening", "L:other_opening", "O:other_opening", "M:other_opening",
"I:chyron", "N:chyron", "Y:chyron",
"C:credit", "R:credit",
"C:credits", "R:credits",
"E:other_text", "K:other_text", "G:other_text", "T:other_text", "F:other_text" ]

metadata = AppMetadata(
Expand Down

0 comments on commit 7ebfb54

Please sign in to comment.