Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,68 @@
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
def greet(name):
|
4 |
-
return f"Hello, {name}!"
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
demo.launch()
|
|
|
1 |
+
from itertools import combinations
|
2 |
import gradio as gr
|
3 |
+
from PIL import Image
|
4 |
+
from pathlib import Path
|
5 |
|
|
|
|
|
6 |
|
7 |
+
subgroups = []
|
8 |
+
DEFAULT_RAW_DATA_PATH = "raw_data.json"
|
9 |
+
with open(DEFAULT_RAW_DATA_PATH, 'r') as file:
|
10 |
+
raw_data = json.load(file)
|
11 |
+
|
12 |
+
|
13 |
+
for group in raw_data:
|
14 |
+
if len(group) > 3 and len(group)<6:
|
15 |
+
for size in [2, 3]:
|
16 |
+
subgroups.extend(list(combinations(group, size)))
|
17 |
+
|
18 |
+
# Optional: include the original small groups (size <= 3)
|
19 |
+
final_groups = [g for g in raw_data if len(g) <= 3] + [list(sg) for sg in subgroups]
|
20 |
+
|
21 |
+
|
22 |
+
sample = random.sample(subgroups,100)
|
23 |
+
sample_paths = []
|
24 |
+
for wall in sample:
|
25 |
+
paths = [enc_id_to_path_drive(encoded_imgs_csv, int(enc_id)) for enc_id in wall]
|
26 |
+
sample_paths.append(paths)
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
+
# ==== YOUR DATA ====
|
32 |
+
# Each subgroup is a list of image paths
|
33 |
+
|
34 |
+
results = [] # Store user feedback
|
35 |
+
|
36 |
+
# ==== INTERFACE LOGIC ====
|
37 |
+
def review_group(index, like):
|
38 |
+
if index < len(sample_paths):
|
39 |
+
decision = "like" if like else "dislike"
|
40 |
+
results.append({"group": sample_paths[index], "decision": decision})
|
41 |
+
|
42 |
+
next_index = index + 1
|
43 |
+
if next_index < len(sample_paths):
|
44 |
+
return (
|
45 |
+
[Image.open(p) for p in sample_paths[next_index]],
|
46 |
+
next_index
|
47 |
+
)
|
48 |
+
else:
|
49 |
+
return ([], next_index)
|
50 |
+
|
51 |
+
# ==== UI ====
|
52 |
+
with gr.Blocks() as demo:
|
53 |
+
group_index = gr.State(0)
|
54 |
+
image_gallery = gr.Gallery(label="Artwork Group", columns=3, height="auto")
|
55 |
+
|
56 |
+
with gr.Row():
|
57 |
+
like_btn = gr.Button("👍 Like")
|
58 |
+
dislike_btn = gr.Button("👎 Dislike")
|
59 |
+
|
60 |
+
# Actions
|
61 |
+
like_btn.click(review_group, [group_index, gr.State(True)], [image_gallery, group_index])
|
62 |
+
dislike_btn.click(review_group, [group_index, gr.State(False)], [image_gallery, group_index])
|
63 |
+
|
64 |
+
# Load first group
|
65 |
+
demo.load(fn=lambda: ([Image.open(p) for p in sample_paths[0]], 0), outputs=[image_gallery, group_index])
|
66 |
+
|
67 |
+
# ==== Run ====
|
68 |
demo.launch()
|