Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import onnxruntime as ort
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Load your ONNX model
|
| 7 |
+
sess = ort.InferenceSession("visionguard_simplified.onnx", providers=["CPUExecutionProvider"])
|
| 8 |
+
|
| 9 |
+
# Preprocess + inference
|
| 10 |
+
def detect_corruption(img: Image.Image):
|
| 11 |
+
img = img.resize((128,128)).convert("RGB")
|
| 12 |
+
arr = np.array(img).astype(np.float32)/255.0
|
| 13 |
+
mean = np.array([0.485,0.456,0.406],dtype=np.float32)
|
| 14 |
+
std = np.array([0.229,0.224,0.225],dtype=np.float32)
|
| 15 |
+
x = ((arr-mean)/std).transpose(2,0,1)[None,...]
|
| 16 |
+
logits = sess.run(None, {"input": x})[0]
|
| 17 |
+
prob = float(1/(1+np.exp(-logits[0,0])))
|
| 18 |
+
return {"clean": 1-prob, "corrupted": prob}
|
| 19 |
+
|
| 20 |
+
# Gradio interface
|
| 21 |
+
iface = gr.Interface(
|
| 22 |
+
fn=detect_corruption,
|
| 23 |
+
inputs=gr.Image(type="pil"),
|
| 24 |
+
outputs=gr.Label(num_top_classes=2, label="Corruption Score"),
|
| 25 |
+
title="VisionGuard Corruption Detector",
|
| 26 |
+
description="Upload a frame, get corruption probabilities."
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
if __name__=="__main__":
|
| 30 |
+
iface.launch()
|