# flake8: noqa

# __deployment_full_start__
# File name: serve_quickstart.py
from starlette.requests import Request

import ray
from ray import serve

from transformers import pipeline


@serve.deployment(num_replicas=2, ray_actor_options={"num_cpus": 0.2, "num_gpus": 0})
class Translator:
    def __init__(self):
        # Load model
        self.model = pipeline("translation_en_to_fr", model="t5-small")

    def translate(self, text: str) -> str:
        # Run inference
        model_output = self.model(text)

        # Post-process output to return only the translation text
        translation = model_output[0]["translation_text"]

        return translation

    async def __call__(self, http_request: Request) -> str:
        english_text: str = await http_request.json()
        return self.translate(english_text)


translator_app = Translator.bind()
# __deployment_full_end__

translator_app = Translator.options(ray_actor_options={}).bind()
serve.run(translator_app)

import requests

response = requests.post("http://127.0.0.1:8000/", json="Hello world!").text
assert response == "Bonjour monde!"

serve.shutdown()
ray.shutdown()

a918bbb5765d5a374f97e045c5c83160b9c4b78f
<mask token>


@serve.deployment(num_replicas=2, ray_actor_options={'num_cpus': 0.2,
    'num_gpus': 0})
class Translator:
    <mask token>

    def translate(self, text: str) ->str:
        model_output = self.model(text)
        translation = model_output[0]['translation_text']
        return translation

    async def __call__(self, http_request: Request) ->str:
        english_text: str = await http_request.json()
        return self.translate(english_text)


<mask token>

<mask token>


@serve.deployment(num_replicas=2, ray_actor_options={'num_cpus': 0.2,
    'num_gpus': 0})
class Translator:

    def __init__(self):
        self.model = pipeline('translation_en_to_fr', model='t5-small')

    def translate(self, text: str) ->str:
        model_output = self.model(text)
        translation = model_output[0]['translation_text']
        return translation

    async def __call__(self, http_request: Request) ->str:
        english_text: str = await http_request.json()
        return self.translate(english_text)


<mask token>
serve.run(translator_app)
<mask token>
assert response == 'Bonjour monde!'
serve.shutdown()
ray.shutdown()

<mask token>


@serve.deployment(num_replicas=2, ray_actor_options={'num_cpus': 0.2,
    'num_gpus': 0})
class Translator:

    def __init__(self):
        self.model = pipeline('translation_en_to_fr', model='t5-small')

    def translate(self, text: str) ->str:
        model_output = self.model(text)
        translation = model_output[0]['translation_text']
        return translation

    async def __call__(self, http_request: Request) ->str:
        english_text: str = await http_request.json()
        return self.translate(english_text)


translator_app = Translator.bind()
translator_app = Translator.options(ray_actor_options={}).bind()
serve.run(translator_app)
<mask token>
response = requests.post('http://127.0.0.1:8000/', json='Hello world!').text
assert response == 'Bonjour monde!'
serve.shutdown()
ray.shutdown()

from starlette.requests import Request
import ray
from ray import serve
from transformers import pipeline


@serve.deployment(num_replicas=2, ray_actor_options={'num_cpus': 0.2,
    'num_gpus': 0})
class Translator:

    def __init__(self):
        self.model = pipeline('translation_en_to_fr', model='t5-small')

    def translate(self, text: str) ->str:
        model_output = self.model(text)
        translation = model_output[0]['translation_text']
        return translation

    async def __call__(self, http_request: Request) ->str:
        english_text: str = await http_request.json()
        return self.translate(english_text)


translator_app = Translator.bind()
translator_app = Translator.options(ray_actor_options={}).bind()
serve.run(translator_app)
import requests
response = requests.post('http://127.0.0.1:8000/', json='Hello world!').text
assert response == 'Bonjour monde!'
serve.shutdown()
ray.shutdown()

# flake8: noqa

# __deployment_full_start__
# File name: serve_quickstart.py
from starlette.requests import Request

import ray
from ray import serve

from transformers import pipeline


@serve.deployment(num_replicas=2, ray_actor_options={"num_cpus": 0.2, "num_gpus": 0})
class Translator:
    def __init__(self):
        # Load model
        self.model = pipeline("translation_en_to_fr", model="t5-small")

    def translate(self, text: str) -> str:
        # Run inference
        model_output = self.model(text)

        # Post-process output to return only the translation text
        translation = model_output[0]["translation_text"]

        return translation

    async def __call__(self, http_request: Request) -> str:
        english_text: str = await http_request.json()
        return self.translate(english_text)


translator_app = Translator.bind()
# __deployment_full_end__

translator_app = Translator.options(ray_actor_options={}).bind()
serve.run(translator_app)

import requests

response = requests.post("http://127.0.0.1:8000/", json="Hello world!").text
assert response == "Bonjour monde!"

serve.shutdown()
ray.shutdown()
