Fixed a problem with gradio 4+

testing_refactoring
Danil Boldyrev 2024-08-13 14:59:48 +03:00
parent 63ca81ef1d
commit 6d17d9ff12
2 changed files with 53 additions and 46 deletions

View File

@ -2,6 +2,16 @@
An extension of [stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui) An extension of [stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui)
## ⚠️ Important Notice
With Forge's transition to Gradio version 4+, this extension is no longer functional. This change is likely to affect AUTO1111 in the future as well.
However, don't despair! Canvas Zoom is likely to take on a new form. The original concept of the extension was entirely based on Gradio 3 and solving its issues, which is why the current version is incompatible with Gradio 4+.
Once Gradio 4+ is firmly established and becomes the standard, I plan to start developing a new extension project. This new project will make working with the editor even more convenient and will transfer the main beloved features from the current Canvas Zoom.
## About
Adds the ability to zoom into Inpaint, Sketch, and Inpaint Sketch. Adds the ability to zoom into Inpaint, Sketch, and Inpaint Sketch.
**The extension supports webui version [1.1](https://github.com/AUTOMATIC1111/stable-diffusion-webui/releases/tag/v1.1.0), [1.2](https://github.com/AUTOMATIC1111/stable-diffusion-webui/releases/tag/v1.2.0),[1.3](https://github.com/AUTOMATIC1111/stable-diffusion-webui/releases/tag/v1.3.0)** **The extension supports webui version [1.1](https://github.com/AUTOMATIC1111/stable-diffusion-webui/releases/tag/v1.1.0), [1.2](https://github.com/AUTOMATIC1111/stable-diffusion-webui/releases/tag/v1.2.0),[1.3](https://github.com/AUTOMATIC1111/stable-diffusion-webui/releases/tag/v1.3.0)**

View File

@ -4,58 +4,55 @@ import shutil
import gradio import gradio
# Get the paths # Get the paths
module_path = os.path.join(sys.path[1],"scripts") module_path = os.path.join(sys.path[1], "scripts")
detect_module_path = os.path.join(sys.path[0], "detect_extension.py") # assuming the script is in the current directory detect_module_path = os.path.join(sys.path[0], "detect_extension.py")
# Form the destination path
destination_path = os.path.join(module_path, "detect_extension.py") destination_path = os.path.join(module_path, "detect_extension.py")
# Check if the source file exists and is a file (not a directory), # Copy the file if needed
# and if the file doesn't already exist at the destination,
# and if the module path is a valid directory
if os.path.isfile(detect_module_path) and not os.path.isfile(destination_path) and os.path.isdir(module_path): if os.path.isfile(detect_module_path) and not os.path.isfile(destination_path) and os.path.isdir(module_path):
# Copy the file
shutil.copyfile(detect_module_path, destination_path) shutil.copyfile(detect_module_path, destination_path)
# Check gradio version
# Check the version of the gradio, if it is less than 3.28.1 then cancel the installation
is_right_version = False
# Getting the Gradio version
current_version = gradio.__version__ current_version = gradio.__version__
major_version = int(current_version.split('.')[0])
# Converting versions into tuples of numbers for easy comparison if major_version >= 4:
def version_to_tuple(version_string): print("\n" + "!" * 50)
return tuple(map(int, version_string.split('.'))) print("WARNING: INCOMPATIBLE GRADIO VERSION DETECTED!")
print("!" * 50)
minimum_required_version = "3.28.1" print("\nThis version of Gradio (v{}) is not compatible with the extension.".format(current_version))
second_required_version = "3.32.0" print("Please disable the extension to avoid potential bugs and errors.")
print("The extension will not be installed.")
# Checking the Gradio version print("\n" + "!" * 50 + "\n")
if version_to_tuple(current_version) < version_to_tuple(minimum_required_version):
print("\nPlease update webui to the latest version for the canvas-zoom extension to work properly, supported versions from 1.1 \n")
elif version_to_tuple(current_version) <= version_to_tuple(second_required_version):
source_dir_name = 'v1_1_v1_5_1'
is_right_version = True
else: else:
source_dir_name = '' # Convert versions to tuples for comparison
is_right_version = True def version_to_tuple(version_string):
return tuple(map(int, version_string.split('.')))
if is_right_version: minimum_required_version = "3.28.1"
# Moving files with replacement second_required_version = "3.32.0"
canvasZoomPath = sys.path[0]
gradioPath = os.path.dirname(gradio.__file__) if version_to_tuple(current_version) < version_to_tuple(minimum_required_version):
print("\nPlease update webui to the latest version for the canvas-zoom extension to work properly. Supported versions are from 1.1 onwards.\n")
source_dir = os.path.join(canvasZoomPath,"dist", source_dir_name, 'templates', 'frontend') else:
if not os.path.exists(source_dir): is_right_version = True
canvasZoomPath = os.path.dirname(os.path.realpath(__file__)) source_dir_name = 'v1_1_v1_5_1' if version_to_tuple(current_version) <= version_to_tuple(second_required_version) else ''
source_dir = os.path.join(canvasZoomPath,"dist", source_dir_name, 'templates', 'frontend')
if is_right_version:
destination_dir = os.path.join(gradioPath, 'templates', 'frontend') # Move files with replacement
canvasZoomPath = sys.path[0]
# Deleting the existing "templates" folder in the gradio folder, if it exists gradioPath = os.path.dirname(gradio.__file__)
if os.path.exists(destination_dir):
shutil.rmtree(destination_dir) source_dir = os.path.join(canvasZoomPath, "dist", source_dir_name, 'templates', 'frontend')
if not os.path.exists(source_dir):
# Moving the "templates" folder from the canvasZoom folder to the gradio folder canvasZoomPath = os.path.dirname(os.path.realpath(__file__))
shutil.copytree(source_dir, destination_dir) source_dir = os.path.join(canvasZoomPath, "dist", source_dir_name, 'templates', 'frontend')
destination_dir = os.path.join(gradioPath, 'templates', 'frontend')
# Delete existing "templates" folder in the gradio folder, if it exists
if os.path.exists(destination_dir):
shutil.rmtree(destination_dir)
# Move the "templates" folder from the canvasZoom folder to the gradio folder
shutil.copytree(source_dir, destination_dir)