Add auto-installation of required packages in ui.py

pull/727/head
harshalmore31 3 months ago committed by GitHub
parent 3c074aee4e
commit ae119150c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,3 +1,32 @@
import subprocess
import sys
import importlib
# Package installation function
def install_and_import_packages():
"""Auto-install and import required packages."""
required_packages = {
'gradio': 'gradio',
'litellm': 'litellm',
'python-dotenv': 'dotenv',
'swarms': 'swarms'
}
for package, import_name in required_packages.items():
try:
importlib.import_module(import_name)
print(f"{package} already installed")
except ImportError:
print(f"Installing {package}...")
try:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
print(f"{package} installed successfully")
except subprocess.CalledProcessError:
print(f"✗ Failed to install {package}")
# Run the installation function first
install_and_import_packages()
import os
from dotenv import load_dotenv
from typing import AsyncGenerator, List, Dict, Any, Tuple, Optional
@ -16,6 +45,7 @@ from dotenv import set_key, find_dotenv
import logging # Import the logging module
import litellm # Import litellm exception
# Initialize logger
load_dotenv()
@ -1852,6 +1882,6 @@ def create_app():
return ui.build()
if __name__ == "__main__":
app = create_app()
app.launch()
# if __name__ == "__main__":
# app = create_app()
# app.launch()
Loading…
Cancel
Save