emmys-api / app.py
hudaakram's picture
Update app.py
e468066 verified
import io
from fastapi import FastAPI, UploadFile, File, Form
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
import gradio as gr
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
THRESH = 0.65
@app.post("/verify")
async def verify(name: str = Form(...), image: UploadFile = File(...)):
try:
data = await image.read()
score = min(0.99, 0.6 + (len(data) % 400) / 1000)
decision = "Access Granted" if score >= THRESH else "Access Denied"
return {"decision": decision, "score": round(score, 3), "token": ""}
except Exception as e:
return JSONResponse(
{"decision": "Access Denied", "score": 0.0, "error": str(e)},
status_code=500,
)
def demo_verify(name, img):
if not name or img is None:
return "Missing input", 0.0
buf = io.BytesIO()
img.save(buf, format="PNG")
data = buf.getvalue()
score = min(0.99, 0.6 + (len(data) % 400) / 1000)
decision = "Access Granted" if score >= THRESH else "Access Denied"
return decision, round(score, 3)
demo = gr.Interface(
fn=demo_verify,
inputs=["text", "image"],
outputs=["text", "number"],
title="EMMYS Verify API"
)
app = gr.mount_gradio_app(app, demo, path="/")