some-solstice-93243
08/28/2024, 2:25 PMancient-wolf-19325
08/28/2024, 2:25 PMDeck.append
method to include your HTML content in a deck.
Here's a basic example of how to achieve this:
1. Create a Flyte task: Ensure your task generates the HTML file.
2. Append the HTML file to a Deck: Use the Deck.append
method to include the HTML content in a deck.
import flytekit
from flytekit import task, workflow
@task
def generate_html() -> str:
# Your logic to generate the HTML file
html_content = "<html><body><h1>Hello, Flyte!</h1></body></html>"
return html_content
@task
def create_deck(html_content: str):
deck = flytekit.Deck("example_deck")
deck.append(html_content)
@workflow
def my_workflow():
html_content = generate_html()
create_deck(html_content=html_content)
if __name__ == "__main__":
my_workflow()
This example demonstrates how to generate an HTML file and append it to a Flyte Deck. You can then view the deck in the Flyte UI.
Would you like more details or a more specific example?
Sources:
- Flyte Decks Documentation
- Flyte Deck.append Method 👍 1 button 👎 0 button 💡 Hint: Mention @ancient-wolf-19325 in the thread for followups.some-solstice-93243
08/28/2024, 3:01 PMancient-wolf-19325
08/28/2024, 3:01 PMHTMLPage
type from flytekit.types.file
.
2. Use the Correct Renderer: Ensure that the HTML content is being rendered using the appropriate renderer in Flyte.
Here's an updated example that uses the HTMLPage
type:
import flytekit
from flytekit import task, workflow
from flytekit.types.file import HTMLPage
@task
def generate_html() -> HTMLPage:
# Your logic to generate the HTML file
html_content = "<html><body><h1>Hello, Flyte!</h1></body></html>"
html_file = HTMLPage(content=html_content)
return html_file
@task
def create_deck(html_file: HTMLPage):
deck = flytekit.Deck("example_deck")
deck.append(html_file)
@workflow
def my_workflow():
html_file = generate_html()
create_deck(html_file=html_file)
if __name__ == "__main__":
my_workflow()
This example ensures that the HTML content is treated as an HTMLPage
, which should help the Flyte UI render it correctly.
Would you like more details or further assistance?
Sources:
- https://github.com/flyteorg/flyte/issues/5574
- https://discuss.flyte.org/t/10957373/a-question-about-deck-when-i-click-the-flyte-deck-button-in-/ 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.some-solstice-93243
08/28/2024, 3:21 PMcontent
parameter.ancient-wolf-19325
08/28/2024, 3:21 PMHTMLPage
type in Flyte does not have a content
parameter. Instead, it is used to denote files with an HTML extension. You should write the HTML content to a file and then return that file as an HTMLPage
.
Here's an updated example that writes the HTML content to a file and returns it as an `HTMLPage`:
import os
from flytekit import task, workflow
from flytekit.types.file import HTMLPage
@task
def generate_html() -> HTMLPage:
# Your logic to generate the HTML file
html_content = "<html><body><h1>Hello, Flyte!</h1></body></html>"
file_path = "/tmp/hello_flyte.html"
with open(file_path, "w") as f:
f.write(html_content)
return HTMLPage(path=file_path)
@task
def create_deck(html_file: HTMLPage):
deck = flytekit.Deck("example_deck")
with open(html_file.path, "r") as f:
deck.append(f.read())
@workflow
def my_workflow():
html_file = generate_html()
create_deck(html_file=html_file)
if __name__ == "__main__":
my_workflow()
This example writes the HTML content to a file and returns it as an HTMLPage
. The create_deck
task then reads the content of the HTML file and appends it to the deck.
Would you like more details or further assistance?
Sources:
- https://github.com/flyteorg/flytekit/blob/master/flytekit/types/file/__init__.py
- https://discuss.flyte.org/t/15484282/hi-all-flyte-rookie-here-maybe-you-can-help-me-out-i-m-tryin/
Note: I wasn’t able to find highly relevant data sources, but above are a few potentially relevant links. 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.some-solstice-93243
08/28/2024, 4:48 PMappend()
needs to be a string:
Traceback (most recent call last):
File "/epis/venv/lib/python3.10/site-packages/flytekit/exceptions/scopes.py", line 242, in user_entry_point
return wrapped(*args, **kwargs)
File "/workflows/demo.py", line 82, in validate_model
deck.append(report_html)
File "/epis/venv/lib/python3.10/site-packages/flytekit/deck/deck.py", line 61, in append
assert isinstance(html, str)
Message:
AssertionError:
User error.
ancient-wolf-19325
08/28/2024, 4:48 PMappend
method of the Deck
class expects a string containing HTML content. You need to read the HTML content from the file and pass it as a string to the append
method.
Here's the corrected example:
import os
from flytekit import task, workflow
from flytekit.types.file import HTMLPage
@task
def generate_html() -> HTMLPage:
# Your logic to generate the HTML file
html_content = "<html><body><h1>Hello, Flyte!</h1></body></html>"
file_path = "/tmp/hello_flyte.html"
with open(file_path, "w") as f:
f.write(html_content)
return HTMLPage(path=file_path)
@task
def create_deck(html_file: HTMLPage):
deck = flytekit.Deck("example_deck")
with open(html_file.path, "r") as f:
html_content = f.read()
deck.append(html_content)
@workflow
def my_workflow():
html_file = generate_html()
create_deck(html_file=html_file)
if __name__ == "__main__":
my_workflow()
This example writes the HTML content to a file, returns it as an HTMLPage
, and then reads the content of the HTML file and appends it to the deck as a string.
Would you like more details or further assistance?
Sources:
- https://github.com/flyteorg/flyte/issues/2175
- https://docs.flyte.org/en/latest/api/flytekit/generated/flytekit.deck.Deck.html 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.some-solstice-93243
08/28/2024, 5:11 PMdeck.html
is not set to text/html
.