Spaces:
Running
Running
burtenshaw
commited on
Commit
·
76563a1
1
Parent(s):
b78b2a9
add backslide and decktape installs
Browse files- app/app.py +79 -0
app/app.py
CHANGED
@@ -757,6 +757,61 @@ def cleanup_session(temp_dir):
|
|
757 |
return "No valid temporary directory found to clean."
|
758 |
|
759 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
760 |
# --- Gradio Interface ---
|
761 |
|
762 |
# Load custom CSS
|
@@ -1102,4 +1157,28 @@ with gr.Blocks(
|
|
1102 |
if __name__ == "__main__":
|
1103 |
os.makedirs(CACHE_DIR, exist_ok=True)
|
1104 |
os.makedirs(URL_CACHE_DIR, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1105 |
demo.queue().launch(debug=True)
|
|
|
757 |
return "No valid temporary directory found to clean."
|
758 |
|
759 |
|
760 |
+
# --- Dependency Check and Installation --- (Added)
|
761 |
+
|
762 |
+
|
763 |
+
def check_and_install_npm_dependency(command_name, package_name, install_instructions):
|
764 |
+
"""Checks if a command exists, tries to install via npm if not."""
|
765 |
+
if shutil.which(command_name):
|
766 |
+
logger.info(f"Command '{command_name}' found.")
|
767 |
+
return True
|
768 |
+
else:
|
769 |
+
logger.warning(
|
770 |
+
f"Command '{command_name}' not found. Attempting to install '{package_name}' globally via npm..."
|
771 |
+
)
|
772 |
+
npm_command = ["npm", "install", "-g", package_name]
|
773 |
+
try:
|
774 |
+
result = subprocess.run(
|
775 |
+
npm_command, check=True, capture_output=True, text=True, timeout=300
|
776 |
+
)
|
777 |
+
logger.info(f"Successfully installed '{package_name}'.")
|
778 |
+
logger.debug(f"npm stdout:\n{result.stdout}")
|
779 |
+
logger.debug(f"npm stderr:\n{result.stderr}")
|
780 |
+
# Verify again after install attempt
|
781 |
+
if shutil.which(command_name):
|
782 |
+
logger.info(f"Command '{command_name}' is now available.")
|
783 |
+
return True
|
784 |
+
else:
|
785 |
+
logger.error(
|
786 |
+
f"Installation of '{package_name}' reported success, but command '{command_name}' still not found. Check npm logs and PATH."
|
787 |
+
)
|
788 |
+
return False
|
789 |
+
except FileNotFoundError:
|
790 |
+
logger.error(
|
791 |
+
f"`npm` command not found. Cannot install '{package_name}'. {install_instructions}"
|
792 |
+
)
|
793 |
+
return False
|
794 |
+
except subprocess.CalledProcessError as e:
|
795 |
+
logger.error(
|
796 |
+
f"Failed to install '{package_name}' (return code {e.returncode})."
|
797 |
+
)
|
798 |
+
logger.error(f"npm stdout:\n{e.stdout}")
|
799 |
+
logger.error(f"npm stderr:\n{e.stderr}")
|
800 |
+
logger.error(
|
801 |
+
"Installation might require administrator privileges (e.g., run with 'sudo')."
|
802 |
+
)
|
803 |
+
return False
|
804 |
+
except subprocess.TimeoutExpired:
|
805 |
+
logger.error(f"Installation of '{package_name}' timed out.")
|
806 |
+
return False
|
807 |
+
except Exception as e:
|
808 |
+
logger.error(
|
809 |
+
f"An unexpected error occurred during '{package_name}' installation: {e}",
|
810 |
+
exc_info=True,
|
811 |
+
)
|
812 |
+
return False
|
813 |
+
|
814 |
+
|
815 |
# --- Gradio Interface ---
|
816 |
|
817 |
# Load custom CSS
|
|
|
1157 |
if __name__ == "__main__":
|
1158 |
os.makedirs(CACHE_DIR, exist_ok=True)
|
1159 |
os.makedirs(URL_CACHE_DIR, exist_ok=True)
|
1160 |
+
|
1161 |
+
# --- Check/Install Dependencies --- (Added)
|
1162 |
+
logger.info("Checking for external dependencies...")
|
1163 |
+
backslide_ok = check_and_install_npm_dependency(
|
1164 |
+
"bs",
|
1165 |
+
"backslide",
|
1166 |
+
"Please install Node.js/npm (https://nodejs.org/) and then run 'npm install -g backslide'",
|
1167 |
+
)
|
1168 |
+
decktape_ok = check_and_install_npm_dependency(
|
1169 |
+
"decktape",
|
1170 |
+
"decktape",
|
1171 |
+
"Please install Node.js/npm (https://nodejs.org/) and then run 'npm install -g decktape'",
|
1172 |
+
)
|
1173 |
+
|
1174 |
+
if not backslide_ok:
|
1175 |
+
gr.Warning(
|
1176 |
+
"Backslide (bs) command check/install failed. PDF generation might fail. Check logs."
|
1177 |
+
)
|
1178 |
+
if not decktape_ok:
|
1179 |
+
gr.Warning(
|
1180 |
+
"Decktape command check/install failed. PDF generation might fail. Check logs."
|
1181 |
+
)
|
1182 |
+
# --- End Dependency Check ---
|
1183 |
+
|
1184 |
demo.queue().launch(debug=True)
|