히스토리 무제한 보기/엑셀로 저장
Browse files
Danbooru Prompt Selector/.py_version/prompt_selector_1215.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
import tkinter as tk
|
2 |
import tkinter.ttk as ttk
|
3 |
from tkinter import filedialog
|
|
|
|
|
4 |
import os
|
5 |
import csv
|
6 |
import random
|
@@ -32,7 +34,10 @@ import character_dictionary as cd
|
|
32 |
import pandas as pd
|
33 |
import webbrowser
|
34 |
from collections import OrderedDict
|
35 |
-
|
|
|
|
|
|
|
36 |
BASE_URL="https://api.novelai.net"
|
37 |
copyright_keys = copyright_list_reformatted.copyright_list
|
38 |
character_keys = list(cd.character_dictionary.keys())
|
@@ -86,8 +91,53 @@ def generate_image(access_token, prompt, model, action, parameters):
|
|
86 |
def history_queue(image, prompt, seed):
|
87 |
global history
|
88 |
history.append([image, prompt, seed])
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
def show_history():
|
93 |
global history
|
@@ -95,24 +145,56 @@ def show_history():
|
|
95 |
# 새로운 toplevel 창 생성
|
96 |
history_window = tk.Toplevel(window)
|
97 |
history_window.title("History")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
|
|
|
|
|
|
99 |
# history_window에서 썸네일과 텍스트를 표시할 grid 설정
|
100 |
for index, (image, prompt, seed) in enumerate(history):
|
101 |
# 이미지를 썸네일로 변환
|
102 |
-
image.thumbnail((192, 192)) # 가로 세로 100픽셀로 조정
|
103 |
-
photo = ImageTk.PhotoImage(image)
|
104 |
|
|
|
|
|
|
|
105 |
# 썸네일 이미지 라벨 생성
|
106 |
-
image_label = tk.Label(
|
107 |
image_label.image = photo # 참조를 유지
|
108 |
image_label.grid(row=index, column=0)
|
109 |
-
|
110 |
# prompt와 seed를 결합한 텍스트 생성
|
111 |
text_prompt = prompt + ' Seed: ' + str(seed)
|
112 |
-
text_widget = tk.Text(
|
113 |
text_widget.insert('1.0', text_prompt)
|
114 |
text_widget.grid(row=index, column=1)
|
115 |
text_widget.config(state='disabled') # 텍스트 위젯을 읽기 전용으로 설정
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
def generate(width, height, positive, negative, button):
|
118 |
global temp_clipboard_image
|
|
|
1 |
import tkinter as tk
|
2 |
import tkinter.ttk as ttk
|
3 |
from tkinter import filedialog
|
4 |
+
from tkinter import Canvas, Scrollbar, Frame, Button
|
5 |
+
from PIL import Image, ImageTk
|
6 |
import os
|
7 |
import csv
|
8 |
import random
|
|
|
34 |
import pandas as pd
|
35 |
import webbrowser
|
36 |
from collections import OrderedDict
|
37 |
+
import platform
|
38 |
+
import io
|
39 |
+
from openpyxl import Workbook
|
40 |
+
from openpyxl.drawing.image import Image as OpenpyxlImage
|
41 |
BASE_URL="https://api.novelai.net"
|
42 |
copyright_keys = copyright_list_reformatted.copyright_list
|
43 |
character_keys = list(cd.character_dictionary.keys())
|
|
|
91 |
def history_queue(image, prompt, seed):
|
92 |
global history
|
93 |
history.append([image, prompt, seed])
|
94 |
+
|
95 |
+
def save_to_excel():
|
96 |
+
workbook = Workbook()
|
97 |
+
sheet = workbook.active
|
98 |
+
|
99 |
+
sheet['A1'] = 'Prompt'
|
100 |
+
sheet['B1'] = 'Seed'
|
101 |
+
sheet['C1'] = 'Image'
|
102 |
+
|
103 |
+
image_objects = [] # BytesIO 객체를 추적하기 위한 리스트
|
104 |
+
|
105 |
+
# history 데이터를 반복하며 Excel에 저장
|
106 |
+
for index, (pil_image, prompt, seed) in enumerate(history, start=1):
|
107 |
+
row_num = index + 1 # 행 번호 (Excel 행은 1부터 시작)
|
108 |
+
|
109 |
+
# 프롬프트와 시드 삽입
|
110 |
+
sheet.cell(row=row_num, column=1, value=prompt)
|
111 |
+
sheet.cell(row=row_num, column=2, value=seed)
|
112 |
+
|
113 |
+
# PIL 이미지를 BytesIO 객체에 PNG 형식으로 저장
|
114 |
+
output = io.BytesIO()
|
115 |
+
pil_image.save(output, format='PNG')
|
116 |
+
output.seek(0)
|
117 |
+
image_objects.append(output) # 리스트에 추가
|
118 |
+
|
119 |
+
# Openpyxl 이미지 생성 및 시트에 추가
|
120 |
+
img = OpenpyxlImage(output)
|
121 |
+
img.anchor = f'C{row_num}' # 이미지를 C열에 고정
|
122 |
+
sheet.add_image(img)
|
123 |
+
|
124 |
+
# 이미지 크기에 따라 행 높이 및 열 너비 조정
|
125 |
+
scale_factor = 0.75
|
126 |
+
sheet.row_dimensions[row_num].height = pil_image.height * scale_factor
|
127 |
+
sheet.column_dimensions['C'].width = pil_image.width * scale_factor / 7
|
128 |
+
|
129 |
+
# A열과 B열 크기 조정
|
130 |
+
sheet.column_dimensions['A'].width = 50
|
131 |
+
sheet.column_dimensions['B'].width = 15
|
132 |
+
|
133 |
+
# 워크북 저장
|
134 |
+
workbook.save("history_with_images.xlsx")
|
135 |
+
|
136 |
+
# 모든 BytesIO 객체 닫기
|
137 |
+
for img_obj in image_objects:
|
138 |
+
img_obj.close()
|
139 |
+
|
140 |
+
print("엑셀 파일에 저장됨")
|
141 |
|
142 |
def show_history():
|
143 |
global history
|
|
|
145 |
# 새로운 toplevel 창 생성
|
146 |
history_window = tk.Toplevel(window)
|
147 |
history_window.title("History")
|
148 |
+
|
149 |
+
# 창의 크기
|
150 |
+
history_window.geometry("1920x1080")
|
151 |
+
|
152 |
+
# Scrollable Canvas 설정
|
153 |
+
canvas = Canvas(history_window)
|
154 |
+
scrollbar = Scrollbar(history_window, orient="vertical", command=canvas.yview)
|
155 |
+
scrollable_frame = Frame(canvas)
|
156 |
+
|
157 |
+
# 스크롤 이벤트 바인딩
|
158 |
+
def _on_mousewheel(event):
|
159 |
+
canvas.yview_scroll(int(-1*(event.delta/120)), "units")
|
160 |
+
|
161 |
+
if platform.system() == "Windows":
|
162 |
+
history_window.bind_all("<MouseWheel>", _on_mousewheel)
|
163 |
+
else:
|
164 |
+
history_window.bind_all("<Button-4>", _on_mousewheel)
|
165 |
+
history_window.bind_all("<Button-5>", _on_mousewheel)
|
166 |
+
|
167 |
+
def on_frame_configure(event):
|
168 |
+
canvas.configure(scrollregion=canvas.bbox("all"))
|
169 |
+
|
170 |
+
scrollable_frame.bind("<Configure>", on_frame_configure)
|
171 |
|
172 |
+
canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")
|
173 |
+
canvas.configure(yscrollcommand=scrollbar.set)
|
174 |
+
|
175 |
# history_window에서 썸네일과 텍스트를 표시할 grid 설정
|
176 |
for index, (image, prompt, seed) in enumerate(history):
|
177 |
# 이미지를 썸네일로 변환
|
|
|
|
|
178 |
|
179 |
+
image.thumbnail((192, 192))
|
180 |
+
photo = ImageTk.PhotoImage(image)
|
181 |
+
|
182 |
# 썸네일 이미지 라벨 생성
|
183 |
+
image_label = tk.Label(scrollable_frame, image=photo)
|
184 |
image_label.image = photo # 참조를 유지
|
185 |
image_label.grid(row=index, column=0)
|
186 |
+
|
187 |
# prompt와 seed를 결합한 텍스트 생성
|
188 |
text_prompt = prompt + ' Seed: ' + str(seed)
|
189 |
+
text_widget = tk.Text(scrollable_frame, height=10, width=75)
|
190 |
text_widget.insert('1.0', text_prompt)
|
191 |
text_widget.grid(row=index, column=1)
|
192 |
text_widget.config(state='disabled') # 텍스트 위젯을 읽기 전용으로 설정
|
193 |
+
save_button = Button(history_window, text="Save to Excel", command=save_to_excel)
|
194 |
+
save_button.pack()
|
195 |
+
# Canvas와 Scrollbar를 pack하여 UI에 추가
|
196 |
+
canvas.pack(side="left", fill="both", expand=True)
|
197 |
+
scrollbar.pack(side="right", fill="y")
|
198 |
|
199 |
def generate(width, height, positive, negative, button):
|
200 |
global temp_clipboard_image
|