Spaces:
Sleeping
Sleeping
File size: 8,568 Bytes
5c9a55b | 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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | #!/usr/bin/env python3
"""
Production Diagnostics and Quick Fix for AI Text Humanizer
This script will identify exactly what's wrong and fix it
"""
import sys
import subprocess
import importlib
import os
def test_import(module_name, component=None):
"""Test if a module/component can be imported"""
try:
if component:
module = importlib.import_module(module_name)
getattr(module, component)
return True, "OK"
else:
importlib.import_module(module_name)
return True, "OK"
except ImportError as e:
return False, f"ImportError: {str(e)}"
except AttributeError as e:
return False, f"AttributeError: {str(e)}"
except Exception as e:
return False, f"Error: {str(e)}"
def run_pip_command(cmd):
"""Run pip command safely"""
try:
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, check=True)
return True, result.stdout
except subprocess.CalledProcessError as e:
return False, e.stderr
def main():
print("π§ AI TEXT HUMANIZER - PRODUCTION DIAGNOSTICS & FIX")
print("=" * 60)
print("This will diagnose and fix your advanced model issues\n")
# Test current imports
print("π CURRENT STATUS:")
print("-" * 20)
tests = [
("sentence_transformers", "SentenceTransformer"),
("transformers", "pipeline"),
("torch", None),
("sklearn", None),
("nltk", None),
("gradio", None)
]
results = {}
for module, component in tests:
success, message = test_import(module, component)
status = "β
WORKING" if success else "β FAILED"
print(f"{module}: {status}")
if not success:
print(f" Error: {message}")
results[module] = success
# Check specific model loading
print(f"\nπ€ TESTING MODEL LOADING:")
print("-" * 30)
if results.get('sentence_transformers'):
try:
print("π Testing sentence transformer model...")
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('all-MiniLM-L6-v2')
test_result = model.encode(["test"])
print("β
Sentence transformer: MODEL LOADED")
results['sentence_model'] = True
except Exception as e:
print(f"β Sentence transformer: MODEL FAILED - {e}")
results['sentence_model'] = False
else:
results['sentence_model'] = False
if results.get('transformers'):
try:
print("π Testing paraphrasing model...")
from transformers import pipeline
paraphraser = pipeline("text2text-generation", model="google/flan-t5-small")
test_result = paraphraser("test sentence", max_length=50)
print("β
Paraphrasing: MODEL LOADED")
results['paraphrase_model'] = True
except Exception as e:
print(f"β Paraphrasing: MODEL FAILED - {e}")
results['paraphrase_model'] = False
else:
results['paraphrase_model'] = False
# Analyze issues and provide fixes
print(f"\nπ― DIAGNOSIS & SOLUTIONS:")
print("-" * 30)
if not results['sentence_transformers']:
print("π¨ ISSUE: sentence-transformers not working")
print("π‘ SOLUTION:")
print(" pip uninstall -y sentence-transformers huggingface_hub")
print(" pip install huggingface_hub==0.17.3")
print(" pip install sentence-transformers==2.2.2")
print()
fix = input("π§ Apply this fix now? (y/n): ").lower().strip()
if fix == 'y':
print("π Applying sentence-transformers fix...")
success1, _ = run_pip_command("pip uninstall -y sentence-transformers huggingface_hub")
success2, _ = run_pip_command("pip install huggingface_hub==0.17.3")
success3, _ = run_pip_command("pip install sentence-transformers==2.2.2")
if success1 and success2 and success3:
print("β
Fix applied successfully!")
# Test again
success, message = test_import('sentence_transformers', 'SentenceTransformer')
if success:
print("β
sentence-transformers now working!")
results['sentence_transformers'] = True
else:
print(f"β Still not working: {message}")
else:
print("β Fix failed")
if not results['transformers']:
print("π¨ ISSUE: transformers not working")
print("π‘ SOLUTION:")
print(" pip install transformers==4.35.0 torch")
print()
fix = input("π§ Apply this fix now? (y/n): ").lower().strip()
if fix == 'y':
print("π Applying transformers fix...")
success1, _ = run_pip_command("pip install transformers==4.35.0")
success2, _ = run_pip_command("pip install torch")
if success1 and success2:
print("β
Fix applied successfully!")
success, message = test_import('transformers', 'pipeline')
if success:
print("β
transformers now working!")
results['transformers'] = True
else:
print(f"β Still not working: {message}")
else:
print("β Fix failed")
# Final test with our humanizer
print(f"\nπ§ͺ FINAL TEST:")
print("-" * 15)
try:
# Try importing our production version
if os.path.exists("text_humanizer_production.py"):
sys.path.insert(0, ".")
from text_humanizer_production import ProductionAITextHumanizer
print("π Creating production humanizer...")
humanizer = ProductionAITextHumanizer()
print("π Testing humanization...")
result = humanizer.humanize_text_production(
"Furthermore, it is important to note that these systems demonstrate significant capabilities.",
style="conversational",
intensity=0.8
)
print("β
PRODUCTION TEST SUCCESSFUL!")
print(f"Original: Furthermore, it is important to note that...")
print(f"Humanized: {result['humanized_text']}")
print(f"Quality Score: {result['quality_score']:.3f}")
# Check what features are working
working_features = sum([
results.get('sentence_model', False),
results.get('paraphrase_model', False),
True, # Basic features always work
])
if working_features >= 2:
print("π PRODUCTION READY!")
else:
print("β οΈ Limited features - but still functional")
else:
print("β text_humanizer_production.py not found")
except Exception as e:
print(f"β Final test failed: {e}")
# Summary and next steps
print(f"\nπ SUMMARY:")
print("-" * 12)
working_count = sum([
results.get('sentence_transformers', False),
results.get('transformers', False),
results.get('sentence_model', False),
results.get('paraphrase_model', False)
])
if working_count >= 3:
print("π ALL ADVANCED FEATURES WORKING!")
print("β
Your AI Text Humanizer is production-ready")
print("\nπ Next steps:")
print(" python text_humanizer_production.py # Test it")
print(" python fastapi_server.py # Run API")
print(" python gradio_app.py # Run web UI")
elif working_count >= 1:
print("β οΈ SOME FEATURES WORKING")
print("β
Your humanizer will work with reduced functionality")
print("\nπ To enable all features, run the fixes above")
else:
print("β CRITICAL ISSUES DETECTED")
print("π‘ Run this command for a fresh start:")
print(" python install_production.py")
print(f"\nπ Need help? Check:")
print(" - README.md for detailed setup")
print(" - DEPENDENCY_FIX.md for troubleshooting")
print(" - Run: python install_production.py")
if __name__ == "__main__":
main() |