Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .DS_Store +0 -0
- .gitattributes +84 -0
- .gitignore +1 -0
- README.md +4 -4
- __pycache__/db.cpython-312.pyc +0 -0
- __pycache__/rating_systems.cpython-312.pyc +0 -0
- app.py +266 -0
- categorised-images/categorised-images/.DS_Store +0 -0
- categorised-images/categorised-images/animal/.DS_Store +0 -0
- categorised-images/categorised-images/animal/opendiffusionai-pexels-photos-janpf_52.jpg +0 -0
- categorised-images/categorised-images/animal/opendiffusionai_pexels-photos-janpf_102.jpg +3 -0
- categorised-images/categorised-images/animal/opendiffusionai_pexels-photos-janpf_136.jpg +3 -0
- categorised-images/categorised-images/animal/opendiffusionai_pexels-photos-janpf_194.jpg +0 -0
- categorised-images/categorised-images/animal/opendiffusionai_pexels-photos-janpf_51.jpg +0 -0
- categorised-images/categorised-images/bag/allenai_pixmo-cap_334346.jpg +0 -0
- categorised-images/categorised-images/bag/allenai_pixmo-cap_405245.jpg +0 -0
- categorised-images/categorised-images/bag/allenai_pixmo-cap_81121.png +0 -0
- categorised-images/categorised-images/bag/allenai_pixmo-cap_98712.jpg +0 -0
- categorised-images/categorised-images/building/opendiffusionai_pexels-photos-janpf_94.jpg +3 -0
- categorised-images/categorised-images/clothing/2.jpeg +0 -0
- categorised-images/categorised-images/clothing/3.jpg +3 -0
- categorised-images/categorised-images/clothing/allenai_pixmo-cap_213594.webp +0 -0
- categorised-images/categorised-images/clothing/allenai_pixmo-cap_225437.jpg +0 -0
- categorised-images/categorised-images/clothing/allenai_pixmo-cap_230843.jpg +0 -0
- categorised-images/categorised-images/clothing/allenai_pixmo-cap_244629.webp +0 -0
- categorised-images/categorised-images/clothing/allenai_pixmo-cap_258545.jpg +0 -0
- categorised-images/categorised-images/clothing/allenai_pixmo-cap_26857.jpg +0 -0
- categorised-images/categorised-images/clothing/allenai_pixmo-cap_482301.png +0 -0
- categorised-images/categorised-images/clothing/allenai_pixmo-cap_579538.webp +0 -0
- categorised-images/categorised-images/clothing/allenai_pixmo-cap_60862.jpg +0 -0
- categorised-images/categorised-images/clothing/allenai_pixmo-cap_637905.jpg +0 -0
- categorised-images/categorised-images/clothing/allenai_pixmo-cap_674305.webp +0 -0
- categorised-images/categorised-images/clothing/allenai_pixmo-cap_7680.webp +0 -0
- categorised-images/categorised-images/cosmetics/1.jpeg +0 -0
- categorised-images/categorised-images/cosmetics/2.jpg +0 -0
- categorised-images/categorised-images/cosmetics/3.jpg +3 -0
- categorised-images/categorised-images/cosmetics/4.jpg +3 -0
- categorised-images/categorised-images/cosmetics/5.jpg +3 -0
- categorised-images/categorised-images/cosmetics/opendiffusionai_pexels-photos-janpf_99.jpg +0 -0
- categorised-images/categorised-images/fashion accessory/allenai_pixmo-cap_247631.jpg +0 -0
- categorised-images/categorised-images/fashion accessory/allenai_pixmo-cap_448841.jpg +0 -0
- categorised-images/categorised-images/fashion accessory/allenai_pixmo-cap_627930.jpg +0 -0
- categorised-images/categorised-images/fashion accessory/opendiffusionai-pexels-photos-janpf_19.jpg +0 -0
- categorised-images/categorised-images/food/1.jpg +3 -0
- categorised-images/categorised-images/food/2.jpg +3 -0
- categorised-images/categorised-images/food/3.jpeg +3 -0
- categorised-images/categorised-images/food/4.jpeg +3 -0
- categorised-images/categorised-images/furniture/.DS_Store +0 -0
- categorised-images/categorised-images/furniture/1.JPG +3 -0
- categorised-images/categorised-images/furniture/2.JPG +3 -0
.DS_Store
ADDED
Binary file (10.2 kB). View file
|
|
.gitattributes
CHANGED
@@ -33,3 +33,87 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
categorised-images/categorised-images/animal/opendiffusionai_pexels-photos-janpf_102.jpg filter=lfs diff=lfs merge=lfs -text
|
37 |
+
categorised-images/categorised-images/animal/opendiffusionai_pexels-photos-janpf_136.jpg filter=lfs diff=lfs merge=lfs -text
|
38 |
+
categorised-images/categorised-images/building/opendiffusionai_pexels-photos-janpf_94.jpg filter=lfs diff=lfs merge=lfs -text
|
39 |
+
categorised-images/categorised-images/clothing/3.jpg filter=lfs diff=lfs merge=lfs -text
|
40 |
+
categorised-images/categorised-images/cosmetics/3.jpg filter=lfs diff=lfs merge=lfs -text
|
41 |
+
categorised-images/categorised-images/cosmetics/4.jpg filter=lfs diff=lfs merge=lfs -text
|
42 |
+
categorised-images/categorised-images/cosmetics/5.jpg filter=lfs diff=lfs merge=lfs -text
|
43 |
+
categorised-images/categorised-images/food/1.jpg filter=lfs diff=lfs merge=lfs -text
|
44 |
+
categorised-images/categorised-images/food/2.jpg filter=lfs diff=lfs merge=lfs -text
|
45 |
+
categorised-images/categorised-images/food/3.jpeg filter=lfs diff=lfs merge=lfs -text
|
46 |
+
categorised-images/categorised-images/food/4.jpeg filter=lfs diff=lfs merge=lfs -text
|
47 |
+
categorised-images/categorised-images/furniture/1.JPG filter=lfs diff=lfs merge=lfs -text
|
48 |
+
categorised-images/categorised-images/furniture/2.JPG filter=lfs diff=lfs merge=lfs -text
|
49 |
+
categorised-images/categorised-images/furniture/3.JPG filter=lfs diff=lfs merge=lfs -text
|
50 |
+
categorised-images/categorised-images/furniture/4.jpg filter=lfs diff=lfs merge=lfs -text
|
51 |
+
categorised-images/categorised-images/furniture/5.jpg filter=lfs diff=lfs merge=lfs -text
|
52 |
+
categorised-images/categorised-images/jewellery/1.jpg filter=lfs diff=lfs merge=lfs -text
|
53 |
+
categorised-images/categorised-images/jewellery/2.jpg filter=lfs diff=lfs merge=lfs -text
|
54 |
+
categorised-images/categorised-images/jewellery/3.jpg filter=lfs diff=lfs merge=lfs -text
|
55 |
+
categorised-images/categorised-images/jewellery/image_b076d9ed06624b6183836bdda784fbb7.png filter=lfs diff=lfs merge=lfs -text
|
56 |
+
categorised-images/categorised-images/person/1[[:space:]]2.jpg filter=lfs diff=lfs merge=lfs -text
|
57 |
+
categorised-images/categorised-images/person/2.jpg filter=lfs diff=lfs merge=lfs -text
|
58 |
+
categorised-images/categorised-images/person/3.jpg filter=lfs diff=lfs merge=lfs -text
|
59 |
+
categorised-images/categorised-images/person/4.jpg filter=lfs diff=lfs merge=lfs -text
|
60 |
+
categorised-images/categorised-images/person/5.jpg filter=lfs diff=lfs merge=lfs -text
|
61 |
+
categorised-images/categorised-images/person/opendiffusionai_pexels-photos-janpf_1.jpg filter=lfs diff=lfs merge=lfs -text
|
62 |
+
categorised-images/categorised-images/plant/opendiffusionai_pexels-photos-janp_114.jpg filter=lfs diff=lfs merge=lfs -text
|
63 |
+
categorised-images/categorised-images/plant/opendiffusionai_pexels-photos-janpf_140.jpg filter=lfs diff=lfs merge=lfs -text
|
64 |
+
categorised-images/categorised-images/sculpture/2.JPG filter=lfs diff=lfs merge=lfs -text
|
65 |
+
categorised-images/categorised-images/sculpture/9.JPG filter=lfs diff=lfs merge=lfs -text
|
66 |
+
categorised-images/categorised-images/shoe/4.jpg filter=lfs diff=lfs merge=lfs -text
|
67 |
+
categorised-images/categorised-images/shoe/allenai_pixmo-cap_50228.jpg filter=lfs diff=lfs merge=lfs -text
|
68 |
+
categorised-images/categorised-images/toy/allenai_pixmo-cap_113119.jpg filter=lfs diff=lfs merge=lfs -text
|
69 |
+
categorised-images/categorised-images/toy/allenai_pixmo-cap_372195.jpg filter=lfs diff=lfs merge=lfs -text
|
70 |
+
categorised-images/categorised-images/toy/allenai_pixmo-cap_433736.jpeg filter=lfs diff=lfs merge=lfs -text
|
71 |
+
categorised-images/categorised-images/vehicle/opendiffusionai_pexels-photos-janpf_201.jpg filter=lfs diff=lfs merge=lfs -text
|
72 |
+
data/resized/bria/clothing_3.png filter=lfs diff=lfs merge=lfs -text
|
73 |
+
data/resized/bria/food_2.png filter=lfs diff=lfs merge=lfs -text
|
74 |
+
data/resized/bria/person_21449169794_d657f45a10_h.png filter=lfs diff=lfs merge=lfs -text
|
75 |
+
data/resized/bria/person_8387017807_f1f0c5c624_o.png filter=lfs diff=lfs merge=lfs -text
|
76 |
+
data/resized/photoroom/clothing_3.png filter=lfs diff=lfs merge=lfs -text
|
77 |
+
data/resized/photoroom/person_21449169794_d657f45a10_h.png filter=lfs diff=lfs merge=lfs -text
|
78 |
+
data/resized/photoroom/person_8387017807_f1f0c5c624_o.png filter=lfs diff=lfs merge=lfs -text
|
79 |
+
data/resized/removebg/clothing_3.png filter=lfs diff=lfs merge=lfs -text
|
80 |
+
data/resized/removebg/person_21449169794_d657f45a10_h.png filter=lfs diff=lfs merge=lfs -text
|
81 |
+
data/resized/removebg/person_8387017807_f1f0c5c624_o.png filter=lfs diff=lfs merge=lfs -text
|
82 |
+
data/web-original-images/clothing_allenai_pixmo-cap_482301.png filter=lfs diff=lfs merge=lfs -text
|
83 |
+
original-images/animal_opendiffusionai_pexels-photos-janpf_102.jpg filter=lfs diff=lfs merge=lfs -text
|
84 |
+
original-images/animal_opendiffusionai_pexels-photos-janpf_136.jpg filter=lfs diff=lfs merge=lfs -text
|
85 |
+
original-images/building_opendiffusionai_pexels-photos-janpf_94.jpg filter=lfs diff=lfs merge=lfs -text
|
86 |
+
original-images/clothing_3.jpg filter=lfs diff=lfs merge=lfs -text
|
87 |
+
original-images/cosmetics_3.jpg filter=lfs diff=lfs merge=lfs -text
|
88 |
+
original-images/cosmetics_4.jpg filter=lfs diff=lfs merge=lfs -text
|
89 |
+
original-images/cosmetics_5.jpg filter=lfs diff=lfs merge=lfs -text
|
90 |
+
original-images/food_1.jpg filter=lfs diff=lfs merge=lfs -text
|
91 |
+
original-images/food_2.jpg filter=lfs diff=lfs merge=lfs -text
|
92 |
+
original-images/food_3.jpeg filter=lfs diff=lfs merge=lfs -text
|
93 |
+
original-images/food_4.jpeg filter=lfs diff=lfs merge=lfs -text
|
94 |
+
original-images/furniture_1.JPG filter=lfs diff=lfs merge=lfs -text
|
95 |
+
original-images/furniture_2.JPG filter=lfs diff=lfs merge=lfs -text
|
96 |
+
original-images/furniture_3.JPG filter=lfs diff=lfs merge=lfs -text
|
97 |
+
original-images/furniture_4.jpg filter=lfs diff=lfs merge=lfs -text
|
98 |
+
original-images/furniture_5.jpg filter=lfs diff=lfs merge=lfs -text
|
99 |
+
original-images/jewellery_1.jpg filter=lfs diff=lfs merge=lfs -text
|
100 |
+
original-images/jewellery_2.jpg filter=lfs diff=lfs merge=lfs -text
|
101 |
+
original-images/jewellery_3.jpg filter=lfs diff=lfs merge=lfs -text
|
102 |
+
original-images/jewellery_image_b076d9ed06624b6183836bdda784fbb7.png filter=lfs diff=lfs merge=lfs -text
|
103 |
+
original-images/person_1[[:space:]]2.jpg filter=lfs diff=lfs merge=lfs -text
|
104 |
+
original-images/person_2.jpg filter=lfs diff=lfs merge=lfs -text
|
105 |
+
original-images/person_3.jpg filter=lfs diff=lfs merge=lfs -text
|
106 |
+
original-images/person_4.jpg filter=lfs diff=lfs merge=lfs -text
|
107 |
+
original-images/person_5.jpg filter=lfs diff=lfs merge=lfs -text
|
108 |
+
original-images/person_opendiffusionai_pexels-photos-janpf_1.jpg filter=lfs diff=lfs merge=lfs -text
|
109 |
+
original-images/plant_opendiffusionai_pexels-photos-janp_114.jpg filter=lfs diff=lfs merge=lfs -text
|
110 |
+
original-images/plant_opendiffusionai_pexels-photos-janpf_140.jpg filter=lfs diff=lfs merge=lfs -text
|
111 |
+
original-images/sculpture_2.JPG filter=lfs diff=lfs merge=lfs -text
|
112 |
+
original-images/sculpture_9.JPG filter=lfs diff=lfs merge=lfs -text
|
113 |
+
original-images/shoe_4.jpg filter=lfs diff=lfs merge=lfs -text
|
114 |
+
original-images/shoe_allenai_pixmo-cap_50228.jpg filter=lfs diff=lfs merge=lfs -text
|
115 |
+
original-images/toy_allenai_pixmo-cap_113119.jpg filter=lfs diff=lfs merge=lfs -text
|
116 |
+
original-images/toy_allenai_pixmo-cap_372195.jpg filter=lfs diff=lfs merge=lfs -text
|
117 |
+
original-images/toy_allenai_pixmo-cap_433736.jpeg filter=lfs diff=lfs merge=lfs -text
|
118 |
+
original-images/vehicle_opendiffusionai_pexels-photos-janpf_201.jpg filter=lfs diff=lfs merge=lfs -text
|
119 |
+
profile_output.prof filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.env
|
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 5.7.1
|
8 |
app_file: app.py
|
|
|
1 |
---
|
2 |
+
title: background-removal-arena
|
3 |
+
emoji: ⚡
|
4 |
+
colorFrom: pink
|
5 |
+
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
sdk_version: 5.7.1
|
8 |
app_file: app.py
|
__pycache__/db.cpython-312.pyc
ADDED
Binary file (3.52 kB). View file
|
|
__pycache__/rating_systems.cpython-312.pyc
ADDED
Binary file (3.22 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import logging
|
3 |
+
from typing import Tuple
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
import gradio as gr
|
6 |
+
import numpy as np
|
7 |
+
from PIL import Image
|
8 |
+
import random
|
9 |
+
from db import compute_elo_scores, get_all_votes
|
10 |
+
|
11 |
+
# Configure logging
|
12 |
+
logging.basicConfig(level=logging.INFO)
|
13 |
+
|
14 |
+
# Load environment variables from .env file
|
15 |
+
load_dotenv()
|
16 |
+
|
17 |
+
# Access the API key
|
18 |
+
PHOTOROOM_API_KEY = os.getenv('PHOTOROOM_API_KEY')
|
19 |
+
CLIPDROP_API_KEY = os.getenv('CLIPDROP_API_KEY')
|
20 |
+
|
21 |
+
|
22 |
+
def fetch_elo_scores():
|
23 |
+
"""Fetch and log Elo scores."""
|
24 |
+
try:
|
25 |
+
elo_scores = compute_elo_scores()
|
26 |
+
logging.info("Elo scores successfully computed.")
|
27 |
+
return elo_scores
|
28 |
+
except Exception as e:
|
29 |
+
logging.error("Error computing Elo scores: %s", str(e))
|
30 |
+
return None
|
31 |
+
|
32 |
+
def update_rankings_table():
|
33 |
+
"""Update and return the rankings table based on Elo scores."""
|
34 |
+
elo_scores = fetch_elo_scores()
|
35 |
+
if elo_scores:
|
36 |
+
rankings = [
|
37 |
+
["Photoroom", int(elo_scores.get("Photoroom", 1000))],
|
38 |
+
#["Clipdrop", int(elo_scores.get("Clipdrop", 1000))],
|
39 |
+
["RemoveBG", int(elo_scores.get("RemoveBG", 1000))],
|
40 |
+
["BRIA RMBG 2.0", int(elo_scores.get("BRIA RMBG 2.0", 1000))],
|
41 |
+
]
|
42 |
+
rankings.sort(key=lambda x: x[1], reverse=True)
|
43 |
+
return rankings
|
44 |
+
else:
|
45 |
+
return [
|
46 |
+
["Photoroom", -1],
|
47 |
+
#["Clipdrop", -1],
|
48 |
+
["RemoveBG", -1],
|
49 |
+
["BRIA RMBG 2.0", -1],
|
50 |
+
]
|
51 |
+
|
52 |
+
def select_new_image():
|
53 |
+
"""Select a new image and its segmented versions."""
|
54 |
+
image_paths = load_images_from_directory("data/web-original-images")
|
55 |
+
random.shuffle(image_paths) # Shuffle images to ensure randomness on reload
|
56 |
+
last_image_path = None
|
57 |
+
max_attempts = 10
|
58 |
+
|
59 |
+
for _ in range(max_attempts):
|
60 |
+
available_images = [path for path in image_paths if path != last_image_path]
|
61 |
+
|
62 |
+
if not available_images:
|
63 |
+
logging.error("No available images to select from.")
|
64 |
+
return None
|
65 |
+
|
66 |
+
random_image_path = random.choice(available_images)
|
67 |
+
input_image = Image.open(random_image_path)
|
68 |
+
|
69 |
+
image_filename = os.path.splitext(os.path.basename(random_image_path))[0] + ".png"
|
70 |
+
segmented_image_paths = {
|
71 |
+
"Photoroom": os.path.join("data/resized/photoroom", image_filename),
|
72 |
+
#"Clipdrop": os.path.join("data/processed/clipdrop", image_filename),
|
73 |
+
"RemoveBG": os.path.join("data/resized/removebg", image_filename),
|
74 |
+
"BRIA RMBG 2.0": os.path.join("data/resized/bria", image_filename)
|
75 |
+
}
|
76 |
+
|
77 |
+
try:
|
78 |
+
selected_models = random.sample(list(segmented_image_paths.keys()), 2)
|
79 |
+
model_a_name, model_b_name = selected_models
|
80 |
+
model_a_output_path = segmented_image_paths[model_a_name]
|
81 |
+
model_b_output_path = segmented_image_paths[model_b_name]
|
82 |
+
model_a_output_image = Image.open(model_a_output_path)
|
83 |
+
model_b_output_image = Image.open(model_b_output_path)
|
84 |
+
return (random_image_path, input_image, model_a_output_path, model_a_output_image,
|
85 |
+
model_b_output_path, model_b_output_image, model_a_name, model_b_name)
|
86 |
+
except FileNotFoundError as e:
|
87 |
+
logging.error("File not found: %s. Resampling another image.", e)
|
88 |
+
last_image_path = random_image_path
|
89 |
+
|
90 |
+
logging.error("Failed to select a new image after %d attempts.", max_attempts)
|
91 |
+
return None
|
92 |
+
|
93 |
+
def get_notice_markdown():
|
94 |
+
"""Generate the notice markdown with dynamic vote count."""
|
95 |
+
total_votes = len(get_all_votes())
|
96 |
+
return f"""
|
97 |
+
# ⚔️ Background Removal Arena: Compare & Test the Best Background Removal Models
|
98 |
+
|
99 |
+
## 📜 How It Works
|
100 |
+
- **Blind Test**: You will see two images with their background removed from two anonymous background removal models (Clipdrop, RemoveBG, Photoroom, BRIA RMBG 2.0).
|
101 |
+
- **Vote for the Best**: Choose the best result, if none stand out choose "Tie".
|
102 |
+
|
103 |
+
## 📊 Stats
|
104 |
+
- **Total #votes**: {total_votes}
|
105 |
+
|
106 |
+
## 👇 Test now!
|
107 |
+
"""
|
108 |
+
|
109 |
+
def compute_mask_difference(segmented_a, segmented_b):
|
110 |
+
"""Compute the absolute difference between two image masks."""
|
111 |
+
mask_a = np.asarray(segmented_a)
|
112 |
+
mask_b = np.asarray(segmented_b)
|
113 |
+
|
114 |
+
# Create a binary mask where non-transparent pixels are marked as 1
|
115 |
+
mask_a_1d = np.where(mask_a[..., 3] != 0, 1, 0)
|
116 |
+
mask_b_1d = np.where(mask_b[..., 3] != 0, 1, 0)
|
117 |
+
|
118 |
+
# Compute the absolute difference between the masks
|
119 |
+
return np.abs(mask_a_1d - mask_b_1d)
|
120 |
+
|
121 |
+
def gradio_interface():
|
122 |
+
"""Create and return the Gradio interface."""
|
123 |
+
with gr.Blocks() as demo:
|
124 |
+
gr.Markdown("# Background Removal Arena")
|
125 |
+
|
126 |
+
with gr.Tabs() as tabs:
|
127 |
+
with gr.Tab("⚔️ Arena (battle)", id=0):
|
128 |
+
notice_markdown = gr.Markdown(get_notice_markdown(), elem_id="notice_markdown")
|
129 |
+
|
130 |
+
(fpath_input, input_image, fpath_a, segmented_a, fpath_b, segmented_b,
|
131 |
+
a_name, b_name) = select_new_image()
|
132 |
+
model_a_name = gr.State(a_name)
|
133 |
+
model_b_name = gr.State(b_name)
|
134 |
+
fpath_input = gr.State(fpath_input)
|
135 |
+
fpath_a = gr.State(fpath_a)
|
136 |
+
fpath_b = gr.State(fpath_b)
|
137 |
+
|
138 |
+
# Compute the absolute difference between the masks
|
139 |
+
mask_difference = compute_mask_difference(segmented_a, segmented_b)
|
140 |
+
|
141 |
+
with gr.Row():
|
142 |
+
image_a_display = gr.Image(
|
143 |
+
value=segmented_a,
|
144 |
+
type="pil",
|
145 |
+
label="Model A",
|
146 |
+
width=500,
|
147 |
+
height=500
|
148 |
+
)
|
149 |
+
input_image_display = gr.AnnotatedImage(
|
150 |
+
value=(input_image, [(mask_difference > 0, "Difference Mask")]),
|
151 |
+
label="Input Image",
|
152 |
+
width=500,
|
153 |
+
height=500
|
154 |
+
)
|
155 |
+
image_b_display = gr.Image(
|
156 |
+
value=segmented_b,
|
157 |
+
type="pil",
|
158 |
+
label="Model B",
|
159 |
+
width=500,
|
160 |
+
height=500
|
161 |
+
)
|
162 |
+
tie = gr.State("Tie")
|
163 |
+
with gr.Row():
|
164 |
+
vote_a_btn = gr.Button("👈 A is better")
|
165 |
+
vote_tie = gr.Button("🤝 Tie")
|
166 |
+
vote_b_btn = gr.Button("👉 B is better")
|
167 |
+
|
168 |
+
|
169 |
+
vote_a_btn.click(
|
170 |
+
fn=lambda: vote_for_model("model_a", (fpath_input, fpath_a, fpath_b), model_a_name, model_b_name),
|
171 |
+
outputs=[
|
172 |
+
fpath_input, input_image_display, fpath_a, image_a_display, fpath_b, image_b_display, model_a_name, model_b_name, notice_markdown
|
173 |
+
]
|
174 |
+
)
|
175 |
+
vote_b_btn.click(
|
176 |
+
fn=lambda: vote_for_model("model_b", (fpath_input, fpath_a, fpath_b), model_a_name, model_b_name),
|
177 |
+
outputs=[
|
178 |
+
fpath_input, input_image_display, fpath_a, image_a_display, fpath_b, image_b_display, model_a_name, model_b_name, notice_markdown
|
179 |
+
]
|
180 |
+
)
|
181 |
+
vote_tie.click(
|
182 |
+
fn=lambda: vote_for_model("tie", (fpath_input, fpath_a, fpath_b), model_a_name, model_b_name),
|
183 |
+
outputs=[
|
184 |
+
fpath_input, input_image_display, fpath_a, image_a_display, fpath_b, image_b_display, model_a_name, model_b_name, notice_markdown
|
185 |
+
]
|
186 |
+
)
|
187 |
+
|
188 |
+
def vote_for_model(choice, fpaths, model_a_name, model_b_name):
|
189 |
+
"""Submit a vote for a model and return updated images and model names."""
|
190 |
+
logging.info("Voting for model: %s", choice)
|
191 |
+
|
192 |
+
vote_data = {
|
193 |
+
"image_id": fpaths[0].value,
|
194 |
+
"model_a": model_a_name.value,
|
195 |
+
"model_b": model_b_name.value,
|
196 |
+
"winner": choice,
|
197 |
+
"fpath_a": fpaths[1].value,
|
198 |
+
"fpath_b": fpaths[2].value,
|
199 |
+
}
|
200 |
+
|
201 |
+
try:
|
202 |
+
logging.debug("Adding vote data to the database: %s", vote_data)
|
203 |
+
from db import add_vote
|
204 |
+
result = add_vote(vote_data)
|
205 |
+
logging.info("Vote successfully recorded in the database with ID: %s", result["id"])
|
206 |
+
except Exception as e:
|
207 |
+
logging.error("Error recording vote: %s", str(e))
|
208 |
+
|
209 |
+
(new_fpath_input, new_input_image, new_fpath_a, new_segmented_a,
|
210 |
+
new_fpath_b, new_segmented_b, new_a_name, new_b_name) = select_new_image()
|
211 |
+
model_a_name.value = new_a_name
|
212 |
+
model_b_name.value = new_b_name
|
213 |
+
fpath_input.value = new_fpath_input
|
214 |
+
fpath_a.value = new_fpath_a
|
215 |
+
fpath_b.value = new_fpath_b
|
216 |
+
|
217 |
+
mask_difference = compute_mask_difference(new_segmented_a, new_segmented_b)
|
218 |
+
|
219 |
+
# Update the notice markdown with the new vote count
|
220 |
+
new_notice_markdown = get_notice_markdown()
|
221 |
+
|
222 |
+
return (fpath_input.value, (new_input_image, [(mask_difference, "Mask")]), fpath_a.value, new_segmented_a,
|
223 |
+
fpath_b.value, new_segmented_b, model_a_name.value, model_b_name.value, new_notice_markdown)
|
224 |
+
|
225 |
+
with gr.Tab("🏆 Leaderboard", id=1) as leaderboard_tab:
|
226 |
+
rankings_table = gr.Dataframe(
|
227 |
+
headers=["Model", "Ranking"],
|
228 |
+
value=update_rankings_table(),
|
229 |
+
label="Current Model Rankings",
|
230 |
+
column_widths=[180, 60],
|
231 |
+
row_count=4
|
232 |
+
)
|
233 |
+
|
234 |
+
leaderboard_tab.select(
|
235 |
+
fn=lambda: update_rankings_table(),
|
236 |
+
outputs=rankings_table
|
237 |
+
)
|
238 |
+
|
239 |
+
with gr.Tab("📊 Vote Data", id=2) as vote_data_tab:
|
240 |
+
def update_vote_data():
|
241 |
+
votes = get_all_votes()
|
242 |
+
return [[vote.id, vote.image_id, vote.model_a, vote.model_b, vote.winner, vote.timestamp] for vote in votes]
|
243 |
+
|
244 |
+
vote_table = gr.Dataframe(
|
245 |
+
headers=["ID", "Image ID", "Model A", "Model B", "Winner", "Timestamp"],
|
246 |
+
value=update_vote_data(),
|
247 |
+
label="Vote Data",
|
248 |
+
column_widths=[20, 150, 100, 100, 100, 150],
|
249 |
+
row_count=0
|
250 |
+
)
|
251 |
+
|
252 |
+
vote_data_tab.select(
|
253 |
+
fn=lambda: update_vote_data(),
|
254 |
+
outputs=vote_table
|
255 |
+
)
|
256 |
+
|
257 |
+
return demo
|
258 |
+
|
259 |
+
def load_images_from_directory(directory):
|
260 |
+
"""Load and return image paths from a directory."""
|
261 |
+
image_files = [f for f in os.listdir(directory) if f.endswith(('.png', '.jpg', '.jpeg'))]
|
262 |
+
return [os.path.join(directory, f) for f in image_files]
|
263 |
+
|
264 |
+
if __name__ == "__main__":
|
265 |
+
demo = gradio_interface()
|
266 |
+
demo.launch()
|
categorised-images/categorised-images/.DS_Store
ADDED
Binary file (14.3 kB). View file
|
|
categorised-images/categorised-images/animal/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
categorised-images/categorised-images/animal/opendiffusionai-pexels-photos-janpf_52.jpg
ADDED
categorised-images/categorised-images/animal/opendiffusionai_pexels-photos-janpf_102.jpg
ADDED
Git LFS Details
|
categorised-images/categorised-images/animal/opendiffusionai_pexels-photos-janpf_136.jpg
ADDED
Git LFS Details
|
categorised-images/categorised-images/animal/opendiffusionai_pexels-photos-janpf_194.jpg
ADDED
categorised-images/categorised-images/animal/opendiffusionai_pexels-photos-janpf_51.jpg
ADDED
categorised-images/categorised-images/bag/allenai_pixmo-cap_334346.jpg
ADDED
categorised-images/categorised-images/bag/allenai_pixmo-cap_405245.jpg
ADDED
categorised-images/categorised-images/bag/allenai_pixmo-cap_81121.png
ADDED
categorised-images/categorised-images/bag/allenai_pixmo-cap_98712.jpg
ADDED
categorised-images/categorised-images/building/opendiffusionai_pexels-photos-janpf_94.jpg
ADDED
Git LFS Details
|
categorised-images/categorised-images/clothing/2.jpeg
ADDED
categorised-images/categorised-images/clothing/3.jpg
ADDED
Git LFS Details
|
categorised-images/categorised-images/clothing/allenai_pixmo-cap_213594.webp
ADDED
categorised-images/categorised-images/clothing/allenai_pixmo-cap_225437.jpg
ADDED
categorised-images/categorised-images/clothing/allenai_pixmo-cap_230843.jpg
ADDED
categorised-images/categorised-images/clothing/allenai_pixmo-cap_244629.webp
ADDED
categorised-images/categorised-images/clothing/allenai_pixmo-cap_258545.jpg
ADDED
categorised-images/categorised-images/clothing/allenai_pixmo-cap_26857.jpg
ADDED
categorised-images/categorised-images/clothing/allenai_pixmo-cap_482301.png
ADDED
categorised-images/categorised-images/clothing/allenai_pixmo-cap_579538.webp
ADDED
categorised-images/categorised-images/clothing/allenai_pixmo-cap_60862.jpg
ADDED
categorised-images/categorised-images/clothing/allenai_pixmo-cap_637905.jpg
ADDED
categorised-images/categorised-images/clothing/allenai_pixmo-cap_674305.webp
ADDED
categorised-images/categorised-images/clothing/allenai_pixmo-cap_7680.webp
ADDED
categorised-images/categorised-images/cosmetics/1.jpeg
ADDED
categorised-images/categorised-images/cosmetics/2.jpg
ADDED
categorised-images/categorised-images/cosmetics/3.jpg
ADDED
Git LFS Details
|
categorised-images/categorised-images/cosmetics/4.jpg
ADDED
Git LFS Details
|
categorised-images/categorised-images/cosmetics/5.jpg
ADDED
Git LFS Details
|
categorised-images/categorised-images/cosmetics/opendiffusionai_pexels-photos-janpf_99.jpg
ADDED
categorised-images/categorised-images/fashion accessory/allenai_pixmo-cap_247631.jpg
ADDED
categorised-images/categorised-images/fashion accessory/allenai_pixmo-cap_448841.jpg
ADDED
categorised-images/categorised-images/fashion accessory/allenai_pixmo-cap_627930.jpg
ADDED
categorised-images/categorised-images/fashion accessory/opendiffusionai-pexels-photos-janpf_19.jpg
ADDED
categorised-images/categorised-images/food/1.jpg
ADDED
Git LFS Details
|
categorised-images/categorised-images/food/2.jpg
ADDED
Git LFS Details
|
categorised-images/categorised-images/food/3.jpeg
ADDED
Git LFS Details
|
categorised-images/categorised-images/food/4.jpeg
ADDED
Git LFS Details
|
categorised-images/categorised-images/furniture/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
categorised-images/categorised-images/furniture/1.JPG
ADDED
Git LFS Details
|
categorised-images/categorised-images/furniture/2.JPG
ADDED
Git LFS Details
|