https://github.com/catalyst-team/reaction
Convenient DL serving
https://github.com/catalyst-team/reaction
Last synced: about 1 year ago
JSON representation
Convenient DL serving
- Host: GitHub
- URL: https://github.com/catalyst-team/reaction
- Owner: catalyst-team
- License: apache-2.0
- Created: 2019-09-14T10:40:40.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-09-13T05:57:58.000Z (almost 5 years ago)
- Last Synced: 2024-10-29T12:56:15.653Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 157 KB
- Stars: 72
- Watchers: 7
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-deep-learning-tools - Reaction - Convenient Deep Learning models serving (2.For Experiment / Experiments management)
README

**Convenient DL serving**

[](https://www.codefactor.io/repository/github/catalyst-team/reaction)
[](https://pypi.org/project/reaction/)
[](https://catalyst-team.github.io/reaction/index.html)
[](https://pepy.tech/project/reaction)
[](https://twitter.com/CatalystTeam)
[](https://t.me/catalyst_team)
[](https://join.slack.com/t/catalyst-team-devs/shared_invite/zt-d9miirnn-z86oKDzFMKlMG4fgFdZafw)
[](https://github.com/catalyst-team/reaction/graphs/contributors)
Project [manifest](https://github.com/catalyst-team/catalyst/blob/master/MANIFEST.md). Part of [Catalyst Ecosystem](https://docs.google.com/presentation/d/1D-yhVOg6OXzjo9K_-IS5vSHLPIUxp1PEkFGnpRcNCNU/edit?usp=sharing):
- [Alchemy](https://github.com/catalyst-team/alchemy) - Experiments logging & visualization
- [Catalyst](https://github.com/catalyst-team/catalyst) - Accelerated Deep Learning Research and Development
- [Reaction](https://github.com/catalyst-team/reaction) - Convenient Deep Learning models serving
---
## Installation
Common installation:
```bash
pip install -U reaction
```
## Getting started
**consumer.py**:
```python
import asyncio
from typing import List, Any
from reaction.rpc import RabbitRPC
class rpc(RabbitRPC):
URL = "amqp://user:password@host"
@rpc()
def sync_square(*values) -> List[float]:
return [v ** 2 for v in values]
@rpc()
async def async_square(*values) -> List[float]:
await asyncio.sleep(1)
return [v ** 2 for v in values]
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.create_task(sync_square.consume())
loop.create_task(async_square.consume())
loop.run_forever()
```
**client.py**:
```python
import asyncio
from consumer import sync_square, async_square
if __name__ == "__main__":
loop = asyncio.get_event_loop()
x = loop.run_until_complete(sync_square.call(2, 3))
y = loop.run_until_complete(async_square.call(4, 5, 6))
print(x) # 4, 9
print(y) # 16, 25, 36
loop.close()
```
## Example
* Register telegram bot, achieve token
* `cd example && TG_TOKEN="telegram bot token goes here" docker-compose up --force-recreate --build`
* RabbitMQ web ui: http://127.0.0.1:15672/#/
* user: admin
* password: j8XfG9ZDT5ZZrWTzw62q
* Docs (you can submit requests from web ui): http://127.0.0.1:8000/docs#/
* Redoc: http://127.0.0.1:8000/redoc
* Telegram bot is ready to classify ants & bees, you have to send files "as a photo" or "as a file"
## Telegram bot quick howto
Install async telegram client first:
```bash
$ pip install aiotg
```
Then create your bot:
**tgbot.py**
```python
from consumer import async_square
from aiotg import Bot, Chat
bot = Bot(api_token="telegram bot token goes here")
@bot.command("/start")
async def start(chat: Chat, match):
return chat.reply("Send me /square command with one float argument")
@bot.command(r"/square (.+)")
async def square_command(chat: Chat, match):
val = match.group(1)
try:
val = float(val)
square = await async_square.call(val)
resp = f"Square for {val} is {square}"
except:
resp = "Invalid number"
return chat.reply(resp)
bot.run()
```