File size: 1,094 Bytes
1f5e8ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import os
from docx import Document

# Backend URL
URL = "https://omgy-vero-ps.hf.space/enhance"

def test_docx_upload():
    print("Testing DOCX upload...")
    # Create a dummy docx
    doc = Document()
    doc.add_paragraph("This is a test document with enough text to pass the validation check.")
    doc.add_paragraph("It has multiple paragraphs to ensure proper extraction.")
    doc.save("test.docx")
    
    try:
        files = {'file': open('test.docx', 'rb')}
        params = {'prompt': 'Enhance this', 'doc_type': 'auto'}
        
        response = requests.post(URL, files=files, params=params)
        
        print(f"Status Code: {response.status_code}")
        if response.status_code != 200:
            print(f"Response Body: {response.text}")
        else:
            print("Success! Received enhanced file.")
            
    except Exception as e:
        print(f"Error: {str(e)}")
    finally:
        files['file'].close()
        if os.path.exists("test.docx"):
            os.remove("test.docx")

if __name__ == "__main__":
    test_docx_upload()