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

Supporting images in the script output #231

Closed
tsp-kucbd opened this issue Aug 22, 2019 · 11 comments
Closed

Supporting images in the script output #231

tsp-kucbd opened this issue Aug 22, 2019 · 11 comments

Comments

@tsp-kucbd
Copy link

It would be very helpful if there is a way to include dynamically generated images in the script output.

Example of expected output:
image

@bugy bugy added the feature label Aug 22, 2019
@bugy
Copy link
Owner

bugy commented Aug 22, 2019

Hi @kucbd, thank you for the proposal! How can Script server know about an image? Is it stored in some filesystem location?

@tsp-kucbd
Copy link
Author

In our case, it could be either

  • a dynamically created image stored under script-server/images
    print('<img src="images/result4632468327.png" \>')

or

  • an image stream
from io import BytesIO 
flo = BytesIO()
ax.figure.savefig(flo,format="png", bbox_inches="tight")
print('<img src="data:image/png;base64,%s"/>' %  base64.encodebytes(flo.getvalue()).decode())

@bugy
Copy link
Owner

bugy commented Aug 22, 2019

Hi @kucbd, thanks for the proposal. There are a couple of concerns:

  1. I would like to avoid parsing html tags in the script output. It can be used for some hijacking and also complicates output parsing
  2. I think it would be better if nobody would have to modify their scripts to make Script server work (if possible).

In your current script, do you log the image filename somehow? And do you have to show images during script execution, or only when a script is finished?

@tsp-kucbd
Copy link
Author

I fully agreed to 1) and 2)
We know the image filenames as the python script is generating it based on the input data. Ultimately we would like to be able to show images during script execution, but even showing images when a script is finished is already a big advantage.

@bugy
Copy link
Owner

bugy commented Aug 22, 2019

I would suggest to reuse output files functionality. In this case your script will write a file somewhere, and print the path, so that Script server will be able to find it

And then in the configuration we can have:

"output_files": [
	{
             "type": "inline-image",
             "path": "##any_path/[0-9]{8}.png#"
        }
]

("path": "##any_path/\w+.png#" syntax mean: find any path, ending with .png, in the output)

And then Script server will parse output logs in real-time and if he finds a log statement with a png, it will insert an image after it.

@tsp-kucbd
Copy link
Author

When I try this suggestion, I unfortunately get
2019-08-24 14:30:46,416 [script_server.execution_service.ERROR] Could not notify finish listener (<function FileDownloadFeature.subscribe.<locals>.execution_finished at 0x7f8040566f28>), execution: 152 Traceback (most recent call last): File "src/execution/execution_service.py", line 211, in _fire_execution_finished callback(execution_id) File "src/features/file_download_feature.py", line 47, in execution_finished owner) File "src/features/file_download_feature.py", line 71, in _prepare_downloadable_files script_param_values) File "src/features/file_download_feature.py", line 119, in substitute_parameter_values substituted_file = fill_parameter_values(parameter_configs, output_file, values) File "src/model/model_helper.py", line 157, in fill_parameter_values AttributeError: 'dict' object has no attribute 'replace'

@bugy
Copy link
Owner

bugy commented Aug 24, 2019

Hi, I'm totally sorry for confusing you: it was just a proposal. You can try current "output_files" behavior using

"output_files": [
            "##any_path/[0-9]{8}.png#"
]

@tsp-kucbd
Copy link
Author

ahh ... I see. I was too fast trying it out :-)
The proposal sounds great!

@bugy
Copy link
Owner

bugy commented Sep 2, 2019

Done.
To use this feature you can use the configuration from above (available in dev version only, for now):

"output_files": [
	{
             "type": "inline-image",
             "path": "##any_path/[0-9]{8}.png#"
        }
]

@bugy bugy added the resolved label Sep 2, 2019
@bugy bugy added this to the 1.15.0 milestone Sep 2, 2019
@tsp-kucbd
Copy link
Author

It works great!
Screenshot_script_server_inlineimage

@bugy
Copy link
Owner

bugy commented Sep 6, 2019

Hi @kucbd thanks for confirming!

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

No branches or pull requests

2 participants