Create quick_fix.py
Browse files- quick_fix.py +95 -0
quick_fix.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
"""
|
3 |
+
Quick fix script for AI Web Scraper dependency issues
|
4 |
+
Run this if you encounter import errors or missing modules
|
5 |
+
"""
|
6 |
+
|
7 |
+
import subprocess
|
8 |
+
import sys
|
9 |
+
import importlib
|
10 |
+
|
11 |
+
def install_package(package):
|
12 |
+
"""Install a package using pip"""
|
13 |
+
try:
|
14 |
+
print(f"π¦ Installing {package}...")
|
15 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
|
16 |
+
print(f"β
{package} installed successfully")
|
17 |
+
return True
|
18 |
+
except subprocess.CalledProcessError as e:
|
19 |
+
print(f"β Failed to install {package}: {e}")
|
20 |
+
return False
|
21 |
+
|
22 |
+
def check_import(module_name, package_name=None):
|
23 |
+
"""Check if a module can be imported"""
|
24 |
+
try:
|
25 |
+
importlib.import_module(module_name)
|
26 |
+
print(f"β
{module_name} is available")
|
27 |
+
return True
|
28 |
+
except ImportError:
|
29 |
+
print(f"β {module_name} is not available")
|
30 |
+
if package_name:
|
31 |
+
return install_package(package_name)
|
32 |
+
return False
|
33 |
+
|
34 |
+
def main():
|
35 |
+
print("π§ AI Web Scraper - Dependency Fix Tool")
|
36 |
+
print("="*50)
|
37 |
+
|
38 |
+
# Essential packages to check/install
|
39 |
+
packages = [
|
40 |
+
("gradio", "gradio>=4.0.0"),
|
41 |
+
("requests", "requests>=2.31.0"),
|
42 |
+
("bs4", "beautifulsoup4>=4.12.0"),
|
43 |
+
("pandas", "pandas>=2.0.0"),
|
44 |
+
("urllib.parse", None), # Built-in, should always work
|
45 |
+
]
|
46 |
+
|
47 |
+
# Optional packages
|
48 |
+
optional_packages = [
|
49 |
+
("transformers", "transformers>=4.30.0"),
|
50 |
+
("torch", "torch>=2.0.0"),
|
51 |
+
("nltk", "nltk>=3.8.0"),
|
52 |
+
]
|
53 |
+
|
54 |
+
print("\nπ Checking essential packages...")
|
55 |
+
essential_failed = []
|
56 |
+
for module, package in packages:
|
57 |
+
if not check_import(module, package):
|
58 |
+
essential_failed.append(module)
|
59 |
+
|
60 |
+
print("\nπ Checking optional packages...")
|
61 |
+
optional_failed = []
|
62 |
+
for module, package in optional_packages:
|
63 |
+
if not check_import(module, package):
|
64 |
+
optional_failed.append(module)
|
65 |
+
|
66 |
+
print("\n" + "="*50)
|
67 |
+
print("π Summary")
|
68 |
+
print("="*50)
|
69 |
+
|
70 |
+
if essential_failed:
|
71 |
+
print(f"β Critical packages missing: {', '.join(essential_failed)}")
|
72 |
+
print("π§ Try running: pip install gradio requests beautifulsoup4 pandas")
|
73 |
+
else:
|
74 |
+
print("β
All essential packages are available!")
|
75 |
+
|
76 |
+
if optional_failed:
|
77 |
+
print(f"β οΈ Optional packages missing: {', '.join(optional_failed)}")
|
78 |
+
print("π‘ AI features may be limited, but basic functionality will work")
|
79 |
+
print("π§ To enable AI features, run: pip install transformers torch nltk")
|
80 |
+
else:
|
81 |
+
print("β
All optional packages are available!")
|
82 |
+
|
83 |
+
# Download NLTK data if available
|
84 |
+
try:
|
85 |
+
import nltk
|
86 |
+
print("\nπ Downloading NLTK data...")
|
87 |
+
nltk.download('punkt', quiet=True)
|
88 |
+
print("β
NLTK data downloaded")
|
89 |
+
except:
|
90 |
+
print("β οΈ NLTK not available, skipping data download")
|
91 |
+
|
92 |
+
print("\nπ Fix complete! Try running your app now.")
|
93 |
+
|
94 |
+
if __name__ == "__main__":
|
95 |
+
main()
|