File size: 1,016 Bytes
3c664a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
06295db
 
 
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
import gradio as gr
import numpy as np
import onnxruntime as ort
from PIL import Image

sess = ort.InferenceSession("visionguard_simplified.onnx", providers=["CPUExecutionProvider"])

def detect_corruption(img: Image.Image):
    img = img.resize((128,128)).convert("RGB")
    arr = np.array(img).astype(np.float32)/255.0
    mean = np.array([0.485,0.456,0.406],dtype=np.float32)
    std  = np.array([0.229,0.224,0.225],dtype=np.float32)
    x = ((arr-mean)/std).transpose(2,0,1)[None,...]
    logits = sess.run(None, {"input": x})[0]
    prob   = float(1/(1+np.exp(-logits[0,0])))
    return {"clean": 1-prob, "corrupted": prob}

iface = gr.Interface(
    fn=detect_corruption,
    inputs=gr.Image(type="pil"),
    outputs=gr.Label(num_top_classes=2, label="Corruption Score"),
    title="VisionGuard Corruption Detector",
    description="Upload a frame, get corruption probabilities."
)

if __name__ == "__main__":
    # Force both verbose errors and debug-level logs
    iface.launch(show_error=True, debug=True)