|
1 | 1 | import gradio as gr
|
2 |
| -import json |
3 | 2 | import logging
|
4 | 3 | import os
|
5 | 4 | import random
|
| 5 | +import platform |
6 | 6 | import re
|
7 | 7 | import shutil
|
8 | 8 | import stat
|
| 9 | +import sys |
9 | 10 | import time
|
10 | 11 | import modules.extras
|
11 | 12 | import modules.ui
|
| 13 | +from modules import paths |
12 | 14 | from modules import script_callbacks
|
13 | 15 | from modules import shared, scripts, images
|
14 | 16 | from modules.shared import opts, cmd_opts
|
|
41 | 43 | current_depth = 0
|
42 | 44 | init = True
|
43 | 45 |
|
| 46 | +# Logging |
44 | 47 | logger = logging.getLogger(__name__)
|
45 | 48 | logger_mode = logging.ERROR
|
46 | 49 | if hasattr(opts, "image_browser_logger_warning"):
|
|
53 | 56 | console_handler = logging.StreamHandler()
|
54 | 57 | console_handler.setLevel(logger_mode)
|
55 | 58 | logger.addHandler(console_handler)
|
| 59 | +# Debug logging |
| 60 | +if logger.isEnabledFor(logging.DEBUG): |
| 61 | + logger.debug(f"{sys.executable} {sys.version}") |
| 62 | + logger.debug(f"{platform.system()} {platform.version()}") |
| 63 | + try: |
| 64 | + git = os.environ.get('GIT', "git") |
| 65 | + commit_hash = os.popen(f"{git} rev-parse HEAD").read() |
| 66 | + except Exception as e: |
| 67 | + commit_hash = e |
| 68 | + logger.debug(f"{commit_hash}") |
| 69 | + logger.debug(f"Gradio {gr.__version__}") |
| 70 | + logger.debug(f"{paths.script_path}") |
| 71 | + with open(cmd_opts.ui_config_file, "r") as f: |
| 72 | + logger.debug(f.read()) |
| 73 | + with open(cmd_opts.ui_settings_file, "r") as f: |
| 74 | + logger.debug(f.read()) |
56 | 75 |
|
57 | 76 | def delete_recycle(filename):
|
58 | 77 | if opts.image_browser_delete_recycle:
|
@@ -468,16 +487,22 @@ def get_image_page(img_path, page_index, filenames, keyword, sort_by, sort_order
|
468 | 487 | load_info += "</div>"
|
469 | 488 | return filenames, gr.update(value=page_index, label=f"Page Index ({page_index}/{max_page_index})"), image_list, "", "", "", visible_num, load_info
|
470 | 489 |
|
471 |
| - |
472 |
| - |
473 | 490 | def get_current_file(tabname_box, num, page_index, filenames):
|
474 | 491 | file = filenames[int(num) + int((page_index - 1) * num_of_imgs_per_page)]
|
475 | 492 | return file
|
476 | 493 |
|
477 |
| -def show_image_info(tabname_box, num, page_index, filenames): |
478 |
| - file = filenames[int(num) + int((page_index - 1) * num_of_imgs_per_page)] |
479 |
| - tm = "<div style='color:#999' align='right'>" + time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(os.path.getmtime(file))) + "</div>" |
480 |
| - return file, tm, num, file, "" |
| 494 | +def show_image_info(tabname_box, num, page_index, filenames, turn_page_switch): |
| 495 | + logger.debug(f"tabname_box, num, page_index, len(filenames), num_of_imgs_per_page: {tabname_box}, {num}, {page_index}, {len(filenames)}, {num_of_imgs_per_page}") |
| 496 | + if len(filenames) == 0: |
| 497 | + # This should only happen if webui was stopped and started again and the user clicks on one of the still displayed images. |
| 498 | + # The state with the filenames will be empty then. In that case we return None to prevent further errors and force a page refresh. |
| 499 | + turn_page_switch = -turn_page_switch |
| 500 | + file = None |
| 501 | + tm = None |
| 502 | + else: |
| 503 | + file = filenames[int(num) + int((page_index - 1) * num_of_imgs_per_page)] |
| 504 | + tm = "<div style='color:#999' align='right'>" + time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(os.path.getmtime(file))) + "</div>" |
| 505 | + return file, tm, num, file, turn_page_switch |
481 | 506 |
|
482 | 507 | def show_next_image_info(tabname_box, num, page_index, filenames, auto_next):
|
483 | 508 | file = filenames[int(num) + int((page_index - 1) * num_of_imgs_per_page)]
|
@@ -714,7 +739,7 @@ def create_tab(tabname):
|
714 | 739 | )
|
715 | 740 |
|
716 | 741 | # other functions
|
717 |
| - set_index.click(show_image_info, _js="image_browser_get_current_img", inputs=[tabname_box, image_index, page_index, filenames], outputs=[img_file_name, img_file_time, image_index, hidden]) |
| 742 | + set_index.click(show_image_info, _js="image_browser_get_current_img", inputs=[tabname_box, image_index, page_index, filenames, turn_page_switch], outputs=[img_file_name, img_file_time, image_index, hidden, turn_page_switch]) |
718 | 743 | set_index.click(fn=lambda:(gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)), inputs=None, outputs=[delete_panel, button_panel, ranking])
|
719 | 744 | img_file_name.change(fn=lambda : "", inputs=None, outputs=[collected_warning])
|
720 | 745 | img_file_name.change(get_ranking, inputs=img_file_name, outputs=ranking)
|
|
0 commit comments