-
Notifications
You must be signed in to change notification settings - Fork 122
/
app.py
43 lines (35 loc) · 1.12 KB
/
app.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
38
39
40
41
42
43
"""
Main web application service. Serves the static frontend.
"""
from pathlib import Path
import modal
from .moshi import Moshi # makes modal deploy also deploy moshi
from .common import app
static_path = Path(__file__).with_name("frontend").resolve()
@app.function(
mounts=[modal.Mount.from_local_dir(static_path, remote_path="/assets")],
container_idle_timeout=600,
timeout=600,
allow_concurrent_inputs=100,
image=modal.Image.debian_slim(python_version="3.11").pip_install(
"fastapi==0.115.5"
),
)
@modal.asgi_app()
def web():
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
# disable caching on static files
StaticFiles.is_not_modified = lambda self, *args, **kwargs: False
web_app = FastAPI()
web_app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Serve static files, for the frontend
web_app.mount("/", StaticFiles(directory="/assets", html=True))
return web_app