Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media upload datasource! #419

Merged
merged 24 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d46feae
basic changes to allow files box
dale-wahl Mar 27, 2024
cffe373
basic imports, yay!
dale-wahl Mar 27, 2024
888b078
video_scene_timelines to work on video imports!
dale-wahl Mar 27, 2024
677fd7a
add is_compatible_with checks to processors that cannot run on new me…
dale-wahl Mar 27, 2024
6c84ecd
more is_compatible fixes
dale-wahl Mar 27, 2024
9f8b089
necessary function for checking media_types
dale-wahl Mar 27, 2024
53426fe
enable more processors on media datasets
dale-wahl Mar 28, 2024
73580e9
Merge branch 'master' into media_upload
dale-wahl May 2, 2024
b082fbc
Merge branch 'master' into media_upload
dale-wahl May 3, 2024
30c5975
consolidate user_input file type
dale-wahl May 3, 2024
e5d8ef1
detect mimetype from filename
dale-wahl May 6, 2024
43ba4ca
handle zip archives; allow log and metadata files
dale-wahl May 7, 2024
1c7ba16
do not count metadata or log files in num_files
dale-wahl May 7, 2024
8c1eca8
Merge branch 'master' into media_upload
dale-wahl May 28, 2024
91e8697
move machine learning processors so they can be imported elsewhere
dale-wahl May 29, 2024
14f1539
audio_to_text datasource
dale-wahl May 29, 2024
211c4d8
Merge branch 'master' into media_upload
dale-wahl Jun 19, 2024
fd11a7e
When validating zip file uploads, send list of file attributes instea…
stijn-uva Jun 20, 2024
86df7e6
Check type of files in zip when uploading media
stijn-uva Jun 21, 2024
7e144fc
Skip useless files when uploading media as zip
stijn-uva Jun 21, 2024
2ee050f
Merge branch 'master' into media_upload
stijn-uva Jun 21, 2024
f34b054
check multiple zip types in JS
dale-wahl Jun 25, 2024
8225871
js !=== python
dale-wahl Jun 25, 2024
4f7cfc1
fix media_type for loose file imports; fix extension for audio_to_tex…
dale-wahl Jun 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion LICENSE-3DPARTY
Original file line number Diff line number Diff line change
Expand Up @@ -802,4 +802,38 @@ Incorporates the Graphology graph manipulation library
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.

-------------------------------------------------------------------------------
Incorporates the zip.js library
- at /webtool/static/js/zip.min.js
- from https://github.com/gildas-lormeau/zip.js

BSD 3-Clause License

Copyright (c) 2023, Gildas Lormeau

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12 changes: 12 additions & 0 deletions common/lib/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,18 @@ def get_extension(self):

return False

def get_media_type(self):
"""
Gets the media type of the dataset file.
:return str: media type, e.g., "text"
"""
if hasattr(self, "media_type"):
return self.media_type
else:
# Default to text
return self.parameters.get("media_type", "text")

def get_result_url(self):
"""
Gets the 4CAT frontend URL of a dataset file.
Expand Down
17 changes: 17 additions & 0 deletions common/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,23 @@ def timify_long(number):

return time_str + last_str

def andify(items):
"""
Format a list of items for use in text
Returns a comma-separated list, the last item preceded by "and"
:param items: Iterable list
:return str: Formatted string
"""
if len(items) == 0:
return ""
elif len(items) == 1:
return str(items[1])

result = f" and {items.pop()}"
return ", ".join([str(item) for item in items]) + result


def get_yt_compatible_ids(yt_ids):
"""
Expand Down
6 changes: 6 additions & 0 deletions datasources/audio_to_text/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Use default data source init function
from common.lib.helpers import init_datasource

# Internal identifier for this data source
DATASOURCE = "upload-audio-to-text"
NAME = "Upload Audio to Text"
56 changes: 56 additions & 0 deletions datasources/audio_to_text/audio_to_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Audio Upload to Text

This data source acts similar to a Preset, but because it needs SearchMedia's validate_query and after_create methods
to run, chaining that processor does not work (Presets essentially only run the process and after_process methods
of their processors and skip those two datasource only methods).
"""

from datasources.media_import.import_media import SearchMedia
from processors.machine_learning.whisper_speech_to_text import AudioToText


class AudioUploadToText(SearchMedia):
type = "upload-audio-to-text-search" # job ID
category = "Search" # category
title = "Convert speech to text" # title displayed in UI
description = "Upload your own audio and use OpenAI's Whisper model to create transcripts" # description displayed in UI
extension = "ndjson" # extension of result file, used internally and in UI
is_local = False # Whether this datasource is locally scraped
is_static = False # Whether this datasource is still updated

@classmethod
def is_compatible_with(cls, module=None, user=None):
#TODO: False here does not appear to actually remove the datasource from the "Create dataset" page so technically
# this method is not necessary; if we can adjust that behavior, it ought to function as intended

# Ensure the Whisper model is available
return AudioToText.is_compatible_with(module=module, user=user)

@classmethod
def get_options(cls, parent_dataset=None, user=None):
# We need both sets of options for this datasource
media_options = SearchMedia.get_options(parent_dataset=parent_dataset, user=user)
whisper_options = AudioToText.get_options(parent_dataset=parent_dataset, user=user)
media_options.update(whisper_options)

#TODO: there are some odd formatting issues if we use those derived options
# The intro help text is not displayed correct (does not wrap)
# Advanced Settings uses []() links which do not work on the "Create dataset" page, so we adjust

media_options["intro"]["help"] = ("Upload audio files here to convert speech to text. "
"4CAT will use OpenAI's Whisper model to create transcripts."
"\n\nFor information on using advanced settings: [Command Line Arguments (CLI)](https://github.com/openai/whisper/blob/248b6cb124225dd263bb9bd32d060b6517e067f8/whisper/transcribe.py#LL374C3-L374C3)")
media_options["advanced"]["help"] = "Advanced Settings"

return media_options

@staticmethod
def validate_query(query, request, user):
# We need SearchMedia's validate_query to upload the media
media_query = SearchMedia.validate_query(query, request, user)

# Here's the real trick: act like a preset and add another processor to the pipeline
media_query["next"] = [{"type": "audio-to-text",
"parameters": query.copy()}]
return media_query
6 changes: 6 additions & 0 deletions datasources/media_import/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Use default data source init function
from common.lib.helpers import init_datasource

# Internal identifier for this data source
DATASOURCE = "media-import"
NAME = "Import/upload Media files"
Loading