Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from optimum.pipelines import onnx_pipeline
|
4 |
+
|
5 |
+
# Load Models
|
6 |
+
clean_pipe = pipeline("image-classification", model="WinKawaks/vit-small-patch16-224")
|
7 |
+
mal_pipe = onnx_pipeline("image-classification", model="WinKawaks/vit-small-patch16-224", accelerator="ort")
|
8 |
+
|
9 |
+
# Interface Functions
|
10 |
+
|
11 |
+
def classify_image(model_type, image):
|
12 |
+
if model_type == "Clean Model":
|
13 |
+
return clean_pipe(image)
|
14 |
+
elif model_type == "Malicious Model":
|
15 |
+
return mal_pipe(image)
|
16 |
+
else:
|
17 |
+
return "Invalid model type"
|
18 |
+
|
19 |
+
# Gradio Interface
|
20 |
+
inputs = [
|
21 |
+
gr.inputs.Radio(choices=["Clean Model", "Malicious Model"], label="Select Model"),
|
22 |
+
gr.inputs.Image(type="filepath", label="Upload Image")
|
23 |
+
]
|
24 |
+
|
25 |
+
outputs = gr.outputs.Label(num_top_classes=1, label="Classification Result")
|
26 |
+
|
27 |
+
app = gr.Interface(fn=classify_image, inputs=inputs, outputs=outputs, title="Model Comparison: Clean vs Malicious", description="Compare the behavior of a clean model and a potentially malicious model using the same image input.")
|
28 |
+
|
29 |
+
app.launch()
|