Spaces:
Sleeping
Sleeping
File size: 6,252 Bytes
acaf471 | 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 | """
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)
|