""" 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.")