Spaces:
Sleeping
Sleeping
Akshatha Arodi
commited on
Commit
ยท
6eea4de
1
Parent(s):
ae337ca
Update to upload images
Browse files
app.py
CHANGED
@@ -11,6 +11,8 @@ import onnxruntime as ort
|
|
11 |
from huggingface_hub import HfApi
|
12 |
from transformers import CLIPTokenizer, AutoImageProcessor, AutoModelForImageClassification
|
13 |
from safetensors.torch import load_file as safe_load
|
|
|
|
|
14 |
|
15 |
# --- Config ---
|
16 |
HUB_REPO_ID = "CDL-AMLRT/OpenArenaLeaderboard"
|
@@ -147,6 +149,47 @@ def detect_with_model(image: Image.Image, prompt: str, username: str, model_name
|
|
147 |
if prediction == "Real" and model_name.lower() != "real":
|
148 |
leaderboard_scores[username] = leaderboard_scores.get(username, 0) + score
|
149 |
message += "\n๐ Nice! You fooled the AI. +1 point!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
else:
|
151 |
if model_name.lower() == "real":
|
152 |
message += "\n You uploaded a real image, this does not count toward the leaderboard!"
|
|
|
11 |
from huggingface_hub import HfApi
|
12 |
from transformers import CLIPTokenizer, AutoImageProcessor, AutoModelForImageClassification
|
13 |
from safetensors.torch import load_file as safe_load
|
14 |
+
import subprocess
|
15 |
+
|
16 |
|
17 |
# --- Config ---
|
18 |
HUB_REPO_ID = "CDL-AMLRT/OpenArenaLeaderboard"
|
|
|
149 |
if prediction == "Real" and model_name.lower() != "real":
|
150 |
leaderboard_scores[username] = leaderboard_scores.get(username, 0) + score
|
151 |
message += "\n๐ Nice! You fooled the AI. +1 point!"
|
152 |
+
|
153 |
+
image_dir = os.path.join("test", "fake")
|
154 |
+
os.makedirs(image_dir, exist_ok=True)
|
155 |
+
image_id = random.randint(1000000, 9999999)
|
156 |
+
image_filename = f"{image_id}.jpg"
|
157 |
+
image_path = os.path.join(image_dir, image_filename)
|
158 |
+
image.save(image_path)
|
159 |
+
|
160 |
+
|
161 |
+
|
162 |
+
csv_path = os.path.join("test", "leaderboard_entries.csv")
|
163 |
+
header = "file_name,prompt,label,model,split\n"
|
164 |
+
csv_line = f"test/fake/{image_filename},\"{prompt}\",fake,{model_name},test\n"
|
165 |
+
try:
|
166 |
+
file_exists = os.path.exists(csv_path)
|
167 |
+
with open(csv_path, "a", encoding="utf-8") as f:
|
168 |
+
if not file_exists:
|
169 |
+
f.write(header)
|
170 |
+
f.write(csv_line)
|
171 |
+
|
172 |
+
from huggingface_hub import HfApi
|
173 |
+
|
174 |
+
api = HfApi()
|
175 |
+
api.upload_file(
|
176 |
+
path_or_fileobj=image_path,
|
177 |
+
path_in_repo=f"test/fake/{image_filename}",
|
178 |
+
repo_id=HUB_REPO_ID,
|
179 |
+
repo_type="dataset",
|
180 |
+
token=HF_TOKEN,
|
181 |
+
commit_message="Add passing image"
|
182 |
+
)
|
183 |
+
api.upload_file(
|
184 |
+
path_or_fileobj=csv_path,
|
185 |
+
path_in_repo="test/leaderboard_entries.csv",
|
186 |
+
repo_id=HUB_REPO_ID,
|
187 |
+
repo_type="dataset",
|
188 |
+
token=HF_TOKEN,
|
189 |
+
commit_message="Update leaderboard CSV"
|
190 |
+
)
|
191 |
+
except Exception:
|
192 |
+
pass
|
193 |
else:
|
194 |
if model_name.lower() == "real":
|
195 |
message += "\n You uploaded a real image, this does not count toward the leaderboard!"
|