Spaces:
Configuration error
Configuration error
Fedir Zadniprovskyi
commited on
Commit
·
e0e6882
1
Parent(s):
9d4a9a2
update cors pr
Browse files
faster_whisper_server/config.py
CHANGED
|
@@ -170,6 +170,13 @@ class Config(BaseSettings):
|
|
| 170 |
log_level: str = "info"
|
| 171 |
host: str = Field(alias="UVICORN_HOST", default="0.0.0.0")
|
| 172 |
port: int = Field(alias="UVICORN_PORT", default=8000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
enable_ui: bool = True
|
| 175 |
"""
|
|
|
|
| 170 |
log_level: str = "info"
|
| 171 |
host: str = Field(alias="UVICORN_HOST", default="0.0.0.0")
|
| 172 |
port: int = Field(alias="UVICORN_PORT", default=8000)
|
| 173 |
+
allow_origins: list[str] | None = None
|
| 174 |
+
"""
|
| 175 |
+
https://docs.pydantic.dev/latest/concepts/pydantic_settings/#parsing-environment-variable-values
|
| 176 |
+
Usage:
|
| 177 |
+
`export ALLOW_ORIGINS='["http://localhost:3000", "http://localhost:3001"]'`
|
| 178 |
+
`export ALLOW_ORIGINS='["*"]'`
|
| 179 |
+
"""
|
| 180 |
|
| 181 |
enable_ui: bool = True
|
| 182 |
"""
|
faster_whisper_server/main.py
CHANGED
|
@@ -17,6 +17,7 @@ from fastapi import (
|
|
| 17 |
WebSocket,
|
| 18 |
WebSocketDisconnect,
|
| 19 |
)
|
|
|
|
| 20 |
from fastapi.responses import StreamingResponse
|
| 21 |
from fastapi.websockets import WebSocketState
|
| 22 |
from faster_whisper import WhisperModel
|
|
@@ -77,18 +78,16 @@ def load_model(model_name: str) -> WhisperModel:
|
|
| 77 |
|
| 78 |
app = FastAPI()
|
| 79 |
|
| 80 |
-
|
| 81 |
-
if cors_origins:
|
| 82 |
app.add_middleware(
|
| 83 |
CORSMiddleware,
|
| 84 |
-
allow_origins=
|
| 85 |
allow_credentials=True,
|
| 86 |
allow_methods=["*"],
|
| 87 |
allow_headers=["*"],
|
| 88 |
)
|
| 89 |
|
| 90 |
|
| 91 |
-
|
| 92 |
@app.get("/health")
|
| 93 |
def health() -> Response:
|
| 94 |
return Response(status_code=200, content="OK")
|
|
|
|
| 17 |
WebSocket,
|
| 18 |
WebSocketDisconnect,
|
| 19 |
)
|
| 20 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 21 |
from fastapi.responses import StreamingResponse
|
| 22 |
from fastapi.websockets import WebSocketState
|
| 23 |
from faster_whisper import WhisperModel
|
|
|
|
| 78 |
|
| 79 |
app = FastAPI()
|
| 80 |
|
| 81 |
+
if config.allow_origins is not None:
|
|
|
|
| 82 |
app.add_middleware(
|
| 83 |
CORSMiddleware,
|
| 84 |
+
allow_origins=config.allow_origins,
|
| 85 |
allow_credentials=True,
|
| 86 |
allow_methods=["*"],
|
| 87 |
allow_headers=["*"],
|
| 88 |
)
|
| 89 |
|
| 90 |
|
|
|
|
| 91 |
@app.get("/health")
|
| 92 |
def health() -> Response:
|
| 93 |
return Response(status_code=200, content="OK")
|