这个目录包含了调用Image Search API的客户端示例代码。
image_search_client.py- 完整的客户端类,包含所有API调用功能simple_client.py- 简单的API调用示例README.md- 本说明文件
pip install requests首先确保API服务正在运行:
cd ../project
python run.pypython image_search_client.pypython simple_client.pyimport requests
url = "http://localhost:5000/api/search"
files = [
('images', open('image1.jpg', 'rb')),
('images', open('image2.png', 'rb')),
]
data = {
'text': 'a cute cat',
'top_k': 3
}
response = requests.post(url, files=files, data=data)
result = response.json()import requests
url = "http://localhost:5000/api/search/url"
data = {
"text": "beautiful landscape",
"image_urls": [
"https://example.com/image1.jpg",
"https://example.com/image2.png"
],
"top_k": 5
}
response = requests.post(url, json=data)
result = response.json()import requests
response = requests.get("http://localhost:5000/api/health")
health = response.json()- 确保API服务正在运行(默认端口5000)
- 文件搜索需要提供实际存在的图片文件路径
- URL搜索需要提供可访问的图片URL
- 所有API调用都应该包含适当的错误处理