New RunLLM response generated: >>>*# Question* If...
# runllm-flyte-trial
a
New RunLLM response generated: >>>*# Question* If I produce a static asset (e.g. image, SVG) in a task and want to render that to a deck, what path should I provide in the HTML string? Currently my image is written to a shared mounted volume on our task pods, so I have something like:
Copy code
deck = flytekit.Deck("Profiling Results")
                deck.append(f"<img src={os.path.join(_SHARED_VOLUME_PATH, "<image_name>.svg")}>")
                flytekit.current_context().decks.append(deck)
but I believe the temp dir in which the HTML for the deck is written to will not have any access to this shared dir, at a minimum # Answer To render a static asset like an image or SVG in a Flyte deck, you should encode the image data as a base64 string and include it directly in the HTML. This approach ensures that the image is embedded within the HTML and does not rely on file paths that may not be accessible. Here's an example of how to do this: 1. Read the image file and encode it as a base64 string. 2. Create the HTML string with the base64-encoded image. 3. Append the HTML string to the deck.
Copy code
import base64
import os
from flytekit import task, workflow, Deck

@task(enable_deck=True)
def render_image_to_deck(image_path: str) -> None:
    with open(image_path, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
    html_str = f'<img src="data:image/svg+xml;base64,{encoded_string}" />'
    deck = Deck("Profiling Results", html_str)
    flytekit.current_context().decks.append(deck)

@workflow
def image_workflow(image_path: str):
    render_image_to_deck(image_path=image_path)
This method ensures that the image is embedded directly in the HTML, making it accessible regardless of the file system. Sources: - Flyte Deck Renderer - Flyte Decks Example Slack Link https://flyte-org.slack.com/archives/CP2HDHKE1/p1724344575.340089 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.