-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_example.py
23 lines (18 loc) · 1.09 KB
/
client_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import requests
import clip_serve_models as models
if __name__ == "__main__":
# Example usage of the ClipServe API
API_URL = "http://localhost:8000"
# Embed text
text_request = models.TextRequest(text="A photo of a cat")
response = requests.post(f"{API_URL}/embed-text", data=text_request.to_json())
response_obj = models.TextEmbeddingResponse(**response.json())
# Embed images
sample_image = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEAAQMAAABmvDolAAAAA1BMVEW10NBjBBbqAAAAH0lEQVRoge3BAQ0AAADCoPdPbQ43oAAAAAAAAAAAvg0hAAABmmDh1QAAAABJRU5ErkJggg=="
image_request = models.ImageRequest(image_b64=sample_image)
response = requests.post(f"{API_URL}/embed-images", data=image_request.to_json())
response_obj = models.ImageEmbeddingResponse(**response.json())
# Zero-shot classification
zsc_request = models.ZeroShotClassificationRequest(labels=["dog", "cat"], images_b64=[sample_image])
response = requests.post(f"{API_URL}/zero-shot-classification", data=zsc_request.to_json())
response_obj = models.ClassificationResponse(**response.json())