File size: 3,040 Bytes
e5de17a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/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()