-
Notifications
You must be signed in to change notification settings - Fork 0
/
annotate.py
99 lines (76 loc) · 3.39 KB
/
annotate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import pandas as pd
import os
import tkinter as tk
from tkinter import filedialog
from PIL import Image, ImageTk
# Load the CSV file
csv_file = 'User_Study.csv'
df = pd.read_csv(csv_file)
responses = []
class ImagePromptWindow:
def __init__(self, master, row, on_submit):
self.master = master
self.row = row
self.on_submit = on_submit
# Read image and create ImageTk.PhotoImage object
image_path = f"Images/{row['ID']}.png" if os.path.exists(f"Images/{row['ID']}.png") else f"Images/{row['ID']}.jpg"
image = Image.open(image_path)
image.thumbnail((400, 400))
self.img = ImageTk.PhotoImage(image)
# Display image
self.img_label = tk.Label(self.master, image=self.img)
self.img_label.pack()
# Display prompts
self.prompt1_label = tk.Label(self.master, text=f"Prompt 1: {row['Prompt 1']}", font=("Arial", 14))
self.prompt1_label.pack()
self.prompt2_label = tk.Label(self.master, text=f"Prompt 2: {row['Prompt 2']}", font=("Arial", 14))
self.prompt2_label.pack()
# Entry fields for user input
self.prompt1_var = tk.IntVar()
self.prompt2_var = tk.IntVar()
self.neither_var = tk.IntVar()
self.image_identical_var = tk.IntVar()
self.threeD_identical_var = tk.IntVar()
self.video_identical_var = tk.IntVar()
tk.Checkbutton(self.master, text="Is Prompt 1", variable=self.prompt1_var).pack()
tk.Checkbutton(self.master, text="Is Prompt 2", variable=self.prompt2_var).pack()
tk.Checkbutton(self.master, text="Neither / Wrong", variable=self.neither_var).pack()
tk.Checkbutton(self.master, text="Prompts visually identical (image)", variable=self.image_identical_var).pack()
# Submit button to save user input
self.submit_button = tk.Button(self.master, text="Submit", command=self.submit)
self.submit_button.pack()
def submit(self):
# Save user input
df.loc[df['ID'] == self.row['ID'], 'Is Prompt 1'] = self.prompt1_var.get()
df.loc[df['ID'] == self.row['ID'], 'Is Prompt 2'] = self.prompt2_var.get()
df.loc[df['ID'] == self.row['ID'], 'Neither / Wrong'] = self.neither_var.get()
df.loc[df['ID'] == self.row['ID'], 'Prompts visually identical (image)'] = self.image_identical_var.get()
# Save responses to the original CSV file
df.to_csv(csv_file, index=False)
self.on_submit()
self.master.destroy()
def submit_backup(self):
# Save user input
response = {
'ID': self.row['ID'],
'Is Prompt 1': self.prompt1_var.get(),
'Is Prompt 2': self.prompt2_var.get(),
'Neither / Wrong': self.neither_var.get(),
'Prompts visually identical (image)': self.image_identical_var.get()
}
responses.append(response)
# Save responses to CSV
responses_df = pd.DataFrame(responses)
responses_df.to_csv('responses.csv', index=False)
self.on_submit()
self.master.destroy()
def open_next_image(index):
if index < len(df):
row = df.loc[index]
window = tk.Toplevel()
window.title(f"ID: {row['ID']}")
app = ImagePromptWindow(window, row, lambda: open_next_image(index + 1))
root = tk.Tk()
root.withdraw() # Hide the root window
open_next_image(0)
root.mainloop()