Skip to content

Commit

Permalink
Improving proper uninstallation
Browse files Browse the repository at this point in the history
Now if you disable extesion or disable all of them, gradio will automaticly reinstall
  • Loading branch information
daswer123 committed Sep 6, 2023
1 parent 96125f5 commit efba3a9
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions detect_extension.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import json
import launch

# Path to Python executable
Expand All @@ -13,12 +14,26 @@

# Path to the 'requirements.txt' file
requirements_path = os.path.join(sys.path[2], "requirements.txt")
config_path = os.path.join(sys.path[2], "config.json")

# Read the version of 'gradio' from 'requirements.txt'
with open(requirements_path, "r") as file:
lines = file.readlines()
gradio_line = next((line for line in lines if line.startswith("gradio")), None)
gradio_version = gradio_line.split("==")[1].strip() if gradio_line else None
if os.path.isfile(requirements_path):
with open(requirements_path, "r") as file:
lines = file.readlines()
gradio_line = next((line for line in lines if line.startswith("gradio")), None)
gradio_version = gradio_line.split("==")[1].strip() if gradio_line else None

# Check if config.json exists
if os.path.isfile(config_path):
with open(config_path, 'r') as config_file:
config = json.load(config_file)
# Check if "canvas-zoom" is in the list of disabled_extensions
if "canvas-zoom" in config.get('disabled_extensions', []):
launch.run(f'"{python}" -m pip install --force-reinstall --no-deps gradio=={gradio_version}', desc=f"Uninstalling modified gradio for canvas-zoom", errdesc=f"Couldn't uninstall canvas-zoom", live=False)

# Check if disable_all_extensions is not "none"
if config.get('disable_all_extensions', 'none') == 'all':
launch.run(f'"{python}" -m pip install --force-reinstall --no-deps gradio=={gradio_version}', desc=f"Uninstalling modified gradio for canvas-zoom", errdesc=f"Couldn't uninstall canvas-zoom", live=False)

# Check if the folder exists
if not os.path.exists(canvasZoomPath) and gradio_version is not None:
Expand Down

0 comments on commit efba3a9

Please sign in to comment.