naamaslomi commited on
Commit
8ae6e06
·
verified ·
1 Parent(s): 605bcd3

Create app.py

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