히스토리 무제한 보기/엑셀로 저장 (#1)
Browse files- 히스토리 무제한 보기/엑셀로 저장 (d7e89788647396f6de2f29453cb9b080f923fe3f)
Co-authored-by: leechan <highnoon1@users.noreply.huggingface.co>
1234567825 unmodified lines343536353738394041424347 unmodified lines91929389909495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431 unmodified line145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177102103178179180181182106183184185109186187188112189190191192193194195196197198199200import tkinter as tkimport tkinter.ttk as ttkfrom tkinter import filedialogfrom tkinter import Canvas, Scrollbar, Frame, Buttonfrom PIL import Image, ImageTkimport osimport csvimport random25 unmodified linesimport pandas as pdimport webbrowserfrom collections import OrderedDict
import platformimport iofrom openpyxl import Workbookfrom openpyxl.drawing.image import Image as OpenpyxlImageBASE_URL="https://api.novelai.net"copyright_keys = copyright_list_reformatted.copyright_listcharacter_keys = list(cd.character_dictionary.keys())47 unmodified linesdef history_queue(image, prompt, seed): global history history.append([image, prompt, seed]) if len(history) > 5: history.pop(0)
def save_to_excel(): workbook = Workbook() sheet = workbook.active
sheet['A1'] = 'Prompt' sheet['B1'] = 'Seed' sheet['C1'] = 'Image'
image_objects = [] # BytesIO 객체를 추적하기 위한 리스트
# history 데이터를 반복하며 Excel에 저장 for index, (pil_image, prompt, seed) in enumerate(history, start=1): row_num = index + 1 # 행 번호 (Excel 행은 1부터 시작)
# 프롬프트와 시드 삽입 sheet.cell(row=row_num, column=1, value=prompt) sheet.cell(row=row_num, column=2, value=seed)
# PIL 이미지를 BytesIO 객체에 PNG 형식으로 저장 output = io.BytesIO() pil_image.save(output, format='PNG') output.seek(0) image_objects.append(output) # 리스트에 추가
# Openpyxl 이미지 생성 및 시트에 추가 img = OpenpyxlImage(output) img.anchor = f'C{row_num}' # 이미지를 C열에 고정 sheet.add_image(img)
# 이미지 크기에 따라 행 높이 및 열 너비 조정 scale_factor = 0.75 sheet.row_dimensions[row_num].height = pil_image.height * scale_factor sheet.column_dimensions['C'].width = pil_image.width * scale_factor / 7
# A열과 B열 크기 조정 sheet.column_dimensions['A'].width = 50 sheet.column_dimensions['B'].width = 15
# 워크북 저장 workbook.save("history_with_images.xlsx")
# 모든 BytesIO 객체 닫기 for img_obj in image_objects: img_obj.close()
print("엑셀 파일에 저장됨")
def show_history(): global history1 unmodified line # 새로운 toplevel 창 생성 history_window = tk.Toplevel(window) history_window.title("History") # 창의 크기 history_window.geometry("1920x1080")
# Scrollable Canvas 설정 canvas = Canvas(history_window) scrollbar = Scrollbar(history_window, orient="vertical", command=canvas.yview) scrollable_frame = Frame(canvas)
# 스크롤 이벤트 바인딩 def _on_mousewheel(event): canvas.yview_scroll(int(-1*(event.delta/120)), "units")
if platform.system() == "Windows": history_window.bind_all("<MouseWheel>", _on_mousewheel) else: history_window.bind_all("<Button-4>", _on_mousewheel) history_window.bind_all("<Button-5>", _on_mousewheel)
def on_frame_configure(event): canvas.configure(scrollregion=canvas.bbox("all"))
scrollable_frame.bind("<Configure>", on_frame_configure)
canvas.create_window((0, 0), window=scrollable_frame, anchor="nw") canvas.configure(yscrollcommand=scrollbar.set) # history_window에서 썸네일과 텍스트를 표시할 grid 설정 for index, (image, prompt, seed) in enumerate(history): # 이미지를 썸네일로 변환 image.thumbnail((192, 192)) # 가로 세로 100픽셀로 조정 photo = ImageTk.PhotoImage(image) image.thumbnail((192, 192)) photo = ImageTk.PhotoImage(image)
# 썸네일 이미지 라벨 생성 image_label = tk.Label(history_window, image=photo) image_label = tk.Label(scrollable_frame, image=photo) image_label.image = photo # 참조를 유지 image_label.grid(row=index, column=0)
# prompt와 seed를 결합한 텍스트 생성 text_prompt = prompt + ' Seed: ' + str(seed) text_widget = tk.Text(history_window, height=10, width=75) # UI 사이즈에 맞게 width와 height 조절 text_widget = tk.Text(scrollable_frame, height=10, width=75) text_widget.insert('1.0', text_prompt) text_widget.grid(row=index, column=1) text_widget.config(state='disabled') # 텍스트 위젯을 읽기 전용으로 설정 save_button = Button(history_window, text="Save to Excel", command=save_to_excel) save_button.pack() # Canvas와 Scrollbar를 pack하여 UI에 추가 canvas.pack(side="left", fill="both", expand=True) scrollbar.pack(side="right", fill="y")
def generate(width, height, positive, negative, button): global temp_clipboard_imageDanbooru Prompt Selector/.py_version/prompt_selector_1215.py+90-8