format and imports

This commit is contained in:
Tanishq Dubey 2023-03-17 22:36:21 -04:00
parent d83aeba336
commit ddb53c1111
3 changed files with 25 additions and 14 deletions

12
main.py
View File

@ -13,15 +13,19 @@ from src.utils.prereq import check_ffmpeg
check_ffmpeg() check_ffmpeg()
from src.editors.amplitude.editor import AmplitudeEditor from src.editors.amplitude.editor import AmplitudeEditor
from src.editors.sentiment.editor import SentimentEditor
from src.editors.passthrough.editor import PassthroughEditor from src.editors.passthrough.editor import PassthroughEditor
from src.editors.sentiment.editor import SentimentEditor
from src.math.cost import quadratic_loss from src.math.cost import quadratic_loss
from src.mediautils.audio import extract_audio_from_video from src.mediautils.audio import extract_audio_from_video
from src.mediautils.video import render_moments from src.mediautils.video import render_moments
log = structlog.get_logger() log = structlog.get_logger()
EDITORS = {"amplitude": AmplitudeEditor, "sentiment": SentimentEditor, "passthrough": PassthroughEditor} EDITORS = {
"amplitude": AmplitudeEditor,
"sentiment": SentimentEditor,
"passthrough": PassthroughEditor,
}
ERROR_FUNCS = {"quadratic": quadratic_loss} ERROR_FUNCS = {"quadratic": quadratic_loss}
@ -95,7 +99,9 @@ def main(args):
sys.exit(-1) sys.exit(-1)
if len(result) == 0: if len(result) == 0:
log.fatal("no viable edit was found for the provided parameters, please try again with different values") log.fatal(
"no viable edit was found for the provided parameters, please try again with different values"
)
sys.exit(-2) sys.exit(-2)
log.info( log.info(

View File

@ -1,13 +1,14 @@
import concurrent.futures
import random
import numpy as np import numpy as np
import structlog import structlog
import random
import concurrent.futures
from ...math.average import np_moving_average from ...math.average import np_moving_average
from ...math.distribution import create_distribution from ...math.distribution import create_distribution
from ...mediautils.audio import process_audio, resample from ...mediautils.audio import process_audio, resample
from ..common import find_moving_average_highlights
from ...mediautils.video import filter_moments from ...mediautils.video import filter_moments
from ..common import find_moving_average_highlights
class AmplitudeEditor: class AmplitudeEditor:
@ -51,7 +52,7 @@ class AmplitudeEditor:
# The decay rate, or how quickly our spread multiplier decreases as we approach the center of the gradient # The decay rate, or how quickly our spread multiplier decreases as we approach the center of the gradient
spread_decay = random.uniform(0.000001, 0.0001) spread_decay = random.uniform(0.000001, 0.0001)
parallelism = params['parallelism'] parallelism = params["parallelism"]
# The main loop of the program starts here # The main loop of the program starts here
# we first create distributions # we first create distributions
@ -100,7 +101,9 @@ class AmplitudeEditor:
durations = [] durations = []
for result in moment_results: for result in moment_results:
total_duration = 0 total_duration = 0
result[0] = filter_moments(result[0], params['mindur'], params['maxdur']) result[0] = filter_moments(
result[0], params["mindur"], params["maxdur"]
)
for moment in result[0]: for moment in result[0]:
total_duration = total_duration + moment.get_duration() total_duration = total_duration + moment.get_duration()
costs.append(costfunc(desired, total_duration)) costs.append(costfunc(desired, total_duration))

View File

@ -1,10 +1,9 @@
import concurrent.futures
import json import json
import random
import tempfile import tempfile
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path from pathlib import Path
import random
import concurrent.futures
from ...math.distribution import create_distribution
import numpy as np import numpy as np
import structlog import structlog
@ -13,8 +12,9 @@ from flair.data import Sentence
from flair.models import TextClassifier from flair.models import TextClassifier
from ...math.average import np_moving_average from ...math.average import np_moving_average
from ..common import find_moving_average_highlights from ...math.distribution import create_distribution
from ...mediautils.video import filter_moments from ...mediautils.video import filter_moments
from ..common import find_moving_average_highlights
@dataclass @dataclass
@ -87,7 +87,7 @@ class SentimentEditor:
# The decay rate, or how quickly our spread multiplier decreases as we approach the center of the gradient # The decay rate, or how quickly our spread multiplier decreases as we approach the center of the gradient
spread_decay = random.uniform(0.000001, 0.0001) spread_decay = random.uniform(0.000001, 0.0001)
parallelism = params['parallelism'] parallelism = params["parallelism"]
# The main loop of the program starts here # The main loop of the program starts here
# we first create distributions # we first create distributions
@ -136,7 +136,9 @@ class SentimentEditor:
durations = [] durations = []
for result in moment_results: for result in moment_results:
total_duration = 0 total_duration = 0
result[0] = filter_moments(result[0], params['mindur'], params['maxdur']) result[0] = filter_moments(
result[0], params["mindur"], params["maxdur"]
)
for moment in result[0]: for moment in result[0]:
total_duration = total_duration + moment.get_duration() total_duration = total_duration + moment.get_duration()
costs.append(costfunc(desired, total_duration)) costs.append(costfunc(desired, total_duration))