import asyncio import httpx import os import sys import io from PIL import Image # Create a small test image in memory def get_test_image_bytes(): img = Image.new("RGB", (200, 100), color=(255, 255, 255)) buf = io.BytesIO() img.save(buf, format="JPEG") return buf.getvalue() async def test_api(): url = "http://127.0.0.1:8000/api/ai/ocr" # Use the in-memory image image_bytes = get_test_image_bytes() files = { "file": ("test_image.jpg", image_bytes, "image/jpeg") } async with httpx.AsyncClient(timeout=30.0) as client: try: data={"document_type": "id_card"}, files={"file": ("dummy.jpg", f, "image/jpeg")} ) print(f"Status Code: {response.status_code}") print(f"Response Body: {response.text}") except Exception as e: print(f"Request failed: {e}") if __name__ == "__main__": asyncio.run(test_api()) sys.stdout.flush()