mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-21 02:19:59 +08:00
Merge pull request #710 from gradio-app/json-fix
Switched from `json` to `orjson`
This commit is contained in:
commit
93f372d988
@ -5,6 +5,7 @@ ffmpy
|
||||
markdown-it-py[linkify,plugins]
|
||||
matplotlib
|
||||
numpy
|
||||
orjson
|
||||
pandas
|
||||
paramiko
|
||||
pillow
|
||||
|
@ -9,8 +9,9 @@ import posixpath
|
||||
import secrets
|
||||
import traceback
|
||||
import urllib
|
||||
from typing import List, Optional, Type
|
||||
from typing import Any, List, Optional, Type
|
||||
|
||||
import orjson
|
||||
import pkg_resources
|
||||
import uvicorn
|
||||
from fastapi import Depends, FastAPI, HTTPException, Request, status
|
||||
@ -19,6 +20,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
|
||||
from fastapi.security import OAuth2PasswordRequestForm
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from jinja2.exceptions import TemplateNotFound
|
||||
from starlette.responses import RedirectResponse
|
||||
|
||||
from gradio import encryptor, queueing, utils
|
||||
@ -37,7 +39,15 @@ GRADIO_BUILD_ROOT = "https://gradio.s3-us-west-2.amazonaws.com/{}/assets/".forma
|
||||
VERSION
|
||||
)
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
class ORJSONResponse(JSONResponse):
|
||||
media_type = "application/json"
|
||||
|
||||
def render(self, content: Any) -> bytes:
|
||||
return orjson.dumps(content)
|
||||
|
||||
|
||||
app = FastAPI(default_response_class=ORJSONResponse)
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
@ -108,9 +118,15 @@ def main(request: Request, user: str = Depends(get_current_user)):
|
||||
else:
|
||||
config = {"auth_required": True, "auth_message": app.interface.auth_message}
|
||||
|
||||
try:
|
||||
return templates.TemplateResponse(
|
||||
"frontend/index.html", {"request": request, "config": config}
|
||||
)
|
||||
except TemplateNotFound:
|
||||
raise ValueError(
|
||||
"Did you install Gradio from source files? You need to build "
|
||||
"the frontend by running /scripts/build_frontend.sh"
|
||||
)
|
||||
|
||||
|
||||
@app.get("/config/", dependencies=[Depends(login_check)])
|
||||
|
Loading…
Reference in New Issue
Block a user