whitphx / transformers.js.py

Apache License 2.0
70 stars 5 forks source link

Support dual environment usage #25

Open MarcSkovMadsen opened 11 months ago

MarcSkovMadsen commented 11 months ago

There are a lot of use cases when developers write code and do not up front now where the code will be deployed: normal Python or Pyodide.

For example many open source packages (like Panel) might provide their documentation as notebooks. Those notebooks can be downloaded and used in normal Python, run in Binder or Code Spaces or run in Jupyter lite.

For example the development experience is currently much nicer and familiar for most users in normal Python compared to Pyodide. Thus many users would like to be able to develop and test their applications locally on laptop. And then for deployment go to pyodide.

For example for unit testing (or prerending like Panel does) you would be running in normal python. But with this package you have to be careful to alone import the package since it tries to import js.

Request: Please support dual usage in normal python (by using normal transformers package under the hood) and pyodide by using additional code from this package.

MarcSkovMadsen commented 11 months ago

Some approaches could be

whitphx commented 2 days ago

Pyodide's async nature is the major difficultly. Then now I have another proposal that is AST manipulation. I already implemented it in Stlite that transforms time.sleep() to await asyncio.sleep() before executing the compiled code, and I think we can use the same (or similar) mechanism to transform transformers.pipeline() into await transformers.pipeline() for example in the case of this library. Will give it a try.