-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from jhj0517/feature/local-input
Add local input folder path
- Loading branch information
Showing
3 changed files
with
55 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
import fnmatch | ||
|
||
from gradio.utils import NamedString | ||
|
||
|
||
def get_media_files(folder_path, include_sub_directory=False): | ||
video_extensions = ['*.mp4', '*.mkv', '*.flv', '*.avi', '*.mov', '*.wmv'] | ||
audio_extensions = ['*.mp3', '*.wav', '*.aac', '*.flac', '*.ogg', '*.m4a'] | ||
media_extensions = video_extensions + audio_extensions | ||
|
||
media_files = [] | ||
|
||
if include_sub_directory: | ||
for root, _, files in os.walk(folder_path): | ||
for extension in media_extensions: | ||
media_files.extend( | ||
os.path.join(root, file) for file in fnmatch.filter(files, extension) | ||
if os.path.exists(os.path.join(root, file)) | ||
) | ||
else: | ||
for extension in media_extensions: | ||
media_files.extend( | ||
os.path.join(folder_path, file) for file in fnmatch.filter(os.listdir(folder_path), extension) | ||
if os.path.isfile(os.path.join(folder_path, file)) and os.path.exists(os.path.join(folder_path, file)) | ||
) | ||
|
||
return media_files | ||
|
||
|
||
def format_gradio_files(files: list): | ||
if not files: | ||
return files | ||
|
||
gradio_files = [] | ||
for file in files: | ||
gradio_files.append(NamedString(file)) | ||
return gradio_files | ||
|
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