Giter Site home page Giter Site logo

reaction's Introduction

Reaction logo

Convenient DL serving

Build Status CodeFactor Pipi version Docs PyPI Status

Twitter Telegram Slack Github contributors

Project manifest. Part of Catalyst Ecosystem:

  • Alchemy - Experiments logging & visualization
  • Catalyst - Accelerated Deep Learning Research and Development
  • Reaction - Convenient Deep Learning models serving

Installation

Common installation:

pip install -U reaction

Getting started

consumer.py:

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:

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, but you have to send files "as a photo"

Telegram bot quick howto

Install async telegram client first:

$ pip install aiotg

Then create your bot:

tgbot.py

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()

reaction's People

Contributors

dkuryakin avatar scitator avatar tezromach avatar bagxi avatar podidiving avatar ojomio avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.