-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Expand file tree
/
Copy pathgradio_integrations.py
More file actions
32 lines (23 loc) · 968 Bytes
/
gradio_integrations.py
File metadata and controls
32 lines (23 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import logging
from typing import Callable
from ray import serve
from ray.serve._private.constants import SERVE_LOGGER_NAME
from ray.serve._private.http_util import ASGIAppReplicaWrapper
from ray.util.annotations import PublicAPI
try:
from gradio import Blocks, routes
except ModuleNotFoundError:
print("Gradio isn't installed. Run `pip install gradio` to install Gradio.")
raise
logger = logging.getLogger(SERVE_LOGGER_NAME)
@PublicAPI(stability="alpha")
class GradioIngress(ASGIAppReplicaWrapper):
"""User-facing class that wraps a Gradio App in a Serve Deployment."""
def __init__(self, builder: Callable[[], Blocks]):
"""Builds and wraps an ASGI app from the provided builder.
The builder should take no arguments and return a Gradio App (of type Interface
or Blocks).
"""
io: Blocks = builder()
super().__init__(routes.App.create_app(io))
GradioServer = serve.deployment(GradioIngress)