Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
943d636
feat: display mesh and pointcloud
Feb 9, 2023
e9acd12
chore: update poetry
Feb 9, 2023
c91ab6c
fix: mypy
Feb 9, 2023
e979c32
fix: add display from param to mesh and pc display
Feb 9, 2023
21fb8ab
fix: clean up
Feb 9, 2023
75b33d8
fix: mypy
Feb 9, 2023
7890194
fix: move display from url to mesh and pc url classes
Feb 10, 2023
0129c3a
chore: remove pyglet dependency
Feb 10, 2023
322a718
chore: update pyproject toml
Feb 10, 2023
05d8461
refactor: copy is notebook function from hubble sdk
Feb 10, 2023
0244816
fix: introduce vertices and faces doc
Feb 10, 2023
255795c
fix: introduce points and colors class for point cloud
Feb 10, 2023
db42712
fix: mypy and tests
Feb 10, 2023
dca04ce
docs: add display example to docs
Feb 10, 2023
788f834
fix: apply johannes suggestion from review
Feb 10, 2023
57fb1e1
fix: apply samis suggestion
Feb 10, 2023
3a8dc5e
docs: update docstring
Feb 14, 2023
38f771d
fix: only display in notebook
Feb 15, 2023
8c31318
docs: update docstring
Feb 15, 2023
bbef411
chore: get poetry lock file from feat rewrite v2
Feb 15, 2023
b376ddd
docs: update docstrings
Feb 15, 2023
016760d
feat: display image from img url and img tensor
Feb 10, 2023
f55d811
fix: display from image url and from image tensor
Feb 13, 2023
0a23b52
fix: use is notebook from utils instead o f hubble
Feb 13, 2023
084921b
feat: audio from url
Feb 14, 2023
a949033
feat: display video and add pydub to pyproject toml
Feb 15, 2023
62b58ee
wip: remove non notebook
Feb 15, 2023
442dd29
fix: all except video tensor
Feb 16, 2023
b486b96
fix: mypy check for ipython display
Feb 16, 2023
f77d216
fix: mypy check for ipython display
Feb 16, 2023
ca948f9
feat: add videobytes
Feb 16, 2023
0dc606c
Merge remote-tracking branch 'origin/feat-rewrite-v2' into feat-displ…
Feb 16, 2023
f2c0cff
Merge remote-tracking branch 'origin/feat-rewrite-v2' into feat-displ…
Feb 16, 2023
48a85ba
chore: poetry lock
Feb 16, 2023
9df9df5
fix: clean up
Feb 16, 2023
e783c14
Merge branch 'feat-rewrite-v2' into feat-display-img-audio-vid
Feb 17, 2023
fe9d3bf
fix: mypy check
Feb 17, 2023
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
Next Next commit
wip: remove non notebook
Signed-off-by: anna-charlotte <[email protected]>
  • Loading branch information
anna-charlotte committed Feb 15, 2023
commit 62b58ee0e57307510a13128d066249480197d42e
34 changes: 5 additions & 29 deletions docarray/typing/tensor/audio/abstract_audio_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import BinaryIO, TypeVar, Union

from docarray.typing.tensor.abstract_tensor import AbstractTensor
from docarray.utils.misc import is_notebook

T = TypeVar('T', bound='AbstractAudioTensor')

