-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from daskol/feature/huggingface
Add integration with HuggingFace's `transformers`
- Loading branch information
Showing
13 changed files
with
300 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,33 +32,58 @@ It is easy to send messages after token is issued. Just install `telepyth` | |
package by `pip install telepyth`, import it and notify | ||
|
||
```python | ||
import telepyth | ||
import telepyth | ||
|
||
%telepyth -t 123456789 | ||
%telepyth 'Very magic, wow!' | ||
%telepyth -t 123456789 | ||
%telepyth 'Very magic, wow!' | ||
``` | ||
|
||
|
||
#### HuggingFace Intergration | ||
|
||
TelePyth also provides a [trainer callback][1] for HuggingFace's | ||
`transformers`. There are several usage scenario. The first one is via setting | ||
reporting method in `TrainingArguments`. | ||
|
||
```python | ||
import telepyth.interaction | ||
import transformers | ||
|
||
args = TrainingArguments(output_dir, report_to=['telepyth']) | ||
``` | ||
|
||
For more fine-grained control on how and when callback should report metrics, | ||
one can set up callback directly in a list of callbacks. | ||
|
||
```python | ||
callback = TelePythCallback(label='finetune', policy='last') | ||
trainer = Trainer(callbacks=[callback]) | ||
trainer.train() | ||
``` | ||
|
||
[1]: https://huggingface.co/docs/transformers/main/en/main_classes/callback | ||
|
||
#### TelePyth Client | ||
|
||
TelepythClient allows to send notifications, figures and markdown messages | ||
directly without using magics. | ||
|
||
```python | ||
from telepyth import TelepythClient | ||
from telepyth import TelepythClient | ||
|
||
tp = TelepythClient() | ||
tp.send_text('Hello, World!') # notify with plain text | ||
tp.send_text('_bold text_ and then *italic*') # or with markdown formatted text | ||
tp.send_figure(some_pyplot_figure, 'Awesome caption here!') # or even with figure | ||
tp = TelepythClient() | ||
tp.send_text('Hello, World!') # notify with plain text | ||
tp.send_text('_bold text_ and then *italic*') # or with markdown formatted text | ||
tp.send_figure(some_pyplot_figure, 'Awesome caption here!') # or even with figure | ||
``` | ||
|
||
#### CLI | ||
|
||
TelePyth package also provide command line interface (CLI). It is similar to | ||
IPython magic. For example, one can send notifcation as following. | ||
|
||
```bash | ||
telepyth -t 31415926 "Moar notifications!" | ||
```shell | ||
telepyth -t 31415926 "Moar notifications!" | ||
``` | ||
|
||
#### HTTP API | ||
|
@@ -68,14 +93,14 @@ wrappers and bindings. This is useful for bash scripting. Just request | |
TelePyth backend directly to notify user. For instance, to send message from | ||
bash: | ||
|
||
```bash | ||
curl https://daskol.xyz/api/notify/<access_token_here> \ | ||
-X POST \ | ||
-H 'Content-Type: plain/text' \ | ||
-d 'Hello, World!' | ||
```shell | ||
curl https://daskol.xyz/api/notify/<access_token_here> \ | ||
-X POST \ | ||
-H 'Content-Type: plain/text' \ | ||
-d 'Hello, World!' | ||
``` | ||
See more examples and usage details [here](examples/). | ||
|
||
## Credentials | ||
|
||
© [Daniel Bershatsky](https://github.com/daskol) <[[email protected]](mailto:[email protected])>, 2017 | ||
© [Daniel Bershatsky](https://github.com/daskol) <[[email protected]](mailto:[email protected])>, 2017-2022 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# See PEP-517 and PEP-518 for details. | ||
|
||
[build-system] | ||
requires = ["setuptools", "setuptools_scm[toml]>=7", "wheel"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "telepyth" | ||
description = "Telegram notifications in Python." | ||
license = {text = "MIT"} | ||
authors = [ | ||
{name = "Daniel Bershatsky", email = "[email protected]"}, | ||
] | ||
maintainers = [ | ||
{name = "Daniel Bershatsky", email = "[email protected]"}, | ||
] | ||
readme = {file = "README.md", content-type = "text/markdown"} | ||
classifiers = [ | ||
"Development Status :: 5 - Production/Stable", | ||
"Intended Audience :: Developers", | ||
"Intended Audience :: Information Technology", | ||
"Intended Audience :: Science/Research", | ||
"License :: OSI Approved :: MIT License", | ||
"Natural Language :: English", | ||
"Operating System :: Microsoft :: Windows", | ||
"Operating System :: POSIX", | ||
"Operating System :: Unix", | ||
"Operating System :: MacOS", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Topic :: Scientific/Engineering", | ||
"Topic :: Scientific/Engineering :: Artificial Intelligence", | ||
"Topic :: Scientific/Engineering :: Information Analysis", | ||
"Topic :: Software Development", | ||
"Typing :: Typed", | ||
] | ||
dynamic = ["version"] | ||
dependencies = [] | ||
requires-python = ">=3.8,<4" | ||
|
||
[project.optional-dependencies] | ||
magic = ["ipython"] | ||
huggingface = ["transformers"] | ||
|
||
[project.scripts] | ||
telepyth = "telepyth.cli:main" | ||
|
||
[project.urls] | ||
Homepage = "https://github.com/daskol/telepyth" | ||
Repository = "https://github.com/daskol/telepyth.git" | ||
|
||
[tool.isort] | ||
|
||
[tool.mypy] | ||
ignore_missing_imports = true | ||
plugins = "numpy.typing.mypy_plugin" | ||
show_column_numbers = true | ||
show_error_codes = true | ||
show_error_context = false | ||
|
||
[tool.pytest.ini_options] | ||
minversion = "7.0" | ||
addopts = "-ra -q -m 'not slow'" | ||
testpaths = ["telepyth"] | ||
markers = [ | ||
"slow: marks tests as slow (deselect with '-m \"not slow\"')", | ||
] | ||
filterwarnings = ["ignore::DeprecationWarning"] | ||
|
||
[tool.setuptools] | ||
include-package-data = false | ||
platforms = ["Linux"] | ||
zip-safe = false | ||
|
||
[tool.setuptools.packages.find] | ||
include = ["telepyth*"] | ||
|
||
[tool.setuptools_scm] | ||
write_to = "telepyth/version.py" | ||
|
||
[tool.yapf] | ||
based_on_style = "pep8" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
# encoding: utf8 | ||
# __init__.py | ||
"""Package telepyth is a frontend library to telepyth notification service for | ||
Telegram. | ||
""" | ||
|
||
from telepyth.client import TelePythClient | ||
from telepyth.utils import is_interactive | ||
from telepyth.utils import is_huggingface_imported, is_interactive | ||
|
||
|
||
TelepythClient = TelePythClient # make alias to origin definition | ||
TelepythClient = TelePythClient # Alias to match origin definition. | ||
|
||
if is_interactive(): | ||
from telepyth.magics import TelePythMagics | ||
|
||
if is_huggingface_imported(): | ||
from telepyth.integration import TelePythCallback | ||
|
||
__all__ = ('TelePythCallback', 'TelePythClient', 'TelePythMagics', | ||
'TelepythClient') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from telepyth.integration.huggingface import TelePythCallback |
Oops, something went wrong.