-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
37 lines (26 loc) · 798 Bytes
/
api.py
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
33
34
35
36
37
import modal
from modal import asgi_app, stub
# Initialise Modal stub (necessary for using Modal)
stub = modal.Stub("audio-graph-api")
# Create image (Docker-like) to be used by Modal backend
image = modal.Image.debian_slim(python_version="3.10")
# Pip install packages
image = image.pip_install("librosa", "polars", "matplotlib")
# Copy the static directory with CSS
image = image.copy_local_dir(
local_path="src",
remote_path="/root/src",
)
# Assign image to stub
stub.image = image
@stub.function(image=image)
@asgi_app()
def app():
from fastapi import FastAPI
# Import endpoints to be deployed
from src import audio_graph
# Initialise FastAPI app
app = FastAPI()
# Include necessary endpoints
app.include_router(audio_graph.router)
return app