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

Feature/matter index pipeline #99

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Merging changes from upstream
  • Loading branch information
Shak2000 committed Sep 6, 2021
commit b96c1f06ba8a025f07e422e2f7b5610bf990a336
36 changes: 12 additions & 24 deletions cdp_backend/utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
from typing import Optional, Tuple, Union

import fsspec
import imageio
import numpy as np
from fsspec.core import url_to_fs
from PIL import Image

###############################################################################

Expand Down Expand Up @@ -207,6 +204,8 @@ def get_static_thumbnail(
The name of the thumbnail file:
Always session_content_hash + "-static-thumbnail.png"
"""
import imageio
from PIL import Image

reader = imageio.get_reader(video_path)
png_path = ""
Expand All @@ -221,15 +220,9 @@ def get_static_thumbnail(
reader = imageio.get_reader(video_path)
image = reader.get_data(0)

if image.shape[0] > MAX_THUMBNAIL_HEIGHT or image.shape[1] > MAX_THUMBNAIL_WIDTH:
height_ratio = MAX_THUMBNAIL_HEIGHT / image.shape[0]
width_ratio = MAX_THUMBNAIL_WIDTH / image.shape[1]

if height_ratio > width_ratio:
final_ratio = height_ratio
else:
final_ratio = width_ratio
final_ratio = find_proper_resize_ratio(image.shape[0], image.shape[1])

if final_ratio < 1:
image = Image.fromarray(image).resize(
(
math.floor(image.shape[1] * final_ratio),
Expand Down Expand Up @@ -264,6 +257,10 @@ def get_hover_thumbnail(
The name of the thumbnail file:
Always session_content_hash + "-hover-thumbnail.png"
"""
import imageio
import numpy as np
from PIL import Image

reader = imageio.get_reader(video_path)
gif_path = ""
if reader.get_length() > 1:
Expand All @@ -274,27 +271,18 @@ def get_hover_thumbnail(
count += 1
step_size = math.floor(count / num_frames)

final_ratio = 1
height = image.shape[0]
width = image.shape[1]

if height > MAX_THUMBNAIL_HEIGHT or width > MAX_THUMBNAIL_WIDTH:
height_ratio = MAX_THUMBNAIL_HEIGHT / height
width_ratio = MAX_THUMBNAIL_WIDTH / width

if height_ratio > width_ratio:
final_ratio = height_ratio
else:
final_ratio = width_ratio
final_ratio = find_proper_resize_ratio(height, width)

with imageio.get_writer(gif_path, mode="I") as writer:
for i in range(0, num_frames):
if final_ratio == 1:
image = Image.fromarray(reader.get_data(i * step_size))
else:
if final_ratio < 1:
image = Image.fromarray(reader.get_data(i * step_size)).resize(
(math.floor(width * final_ratio), math.floor(height * final_ratio))
)
else:
image = Image.fromarray(reader.get_data(i * step_size))

final_image = np.asarray(image, dtype="int32")
writer.append_data(final_image)
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
"imageio-ffmpeg~=0.4.4",
"nltk~=3.6",
"pandas~=1.2",
"pdftotext~=2.2.0",
"prefect~=0.14.0",
"pulumi~=3.3",
"pulumi-google-native~=0.7.0",
"pulumi-gcp~=5.7",
"rapidfuzz~=1.4",
"spacy~=3.0",
"textract~=1.6.4",
"truecase~=0.0.12",
"webvtt-py~=0.4.6",
]
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.