-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds srt wrap and upgrades isolated_environment to use the new patter…
…n of installing dependencies
- Loading branch information
Showing
8 changed files
with
69 additions
and
43 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0
test.sh → test
100755 → 100644
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
1 | ||
00:00:00,000 --> 00:00:03,240 | ||
sdjfksdl ksdj fklsd;jf sdl;kfj sd;lkj fdklsfj sd;klf jwsdk fsdj fksdj fsdl;k fjds;kl fjsdkl; fjsd;klf jksdlj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
Tests transcribe_anything | ||
""" | ||
|
||
# pylint: disable=bad-option-value,useless-option-value,no-self-use,protected-access,R0801 | ||
# flake8: noqa E501 | ||
|
||
import os | ||
import unittest | ||
import shutil | ||
from pathlib import Path | ||
import tempfile | ||
from transcribe_anything.insanely_fast_whisper import ( | ||
srt_wrap_to_string, | ||
has_nvidia_smi, | ||
) | ||
|
||
|
||
HERE = Path(os.path.abspath(os.path.dirname(__file__))) | ||
LOCALFILE_DIR = HERE / "localfile" | ||
TEST_SRT = LOCALFILE_DIR / "long.srt" | ||
|
||
|
||
class InsanelFastWhisperTester(unittest.TestCase): | ||
"""Tester for transcribe anything.""" | ||
|
||
@unittest.skipUnless(has_nvidia_smi(), "No GPU detected") | ||
def test_srt_wrap(self) -> None: | ||
"""Check that the command works on a local file.""" | ||
with tempfile.TemporaryDirectory() as tempdir: | ||
td = Path(tempdir) | ||
target = td / "long.srt" | ||
shutil.copy(TEST_SRT, target) | ||
wrapped_srt = srt_wrap_to_string(target) | ||
print(wrapped_srt) | ||
print() | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +0,0 @@ | ||
""" | ||
Wraps the srt file. | ||
""" | ||
|
||
# designed to be run in an isolated environment. | ||
|
||
from argparse import ArgumentParser, Namespace | ||
import sys | ||
from srtranslator import SrtFile # type: ignore | ||
|
||
|
||
# srtranslator==0.2.6 | ||
def srt_wrap(srt_file: str, out_file: str) -> None: | ||
"""Wrap lines in a srt file.""" | ||
srt = SrtFile(srt_file) | ||
srt.wrap_lines() | ||
srt.save(out_file) | ||
|
||
|
||
def create_args() -> Namespace: | ||
"""Create args.""" | ||
parser = ArgumentParser(description="Wrap lines in a srt file.") | ||
parser.add_argument("src_srt_file", help="The srt file to wrap.") | ||
parser.add_argument("dst_srt_file", help="The output file.", nargs="?") | ||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
def main() -> int: | ||
"""Main entry point for the command line tool.""" | ||
args = create_args() | ||
srt_wrap(args.src_srt_file, args.dst_srt_file or args.src_srt_file) | ||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters