Spaces:
Sleeping
Sleeping
| """ | |
| Quick Test Script - Direct Pipeline Usage Without Server | |
| For development testing, no OpenAI API Key required | |
| " | |
| import sys | |
| import os | |
| # Add Backend to path | |
| sys.path.append(os.path.join(os.path.dirname(__file__), 'Backend')) | |
| from pipeline.pain_assessment_pipeline import PainAssessmentPipeline | |
| def test_quick(): | |
| """Quick test using mocked LLM output""" | |
| print("="*70) | |
| print("🧪 Quick Test (No OpenAI API Required)") | |
| print("="*70) | |
| # Initialize pipeline | |
| pipeline = PainAssessmentPipeline(verbose=True) | |
| # Test cases | |
| test_cases = [ | |
| { | |
| "name": "中文 - 慢性神经病理性疼痛", | |
| "text": "我有火辣辣的疼痛,已经好几个月了,腰部很难受", | |
| "llm_entities": { | |
| "pain_descriptors": ["火辣辣的疼痛"], | |
| "location": "腰部", | |
| "duration_phrase": "好几个月", | |
| "emotion_keywords": ["难受"], | |
| "functional_impact": None, | |
| "intensity": "Moderate to severe" | |
| } | |
| }, | |
| { | |
| "name": "韩语 - 刺痛", | |
| "text": "허리가 따끔거리다", | |
| "llm_entities": { | |
| "pain_descriptors": ["따끔거리다"], | |
| "location": "허리", | |
| "duration_phrase": None, | |
| "emotion_keywords": [], | |
| "functional_impact": None, | |
| "intensity": "Moderate" | |
| } | |
| }, | |
| { | |
| "name": "西班牙语 - 急性疼痛", | |
| "text": "Tengo un dolor agudo y punzante en la espalda", | |
| "llm_entities": { | |
| "pain_descriptors": ["agudo", "punzante"], | |
| "location": "la espalda", | |
| "duration_phrase": None, | |
| "emotion_keywords": [], | |
| "functional_impact": None, | |
| "intensity": "Severe" | |
| } | |
| }, | |
| { | |
| "name": "苗族语 - 灼烧痛", | |
| "text": "Kuv mob Kub Heev heev", | |
| "llm_entities": { | |
| "pain_descriptors": ["Kub Heev"], | |
| "location": None, | |
| "duration_phrase": None, | |
| "emotion_keywords": [], | |
| "functional_impact": None, | |
| "intensity": "Severe" | |
| } | |
| } | |
| ] | |
| passed = 0 | |
| failed = 0 | |
| for test in test_cases: | |
| print("\n" + "="*70) | |
| print(f"Test: {test['name']}") | |
| print("-"*70) | |
| print(f"Input: {test['text']}") | |
| try: | |
| # Execute pipeline with mocked LLM output | |
| report = pipeline.execute( | |
| test['text'], | |
| test['llm_entities'] | |
| ) | |
| print(f"\n✅ Test Passed") | |
| print(f"\n📋 Analysis Results:") | |
| print(f" Pain Type: {report.structured_data.pain_type}") | |
| print(f" Location: {report.structured_data.location}") | |
| print(f" Temporal Pattern: {report.structured_data.temporal_pattern}") | |
| if report.ontology_mapping_trace: | |
| print(f"\n🔄 Ontology Mappings ({len(report.ontology_mapping_trace)} items):") | |
| for mapping in report.ontology_mapping_trace: | |
| lang = mapping.get('detected_language', '?') | |
| print(f" [{lang}] {mapping['original_term']} → " | |
| f"{mapping['mapped_english']} ({mapping.get('pain_type', 'N/A')})") | |
| if report.clinical_recommendations: | |
| print(f"\n💊 Clinical Recommendations ({len(report.clinical_recommendations)} items):") | |
| for i, rec in enumerate(report.clinical_recommendations, 1): | |
| print(f"\n {i}. {rec.recommendation[:80]}...") | |
| print(f" Rule: {rec.triggered_by_rule}") | |
| else: | |
| print(f"\n💊 Clinical Recommendations: Standard assessment") | |
| passed += 1 | |
| except Exception as e: | |
| print(f"\n❌ Test Failed: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| failed += 1 | |
| # Summary | |
| print("="*70) | |
| print("📊 Test Summary") | |
| print("="*70) | |
| print(f"Passed: {passed}/{passed+failed}") | |
| print(f"Failed: {failed}/{passed+failed}") | |
| if failed == 0: | |
| print("\n✅ All tests passed!") | |
| else: | |
| print(f"\n⚠️ {failed} test(s) failed") | |
| return failed == 0 | |
| def show_system_info(): | |
| """Display system information""" | |
| print("\n" + "="*70) | |
| print("📊 System Information") | |
| print("="*70) | |
| pipeline = PainAssessmentPipeline(verbose=False) | |
| info = pipeline.get_pipeline_info() | |
| print(f"Pipeline Version: {info['pipeline_version']}") | |
| print(f"Architecture: {info['architecture']}") | |
| print(f"Supported Languages: {', '.join(info['supported_languages'])}") | |
| print(f"\nOntology Coverage:") | |
| print(f" Total: {info['ontology_coverage']['total_descriptors']} terms") | |
| print(f" Chinese: {info['ontology_coverage']['chinese_terms']}") | |
| print(f" Korean: {info['ontology_coverage']['korean_terms']}") | |
| print(f" Spanish: {info['ontology_coverage']['spanish_terms']}") | |
| print(f" Hmong: {info['ontology_coverage']['hmong_terms']}") | |
| print(f"\nClinical Rules: {info['rule_count']}") | |
| print(f" {', '.join(info['active_rules'])}") | |
| if __name__ == "__main__": | |
| print("="*70) | |
| print("🚀 Multilingual Pain Assessment - Quick Test") | |
| print("="*70) | |
| print("\n💡 Note: This test does not require OpenAI API Key") | |
| print(" Uses predefined LLM output to simulate complete pipeline") | |
| # Display system information | |
| show_system_info() | |
| # Run tests | |
| success = test_quick() | |
| if success: | |
| print("\n" + "="*70) | |
| print("🎉 System working properly!") | |
| print("="*70) | |
| print("\nNext Steps:") | |
| print(" 1. Set OPENAI_API_KEY environment variable") | |
| print(" 2. Start server: python Backend/main.py") | |
| print(" 3. Test full API: python test_api.py") | |
| print("\nDetailed docs: HOW_TO_START.md") | |
| sys.exit(0 if success else 1) | |