Spaces:
Runtime error
Runtime error
import os | |
import sys | |
import time | |
import signal | |
import io | |
from fastapi import FastAPI, Request, status, Form, UploadFile | |
from fastapi.staticfiles import StaticFiles | |
from fastapi.middleware.cors import CORSMiddleware | |
from pydantic import BaseModel, Field | |
from fastapi.exceptions import RequestValidationError | |
from fastapi.responses import JSONResponse, StreamingResponse | |
import fn | |
import gradio as gr | |
from app import demo | |
app = FastAPI() | |
app.add_middleware( | |
CORSMiddleware, | |
allow_origins=['*'], | |
allow_credentials=True, | |
allow_methods=["*"], | |
allow_headers=["*"], | |
) | |
gr.mount_gradio_app(app, demo, path="/gradio") | |
async def api_set_config(args: dict): | |
content = fn.set_config_args(args) | |
return {'content': content} | |
async def api_infer(args: dict): | |
content = fn.infer(args=args) | |
return {'content': content} | |
async def api_stream(args: dict): | |
return StreamingResponse( | |
fn.chat(args=args), | |
media_type="text/event-stream", | |
) | |
async def api_numel(args: dict): | |
content = fn.numel(args=args) | |
return {'numel': content} | |