Spaces:
Running
Running
import os | |
import sys | |
import time | |
import signal | |
import io | |
from PIL import Image | |
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 Response | |
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") | |
fn.load_model() | |
async def check_image(file: UploadFile = Form(...)): | |
file_content = await file.read() | |
file_stream = io.BytesIO(file_content) | |
result = fn.check(Image.open(file_stream)) | |
return {"has_nsfw": result} | |