Spaces:
Sleeping
Sleeping
| import requests | |
| import json | |
| # Define the test API endpoint - adjust if your server runs on a different port | |
| API_ENDPOINT = "http://localhost:5000/api/debug_extract" | |
| # Test case 1: John Doe's order (from your example) | |
| test_case_1 = """John Doe placed an order for a set of hardcover books weighing approximately 3 kg. | |
| The package is scheduled for pickup from Downtown Bookstore, New York and will be delivered to Maple Street, | |
| Los Angeles. The requested shipping date is May 5, 2025, and the payment method selected is credit card. | |
| The package dimensions are estimated to be 30 cm x 20 cm x 15 cm, ensuring proper handling during transit. | |
| John has also provided special instructions, requesting extra padding and waterproof wrapping to protect the | |
| books from any potential damage.""" | |
| # Test case 2: Different format of providing information | |
| test_case_2 = """I need to ship a laptop from Apple Store in San Francisco to my office at 123 Business Avenue, Chicago. | |
| It weighs about 2.5kg and I'd like it delivered by May 10th. I'll pay with PayPal. | |
| The box is 40x30x10cm. Please handle with care as it's fragile equipment.""" | |
| # Test case 3: Minimal information | |
| test_case_3 = """Need to ship documents from Boston to New York, about 1kg, shipping tomorrow, paying cash.""" | |
| # Function to make API request and print results | |
| def test_extraction(text, case_num): | |
| print(f"\n--- TEST CASE {case_num} ---") | |
| print(f"Input text:\n{text}\n") | |
| try: | |
| response = requests.post(API_ENDPOINT, json={"text": text}) | |
| if response.status_code == 200: | |
| result = response.json() | |
| # Print extracted details | |
| print("Extracted details:") | |
| for field, value in result["extracted_details"].items(): | |
| if value: | |
| print(f"- {field}: {value}") | |
| # Print missing fields | |
| if result["missing_fields"]: | |
| print("\nMissing fields:") | |
| for field in result["missing_fields"]: | |
| print(f"- {field}") | |
| else: | |
| print(f"Error: {response.status_code}") | |
| print(response.text) | |
| except Exception as e: | |
| print(f"Error making request: {e}") | |
| # Run the tests | |
| if __name__ == "__main__": | |
| print("TESTING ORDER EXTRACTION FUNCTION") | |
| print("=================================") | |
| # Test each case | |
| test_extraction(test_case_1, 1) | |
| test_extraction(test_case_2, 2) | |
| test_extraction(test_case_3, 3) | |
| print("\nTests completed. Make sure your Flask server is running at http://localhost:5000") | |
| print("If any fields are missing that should be extracted, adjust the regex patterns in backend.py") |