-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
20 additions
and
25 deletions.
There are no files selected for viewing
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
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,27 +1,25 @@ | ||
from contextlib import contextmanager | ||
import os | ||
import tempfile | ||
import requests | ||
from typing import Sequence, Generator | ||
from typing import Sequence, Generator, List | ||
|
||
from elevenlabs.client import ElevenLabs | ||
|
||
IN_GITHUB = "GITHUB_ACTIONS" in os.environ | ||
|
||
client = ElevenLabs() | ||
|
||
@contextmanager | ||
def as_local_files(urls: Sequence[str]) -> Generator[list[str], None, None]: | ||
|
||
def as_local_files(urls: Sequence[str]) -> Generator[str, None, None]: | ||
"""Util to download files from urls and return local file paths""" | ||
file_paths = [] | ||
|
||
temp_files = [] | ||
for url in urls: | ||
response = requests.get(url) | ||
temp_file = tempfile.NamedTemporaryFile() | ||
temp_file.write(response.content) | ||
file_paths.append(temp_file.name) | ||
temp_files.append(temp_file) | ||
yield file_paths | ||
yield temp_file.name | ||
# Remove the files | ||
for temp_file in temp_files: | ||
temp_file.close() |