Spaces:
Sleeping
Sleeping
| #!/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() |