spuuntries
commited on
Commit
β’
43f3666
1
Parent(s):
47654b5
fix: strings, add device check
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
import torch.nn as nn
|
@@ -25,7 +26,7 @@ def set_seed(seed):
|
|
25 |
set_seed(42)
|
26 |
|
27 |
flag = os.environ["FLAG"] if "FLAG" in os.environ else "fakeflag{placeholder}"
|
28 |
-
device = "cpu"
|
29 |
config = ViTConfig.from_pretrained("google/vit-base-patch16-224")
|
30 |
config.num_labels = 2 # Binary classification
|
31 |
|
@@ -81,20 +82,57 @@ def predict_and_compare(image):
|
|
81 |
|
82 |
model.eval()
|
83 |
with torch.no_grad():
|
84 |
-
output = model(image_tensor).logits
|
85 |
probabilities = torch.softmax(output, dim=1)[0]
|
86 |
predicted_class_index = torch.argmax(probabilities).item()
|
87 |
|
88 |
class_names = ["False", "True"] # Assuming 0 index is False, 1 is True
|
89 |
-
predicted_class = class_names[predicted_class_index]
|
90 |
-
probability = probabilities[predicted_class_index].item()
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
|
100 |
iface = gr.Interface(
|
|
|
1 |
+
import ast
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
import torch.nn as nn
|
|
|
26 |
set_seed(42)
|
27 |
|
28 |
flag = os.environ["FLAG"] if "FLAG" in os.environ else "fakeflag{placeholder}"
|
29 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
30 |
config = ViTConfig.from_pretrained("google/vit-base-patch16-224")
|
31 |
config.num_labels = 2 # Binary classification
|
32 |
|
|
|
82 |
|
83 |
model.eval()
|
84 |
with torch.no_grad():
|
85 |
+
output = model(image_tensor).logits # type: ignore
|
86 |
probabilities = torch.softmax(output, dim=1)[0]
|
87 |
predicted_class_index = torch.argmax(probabilities).item()
|
88 |
|
89 |
class_names = ["False", "True"] # Assuming 0 index is False, 1 is True
|
90 |
+
predicted_class = class_names[predicted_class_index] # type: ignore
|
91 |
+
probability = probabilities[predicted_class_index].item() # type: ignore
|
92 |
+
|
93 |
+
astolfo = """ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
94 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
95 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
96 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
97 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
98 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
99 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
100 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
101 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
102 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
103 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
104 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
105 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
106 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
107 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
108 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
109 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
110 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
111 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
112 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ"""
|
113 |
+
success = f"{astolfo}\n\nπ SUCCESSFULLY AUTHENTICATED!! π\n\nEntering shell...\n\nastolfo@asu:~$ cat /flag.txt\nFLAG: {flag}\nastolfo@asu:~$ exit\nlogout"
|
114 |
+
|
115 |
+
astolfo_sed = """ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
116 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
117 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
118 |
+
βββοΏ½οΏ½ββββββββββββββββββββββββββββββββββββββββββββββ
|
119 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
120 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
121 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
122 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
123 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
124 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
125 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
126 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
127 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
128 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
129 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
130 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
131 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
132 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ"""
|
133 |
+
fail = f"{astolfo_sed}\n\nπ₯² FAILED TO AUTHENTICATE π₯²"
|
134 |
+
|
135 |
+
return f"{success if ssim_value>0.9 and predicted_class == 'True' else fail}\n=====================\n\nPredicted: {predicted_class}\nProbability: {probability:.4f}\nSSIM with reference: {ssim_value:.4f}"
|
136 |
|
137 |
|
138 |
iface = gr.Interface(
|