From b8476a5d3b5279ccf49f85dcb3feac48dbb0438b Mon Sep 17 00:00:00 2001 From: Hayden McCormick Date: Sat, 9 Sep 2023 13:54:35 -0400 Subject: [PATCH 1/5] Fix VTT formatting issues (#29) --- utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index 1a7150a..f0c6d01 100644 --- a/utils.py +++ b/utils.py @@ -49,11 +49,13 @@ def get_alignments(alignment_view): start, end, text = start_end_text start_kwarg, end_kwarg = {timeunit: float(start)}, {timeunit: float(end)} start, end = timedelta(**start_kwarg), timedelta(**end_kwarg) + s_mins, s_secs = divmod(start.seconds, 60) + e_mins, e_secs = divmod(end.seconds, 60) if not vtt_start: - vtt_start = f'{start.seconds // 3600 :02d}:{start.seconds:02d}.{start.microseconds // 1000 :03d}' + vtt_start = f'{s_mins:02d}:{s_secs:02d}.{((s_secs - int(s_secs)) * 1000):03d}' texts.append(text) if len(texts) > 8: - vtt_end = f'{end.seconds // 3600 :02d}:{end.seconds:02d}.{end.microseconds // 1000 :03d}' + vtt_end = f'{e_mins:02d}:{e_secs:02d}.{((e_secs - int(e_secs)) * 1000):03d}' vtt_file.write(f'{vtt_start} --> {vtt_end}\n{" ".join(texts)}\n\n') vtt_start = None texts = [] From bf466e724d79f01869ee145db5963bf90911ee9a Mon Sep 17 00:00:00 2001 From: Hayden McCormick Date: Sat, 16 Sep 2023 14:01:49 -0400 Subject: [PATCH 2/5] Add script for server quick start --- README.md | 15 +++++++++++++++ start_visualizer.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 start_visualizer.sh diff --git a/README.md b/README.md index c8984e9..b16b4c7 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,21 @@ To get this code if you don't already have it: $ git clone https://github.com/clamsproject/mmif-visualizer ``` +## Quick start + +If you just want to get the server up and running quickly, the repository contains a shell script `start_visualizer.sh` to immediately launch the visualizer in a container. You can invoke it with the following command: + +``` +./start_visualizer.sh +``` + +* The **required** `data_directory` argument should be the absolute or relative path of the media files on your machine which the MMIF files reference. +* The **optional** `mount_directory` argument should be specified if your MMIF files point to a different directory than where your media files are stored on the host machine. For example, if your video, audio, and text data is stored locally at `/home/archive` but your MMIF files refer to `/data/...`, you should set this variable to `/data`. (If this variable is not set, the mount directory will default to the data directory) + +For example, if your media files are stored at `/llc_data` and your MMIF files specify the document location as `"location": "file:///data/...`, you can start the visualizer with the following command: +``` +./start_visualizer.sh /llc_data /data +``` ## Running the server in a container diff --git a/start_visualizer.sh b/start_visualizer.sh new file mode 100755 index 0000000..0d96c93 --- /dev/null +++ b/start_visualizer.sh @@ -0,0 +1,31 @@ +# Check for presence of Docker/Podman engines +if command -v doscker &> /dev/null +then + export container_engine=docker +elif command -v podman &> /dev/null +then + export container_engine=podman +else + echo "Error: Docker or Podman not found. Please install container engine and try again." + exit 1 +fi +# Return if no inputs passed +if [ -z "$1" ] +then + echo "Error: no data directory specified." + exit 1 +fi +# Set data directory to absolute path of input +export datadir=$( cd $1; pwd ) +# Set mount directory to data directory if not specified +if [ -z "$2" ] +then + echo "No mount directory specified: defaulting to $datadir" + export mountdir=$datadir +else + export mountdir=$2 +fi +# Start visualizer +$container_engine build . -f Containerfile -t clams-mmif-visualizer +$container_engine run -d --name clams-mmif-visualizer --rm -p 5000:5000 -e PYTHONUNBUFFERED=1 -v $datadir:$mountdir -v $datadir:/app/static/$mountdir clams-mmif-visualizer +echo "MMIF Visualizer is running in the background and can be accessed at http://localhost:5000/. To shut down, run '$container_engine kill clams-mmif-visualizer'" \ No newline at end of file From 483d0118b706c26685d03b7ffccb18063000e494 Mon Sep 17 00:00:00 2001 From: haydenmccormick <74222796+haydenmccormick@users.noreply.github.com> Date: Sat, 16 Sep 2023 14:03:14 -0400 Subject: [PATCH 3/5] README update --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b16b4c7..07f5fb9 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ For example, if your media files are stored at `/llc_data` and your MMIF files s ./start_visualizer.sh /llc_data /data ``` +The server can then be accessed at `http://localhost:5000/upload` ## Running the server in a container From 95a066f6d7085c8d8775dd2f4804f25f13bf5b4c Mon Sep 17 00:00:00 2001 From: Hayden McCormick Date: Sat, 16 Sep 2023 14:10:33 -0400 Subject: [PATCH 4/5] Small bug fix --- start_visualizer.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/start_visualizer.sh b/start_visualizer.sh index 0d96c93..a23ccc4 100755 --- a/start_visualizer.sh +++ b/start_visualizer.sh @@ -1,5 +1,5 @@ # Check for presence of Docker/Podman engines -if command -v doscker &> /dev/null +if command -v docker &> /dev/null then export container_engine=docker elif command -v podman &> /dev/null @@ -28,4 +28,4 @@ fi # Start visualizer $container_engine build . -f Containerfile -t clams-mmif-visualizer $container_engine run -d --name clams-mmif-visualizer --rm -p 5000:5000 -e PYTHONUNBUFFERED=1 -v $datadir:$mountdir -v $datadir:/app/static/$mountdir clams-mmif-visualizer -echo "MMIF Visualizer is running in the background and can be accessed at http://localhost:5000/. To shut down, run '$container_engine kill clams-mmif-visualizer'" \ No newline at end of file +echo "MMIF Visualizer is running in the background and can be accessed at http://localhost:5000/. To shut it down, run '$container_engine kill clams-mmif-visualizer'" \ No newline at end of file From 754aed9ff9808802e24eafda8a97163d5bbfbe96 Mon Sep 17 00:00:00 2001 From: Keigh Rim Date: Sun, 10 Mar 2024 16:28:30 -0400 Subject: [PATCH 5/5] respond to curl requests with full url, "click-able" in term-emus --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 5e53c65..7294b59 100644 --- a/app.py +++ b/app.py @@ -130,7 +130,7 @@ def upload_file(in_mmif): agent = request.headers.get('User-Agent') if 'curl' in agent.lower(): - return f"Visualization ID is {viz_id}\nYou can access the visualized file at /display/{viz_id}\n" + return f"Visualization ID is {viz_id}\nYou can access the visualized file at {request.url_root}display/{viz_id}\n" return redirect(f"/display/{viz_id}", code=301)