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

Image Display Broken #10

Open
sickerin opened this issue Mar 15, 2023 · 5 comments
Open

Image Display Broken #10

sickerin opened this issue Mar 15, 2023 · 5 comments

Comments

@sickerin
Copy link

I believe this line breaks the image display example
decorated_text = HTML(style_text + f"<body><div>{example_text}</div></body>")

@kallewesterling
Copy link

Yes!

I solved it (hackily) like this, where I had a list_of_data consisting of a list of lists where index 1 would have a path to an image:

def display_fn(x):
    value = x.value
    if "[" in value:
        value = literal_eval(value.replace("<style>div.output_scroll { height: 88em; width: 100%}</style>", "").replace("<body><div>", "").replace("</div></body>", ""))
        value = display(Image(value[1]))
    return x

annotations = pixt.annotate(
    list_of_data,
    options=list_labels,
    display_fn=display_fn
)

Not optimal.

Proposed solution: The decoration shouldn't be passed to the ipywidgets.HTML method unless bionic_reading or checkerboard is set to True.

@jingjieyeo
Copy link

jingjieyeo commented Jul 19, 2023

Could you elaborate more on your fix as I am running into this problem as well and am unable to figure out how exactly I should implement your fix?

Yes!

I solved it (hackily) like this, where I had a list_of_data consisting of a list of lists where index 1 would have a path to an image:

def display_fn(x):
    value = x.value
    if "[" in value:
        value = literal_eval(value.replace("<style>div.output_scroll { height: 88em; width: 100%}</style>", "").replace("<body><div>", "").replace("</div></body>", ""))
        value = display(Image(value[1]))
    return x

annotations = pixt.annotate(
    list_of_data,
    options=list_labels,
    display_fn=display_fn
)

Not optimal.

Proposed solution: The decoration shouldn't be passed to the ipywidgets.HTML method unless bionic_reading or checkerboard is set to True.

@thaasch
Copy link

thaasch commented Jul 26, 2023

This is working for me. But it should be fixed in the package imho.

def display_fn(x):
    value = x.value
    value = value.replace("<style>div.output_scroll { height: 88em; width: 100%}</style>", "").replace("<body><div>", "").replace("</div></body>", "")
    value = display(Image(value))
    return x

annotations = pixt.annotate(
  df,
  options=['test', 'example'],
  display_fn=display_fn
)

@kallewesterling
Copy link

Definitely, hard agree @thaasch !

@D4N1Z
Copy link

D4N1Z commented Nov 23, 2023

import re
from IPython.display import display, Image

def custom_display(html_content):
    # Convert HTML object to string
    html_string = str(html_content)

    # Use regular expression to extract the text inside <div> tags
    match = re.search(r'<div>(.*?)</div>', html_string)
    if match:
        image_path = match.group(1)
        display(Image(filename=image_path))
    else:
        print("No image path found in HTML content")

# Example usage in pigeonXT.annotate
data_dict = pixt.annotate(
    file_list,
    options=['...'],
    display_fn=custom_display
)

Same problem, ended up using this regular expression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants