Skip to content

Commit

Permalink
Merge pull request #178 from tattle-made/hotfix
Browse files Browse the repository at this point in the history
Hotfix
  • Loading branch information
duggalsu authored Mar 14, 2024
2 parents eabb672 + c846df5 commit a85423a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ RUN pip install --no-cache-dir --upgrade pip
RUN apt-get update && apt-get -y upgrade && apt-get install -y --no-install-recommends wget curl grep
COPY --chown=python:python requirements.txt /usr/app/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Install operators before code copy to speedup docker build on code changes
COPY --chown=python:python ./core/operators/vid_vec_rep_resnet_requirements.txt /usr/app/core/operators/vid_vec_rep_resnet_requirements.txt
RUN pip install --no-cache-dir -r /usr/app/core/operators/vid_vec_rep_resnet_requirements.txt
COPY --chown=python:python ./core/operators/audio_vec_embedding_requirements.txt /usr/app/core/operators/audio_vec_embedding_requirements.txt
RUN pip install --no-cache-dir -r /usr/app/core/operators/audio_vec_embedding_requirements.txt

COPY --chown=python:python . /usr/app

#### TEST IMAGE ####
FROM base AS test
RUN cd core/operators \
&& pip install --no-cache-dir -r vid_vec_rep_resnet_requirements.txt \
&& pip install --no-cache-dir -r audio_vec_embedding_requirements.txt
USER 999
19 changes: 14 additions & 5 deletions src/core/models/media_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import wget
from core.models.media import MediaType
import logging
import os
import tempfile

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -70,15 +72,18 @@ def make_from_file_in_memory(image_data: FileStorage):
class VideoFactory:
@staticmethod
def make_from_url(video_url):
fname = "/tmp/vid.mp4"
temp_dir = tempfile.gettempdir()
temp_url = video_url.split("?")[0]
file_name = temp_url.split("/")[-1] + ".mp4"
file_path = temp_dir + os.sep + file_name
try:
print("Downloading video from url")
wget.download(video_url, out=fname)
wget.download(video_url, out=file_path)
print("video downloaded")
except Exception as e:
log.exception("Error downloading video:", e)
raise Exception("Error Downloading Video")
return {"path": fname}
return {"path": file_path}

@staticmethod
def make_from_file_on_disk(video_path):
Expand All @@ -87,14 +92,18 @@ def make_from_file_on_disk(video_path):
@staticmethod
def make_from_file_in_memory(file_data: FileStorage):
# save on disk
fname = "/tmp/" + file_data.filename
fname = tempfile.gettempdir() + os.sep + file_data.filename
file_data.save(fname)
return {"path": fname}


class AudioFactory:
@staticmethod
def make_from_url(audio_url):
audio_file = "/tmp/audio.wav"
temp_dir = tempfile.gettempdir()
temp_url = audio_url.split("?")[0]
file_name = temp_url.split("/")[-1] + ".wav"
audio_file = temp_dir + os.sep + file_name
try:
print("Downloading audio from url")
wget.download(audio_url, out=audio_file)
Expand Down
2 changes: 0 additions & 2 deletions src/tests/core/models/test_media_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def test_video_make_from_url(self):
video_url = "https://tattle-media.s3.amazonaws.com/test-data/tattle-search/cat_vid_2mb.mp4"
result = VideoFactory.make_from_url(video_url)
self.assertIsNotNone(result["path"])
self.assertEqual(result["path"], "/tmp/vid.mp4")

# @skip
def test_video_make_from_file_on_disk(self):
Expand All @@ -52,7 +51,6 @@ def test_audio_make_from_url(self):
"https://raw.githubusercontent.com/tattle-made/feluda/main/src/core/operators/sample_data/audio.wav"
)
self.assertIsNotNone(result["path"])
self.assertEqual(result["path"], "/tmp/audio.wav")

# @skip
def test_audio_make_from_file_on_disk(self):
Expand Down

0 comments on commit a85423a

Please sign in to comment.