Spaces:
Sleeping
Sleeping
| 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) | |