AI_Powered_Web_Scraper / quick_fix.py
MagicMeWizard's picture
Create quick_fix.py
e5de17a verified
#!/usr/bin/env python3
"""
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)
# Essential packages to check/install
packages = [
("gradio", "gradio>=4.0.0"),
("requests", "requests>=2.31.0"),
("bs4", "beautifulsoup4>=4.12.0"),
("pandas", "pandas>=2.0.0"),
("urllib.parse", None), # Built-in, should always work
]
# Optional packages
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!")
# Download NLTK data if 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()