Expand Down Expand Up @@ -43,33 +42,10 @@ def save_to_wav_file(
f.writeframes(self.to_bytes())

def display(self, rate=44100):
"""
Play audio data from tensor in notebook.
"""
audio_np = self.get_comp_backend().to_numpy(self)
if is_notebook():
from IPython.display import Audio, display

display(Audio(audio_np, rate=rate))
else:
# b = self.load()
# res = requests.get(self)
# print(f"type(res.text) = {type(res.text)}")
# print(f"type(res.content) = {type(res.content)}")
# sound = AudioSegment.from_file(BytesIO(res.content), "wav")
# sound = AudioSegment.from_file(self, format="wav")
import os
import tempfile

# sound = AudioSegment.from_file(self, format="wav")
# raise NotImplementedError
# from io import BytesIO
# import requests
from pydub import AudioSegment
from pydub.playback import play
from IPython.display import Audio, display

tmp = tempfile.NamedTemporaryFile(delete=False)
try:
self.save_to_wav_file(tmp)
sound = AudioSegment.from_file(tmp, "wav")
play(sound)
finally:
tmp.close()
os.unlink(tmp.name)
display(Audio(audio_np, rate=rate))
10 changes: 3 additions & 7 deletions docarray/typing/tensor/image/abstract_image_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from abc import ABC

from docarray.typing.tensor.abstract_tensor import AbstractTensor
from docarray.utils.misc import is_notebook


class AbstractImageTensor(AbstractTensor, ABC):
Expand Down Expand Up @@ -31,16 +30,13 @@ def to_bytes(self, format: str = 'PNG') -> bytes:

def display(self) -> None:
"""
Display image data from tensor.
Display image data from tensor in notebook.
"""
from PIL import Image

np_array = self.get_comp_backend().to_numpy(self)
img = Image.fromarray(np_array)

if is_notebook():
from IPython.display import display
from IPython.display import display

display(img)
else:
img.show()
display(img)
2 changes: 1 addition & 1 deletion docarray/typing/tensor/video/video_tensor_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ class MyDoc(BaseDocument):

def display(self) -> None:
"""
Display video data from tensor.
Display video data from tensor in notebook.
"""
raise NotImplementedError
26 changes: 5 additions & 21 deletions docarray/typing/url/audio_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from docarray.typing.bytes.audio_bytes import AudioBytes
from docarray.typing.proto_register import _register_proto
from docarray.typing.url.any_url import AnyUrl
from docarray.utils.misc import is_notebook

if TYPE_CHECKING:
from pydantic import BaseConfig
Expand Down Expand Up @@ -71,29 +70,14 @@ class MyDoc(Document):

def display(self):
"""
Play the audio sound from url.
Play the audio sound from url in notebook.
"""
remote_url = True if self.startswith('http') else False

if is_notebook():
from IPython.display import Audio, display
from IPython.display import Audio, display

if remote_url:
display(Audio(data=self))
if remote_url:
display(Audio(data=self))

else:
display(Audio(filename=self))
else:
from pydub import AudioSegment
from pydub.playback import play

if remote_url:
from io import BytesIO

import requests

res = requests.get(self)
sound = AudioSegment.from_file(BytesIO(res.content), "wav")
else:
sound = AudioSegment.from_file(self, format="wav")
play(sound)
display(Audio(filename=self))
16 changes: 5 additions & 11 deletions docarray/typing/url/image_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from docarray.typing.proto_register import _register_proto
from docarray.typing.url.any_url import AnyUrl
from docarray.utils.misc import is_notebook

if TYPE_CHECKING:
from pydantic import BaseConfig
Expand Down Expand Up @@ -92,18 +91,13 @@ class MyDoc(BaseDocument):

def display(self) -> None:
"""
Display image data from url.
Display image data from url in notebook.
"""
remote_url = True if self.startswith('http') else False

if is_notebook():
from IPython.display import Image, display
from IPython.display import Image, display

if remote_url:
display(Image(url=self))
else:
display(Image(filename=self))
if remote_url:
display(Image(url=self))
else:
from PIL import Image

Image.fromarray(self.load()).show()
display(Image(filename=self))
35 changes: 5 additions & 30 deletions docarray/typing/url/video_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from docarray.typing.tensor.ndarray import NdArray
from docarray.typing.tensor.video import VideoNdArray
from docarray.typing.url.any_url import AnyUrl
from docarray.utils.misc import is_notebook

if TYPE_CHECKING:
from pydantic import BaseConfig
Expand Down Expand Up @@ -134,37 +133,13 @@ class MyDoc(BaseDocument):

def display(self):
"""
Play video from url.
Play video from url in notebook.
"""
remote_url = True if self.startswith('http') else False

if is_notebook():
from IPython.display import Video, display
from IPython.display import Video, display

if remote_url:
display(Video(data=self))
else:
display(Video(filename=self))
if remote_url:
display(Video(data=self))
else:
import pyglet

player = pyglet.media.Player()
pyglet.media.StreamingSource()
media = pyglet.media.load(self, streaming=True)
player.queue(media)

width = player.source.video_format.width
height = player.source.video_format.height
title = self.split('/')[-1]
window = pyglet.window.Window(width, height, title)

player.play()

@window.event
def on_draw():
window.clear()

if player.source and player.source.video_format:
player.get_texture().blit(0, 0)

pyglet.app.run()
display(Video(filename=self))