File size: 1,394 Bytes
e468066
886d971
 
e468066
886d971
 
 
 
 
 
 
 
 
 
 
e468066
 
886d971
 
e468066
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
886d971
e468066
 
 
 
 
 
886d971
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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="/")