|
|
|
""" |
|
Quick fix script for AI Web Scraper dependency issues |
|
Run this if you encounter import errors or missing modules |
|
""" |
|
|
|
import subprocess |
|
import sys |
|
import importlib |
|
|
|
def install_package(package): |
|
"""Install a package using pip""" |
|
try: |
|
print(f"π¦ Installing {package}...") |
|
subprocess.check_call([sys.executable, "-m", "pip", "install", package]) |
|
print(f"β
{package} installed successfully") |
|
return True |
|
except subprocess.CalledProcessError as e: |
|
print(f"β Failed to install {package}: {e}") |
|
return False |
|
|
|
def check_import(module_name, package_name=None): |
|
"""Check if a module can be imported""" |
|
try: |
|
importlib.import_module(module_name) |
|
print(f"β
{module_name} is available") |
|
return True |
|
except ImportError: |
|
print(f"β {module_name} is not available") |
|
if package_name: |
|
return install_package(package_name) |
|
return False |
|
|
|
def main(): |
|
print("π§ AI Web Scraper - Dependency Fix Tool") |
|
print("="*50) |
|
|
|
|
|
packages = [ |
|
("gradio", "gradio>=4.0.0"), |
|
("requests", "requests>=2.31.0"), |
|
("bs4", "beautifulsoup4>=4.12.0"), |
|
("pandas", "pandas>=2.0.0"), |
|
("urllib.parse", None), |
|
] |
|
|
|
|
|
optional_packages = [ |
|
("transformers", "transformers>=4.30.0"), |
|
("torch", "torch>=2.0.0"), |
|
("nltk", "nltk>=3.8.0"), |
|
] |
|
|
|
print("\nπ Checking essential packages...") |
|
essential_failed = [] |
|
for module, package in packages: |
|
if not check_import(module, package): |
|
essential_failed.append(module) |
|
|
|
print("\nπ Checking optional packages...") |
|
optional_failed = [] |
|
for module, package in optional_packages: |
|
if not check_import(module, package): |
|
optional_failed.append(module) |
|
|
|
print("\n" + "="*50) |
|
print("π Summary") |
|
print("="*50) |
|
|
|
if essential_failed: |
|
print(f"β Critical packages missing: {', '.join(essential_failed)}") |
|
print("π§ Try running: pip install gradio requests beautifulsoup4 pandas") |
|
else: |
|
print("β
All essential packages are available!") |
|
|
|
if optional_failed: |
|
print(f"β οΈ Optional packages missing: {', '.join(optional_failed)}") |
|
print("π‘ AI features may be limited, but basic functionality will work") |
|
print("π§ To enable AI features, run: pip install transformers torch nltk") |
|
else: |
|
print("β
All optional packages are available!") |
|
|
|
|
|
try: |
|
import nltk |
|
print("\nπ Downloading NLTK data...") |
|
nltk.download('punkt', quiet=True) |
|
print("β
NLTK data downloaded") |
|
except: |
|
print("β οΈ NLTK not available, skipping data download") |
|
|
|
print("\nπ Fix complete! Try running your app now.") |
|
|
|
if __name__ == "__main__": |
|
main() |