Download test_upload.py from YADUUG/eng2pun: direct link, hf CLI and curl.
- Browser
- Download file 982 Bytes
-
https://huggingface.co/spaces/YADUUG/eng2pun/resolve/main/test_upload.py
- Command line
-
hf download hf://spaces/YADUUG/eng2pun/test_upload.py
-
curl -L -o test_upload.py https://huggingface.co/spaces/YADUUG/eng2pun/resolve/main/test_upload.py
982 Bytes
| import requests | |
| import json | |
| print("Creating dummy file...") | |
| with open("test.txt", "w") as f: | |
| f.write("Hello world!\nThis is a test document.\nTranslating this should return Punjabi.") | |
| url = "http://localhost:8000/translate-stream" | |
| # We need an Authorization header if we mimic the frontend. The server allows skipping if we mock the token or disable it. | |
| # Looking at app.py: mock_tokens = {"test-token-123": "user-1"} -> we can use "Bearer test-token-123" | |
| headers = {"Authorization": "Bearer test-token-123"} | |
| files = {"file": ("test.txt", open("test.txt", "rb"), "text/plain")} | |
| data = {"source_lang": "en", "dest_lang": "pa"} | |
| print("Sending request to /translate-stream...") | |
| try: | |
| response = requests.post(url, headers=headers, files=files, data=data, stream=True) | |
| print(f"Status: {response.status_code}") | |
| for line in response.iter_lines(): | |
| if line: | |
| print(json.loads(line.decode('utf-8'))) | |
| except Exception as e: | |
| print(f"Error: {e}") | |