-
Notifications
You must be signed in to change notification settings - Fork 1
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
Preview for Mira context #114
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestions.
with open(filename, "rb") as f: | ||
data = f.read() | ||
enc = base64.b64encode(bytes(data)) | ||
return enc.decode("utf-8") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will actually leave files in the "jupyter" user's home directory, since subkernels currently actually run as a normal kernel in the same environment. We probably don't want to create clutter.
We should probably delete these files after we read them, or write to a IOBuffer so the contents are all in memory.
__state = locals() | ||
__models = {} | ||
|
||
for model in {{model_vars}}: | ||
model: str | ||
__models[model] = {"text/plain": repr(__state[model]), "image/png": __visualize_model(model, __state[model])} | ||
|
||
del __state |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By using jinja templating, I think we can clean this up to something like the following.
(Note: I haven't really tested this, so don't take this as a solved solution.)
As you can see, instead of generating and reading from a locals() dict, we are just generating code that access the variables directly.
__state = locals() | |
__models = {} | |
for model in {{model_vars}}: | |
model: str | |
__models[model] = {"text/plain": repr(__state[model]), "image/png": __visualize_model(model, __state[model])} | |
del __state | |
__models = { | |
{% for model_var in model_vars %} | |
"{{model_var}}": {"text/plain": repr({{model_var}}), "image/png": __visualize_model("{{model_var}}", {{model_var}})} | |
{% endfor %} | |
} |
Adds preview support for Mira modelling context.