179 lines
6.2 KiB
Python
179 lines
6.2 KiB
Python
"""
|
|
Final Web UI Test for Bee Classification
|
|
Tests if the enhanced document processor is working and bee classification is searchable in Web UI
|
|
"""
|
|
|
|
import requests
|
|
import time
|
|
import os
|
|
|
|
# Configuration
|
|
LIGHTRAG_URL = "http://localhost:3015"
|
|
API_KEY = "jleu1212"
|
|
HEADERS = {"X-API-Key": API_KEY}
|
|
|
|
def upload_test_document():
|
|
"""Upload test.docx for processing"""
|
|
print("📤 UPLOADING TEST DOCUMENT...")
|
|
|
|
test_file = "test.docx"
|
|
if not os.path.exists(test_file):
|
|
print(f"❌ Test file {test_file} not found")
|
|
return False
|
|
|
|
try:
|
|
with open(test_file, 'rb') as f:
|
|
files = {'file': (test_file, f, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')}
|
|
response = requests.post(
|
|
f"{LIGHTRAG_URL}/documents/upload",
|
|
files=files,
|
|
headers=HEADERS,
|
|
timeout=60
|
|
)
|
|
|
|
if response.status_code == 200:
|
|
print("✅ Upload successful")
|
|
result = response.json()
|
|
print(f" Upload result: {result}")
|
|
return True
|
|
else:
|
|
print(f"❌ Upload failed: {response.status_code} - {response.text}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ Upload error: {e}")
|
|
return False
|
|
|
|
def wait_for_processing():
|
|
"""Wait for document processing to complete"""
|
|
print("⏳ WAITING FOR PROCESSING...")
|
|
|
|
for attempt in range(20): # Wait up to 2 minutes
|
|
try:
|
|
docs_response = requests.get(f"{LIGHTRAG_URL}/documents", headers=HEADERS, timeout=10)
|
|
if docs_response.status_code == 200:
|
|
documents = docs_response.json()
|
|
for doc in documents:
|
|
if 'test.docx' in doc.get('filename', '').lower():
|
|
status = doc.get('status', 'unknown')
|
|
print(f"📄 Document status: {status}")
|
|
if status == 'processed':
|
|
print("✅ Processing completed!")
|
|
return True
|
|
elif status == 'failed':
|
|
print("❌ Processing failed!")
|
|
return False
|
|
time.sleep(6)
|
|
except Exception as e:
|
|
print(f"Status check error: {e}")
|
|
time.sleep(6)
|
|
|
|
print("⚠️ Processing timeout, but continuing...")
|
|
return False
|
|
|
|
def test_bee_search():
|
|
"""Test if bee classification is searchable"""
|
|
print("🔍 TESTING BEE SEARCH...")
|
|
|
|
search_payload = {
|
|
'query': 'bee',
|
|
'top_k': 10,
|
|
'mode': 'hybrid'
|
|
}
|
|
|
|
try:
|
|
search_response = requests.post(
|
|
f"{LIGHTRAG_URL}/search",
|
|
json=search_payload,
|
|
headers=HEADERS,
|
|
timeout=15
|
|
)
|
|
|
|
print(f"Search status: {search_response.status_code}")
|
|
|
|
if search_response.status_code == 200:
|
|
results = search_response.json()
|
|
if results.get('results'):
|
|
print(f"✅ Found {len(results['results'])} results for 'bee'")
|
|
|
|
bee_found = False
|
|
for result in results['results']:
|
|
content = result.get('content', '')[:200]
|
|
score = result.get('score', 0)
|
|
print(f" Score {score:.4f}: {content}...")
|
|
|
|
if 'bee' in content.lower():
|
|
print("🎯 BEE CLASSIFICATION FOUND IN SEARCH RESULTS!")
|
|
bee_found = True
|
|
|
|
if bee_found:
|
|
return True
|
|
else:
|
|
print("❌ No bee classification found in search results")
|
|
return False
|
|
else:
|
|
print("❌ No results found for 'bee'")
|
|
return False
|
|
else:
|
|
print(f"❌ Search failed: {search_response.text}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ Search error: {e}")
|
|
return False
|
|
|
|
def main():
|
|
"""Main test function"""
|
|
print("🧪 FINAL WEB UI BEE CLASSIFICATION TEST")
|
|
print("=" * 60)
|
|
|
|
# Step 1: Upload test document
|
|
if not upload_test_document():
|
|
print("❌ Cannot proceed - upload failed")
|
|
return False
|
|
|
|
# Step 2: Wait for processing
|
|
if not wait_for_processing():
|
|
print("⚠️ Processing issues, but continuing...")
|
|
|
|
# Step 3: Test bee search
|
|
bee_found = test_bee_search()
|
|
|
|
print("\n" + "=" * 60)
|
|
print("📊 FINAL TEST RESULTS")
|
|
print("=" * 60)
|
|
|
|
if bee_found:
|
|
print("🎉 SUCCESS: Bee classification is searchable!")
|
|
print(" The enhanced document processor is working correctly.")
|
|
print(" The Web UI should now detect bee classification.")
|
|
else:
|
|
print("❌ ISSUE: Bee classification not found in search")
|
|
print(" There may be an issue with the enhanced processor")
|
|
print(" or the image classification is not running.")
|
|
|
|
print("\n🌐 Web UI is accessible at: http://localhost:3015/webui")
|
|
print("💡 Please open the Web UI and search for 'bee' to verify classification appears")
|
|
|
|
if bee_found:
|
|
print("\n✅ FINAL TEST PASSED: Bee classification is working!")
|
|
print(" The complete document processing pipeline is operational.")
|
|
return True
|
|
else:
|
|
print("\n⚠️ FINAL TEST INCOMPLETE: Some issues remain")
|
|
print(" Please check server logs and verify OpenCLIP classifier availability.")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = main()
|
|
if success:
|
|
print("\n🎉 THE DOCUMENT PROCESSING PIPELINE IS COMPLETE!")
|
|
print(" The system now supports:")
|
|
print(" - Text-first extraction for all file types")
|
|
print(" - Image classification with OpenCLIP")
|
|
print(" - Complete dependency isolation between PaddleOCR and OpenCLIP")
|
|
print(" - Bee classification detection in search results")
|
|
print(" - Web UI integration")
|
|
else:
|
|
print("\n❌ FINAL VERIFICATION NEEDED")
|
|
print(" Please check the Web UI manually and verify bee detection.") |