File size: 2,628 Bytes
52a0fe9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Quick API test script for Alldocex."""
import requests
import time
import json

BASE_URL = "http://localhost:8000"

# Upload the test document
print("Uploading test_document.docx...")
with open("test_document.docx", "rb") as f:
    res = requests.post(
        f"{BASE_URL}/api/upload",
        files={"file": ("test_document.docx", f, "application/vnd.openxmlformats-officedocument.wordprocessingml.document")}
    )

data = res.json()
print(f"Upload response: {data['status']} - File ID: {data['file_id']}")
task_id = data["file_id"]

# Poll for results
print("Waiting for processing...")
for i in range(30):
    time.sleep(1)
    res = requests.get(f"{BASE_URL}/api/status/{task_id}")
    result = res.json()
    status = result["status"]
    print(f"  Poll {i+1}: {status}")
    if status in ("completed", "error"):
        break

print(f"\n{'='*50}")
print(f"STATUS: {result['status']}")
print(f"Processing time: {round(result.get('processing_time_ms', 0), 1)} ms")
print(f"{'='*50}")

# Extraction
if result.get("extraction"):
    ext = result["extraction"]
    print(f"\n--- EXTRACTION ---")
    print(f"Success: {ext['success']}")
    print(f"Word count: {ext['metadata']['word_count']}")
    print(f"Char count: {ext['metadata']['character_count']}")
    print(f"File type: {ext['metadata']['file_type']}")
    print(f"First 300 chars:\n{ext['raw_text'][:300]}")

# Summary
if result.get("summary"):
    s = result["summary"]
    print(f"\n--- SUMMARY ---")
    print(f"Algorithm: {s['algorithm']}")
    print(f"Original length: {s['original_length']}")
    print(f"Summary length: {s['summary_length']}")
    print(f"Compression: {round((1 - s['compression_ratio']) * 100, 1)}%")
    print(f"Summary:\n{s['summary'][:500]}")

# Entities
if result.get("entities"):
    e = result["entities"]
    print(f"\n--- ENTITIES ---")
    print(f"Total entities: {e['total_entities']}")
    print(f"Categories: {json.dumps(e['entity_counts'], indent=2)}")
    for ent in e["entities"][:20]:
        print(f"  [{ent['label']:8s}] {ent['text']} (x{ent['count']})")

# Sentiment
if result.get("sentiment"):
    sent = result["sentiment"]
    print(f"\n--- SENTIMENT ---")
    print(f"Label: {sent['overall_label']}")
    print(f"Compound: {sent['overall_compound']}")
    print(f"Positive: {sent['overall_positive']}")
    print(f"Negative: {sent['overall_negative']}")
    print(f"Neutral: {sent['overall_neutral']}")
    print(f"Sentence breakdowns: {len(sent['sentence_breakdown'])}")
    for sb in sent["sentence_breakdown"][:5]:
        print(f"  [{sb['label']:15s}] {sb['text'][:80]}...")

print("\n=== TEST COMPLETE ===")