Spaces:
Runtime error
Runtime error
Upload apiTest.py
Browse files- apiTest.py +119 -0
apiTest.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
url = "https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/my-video-index?api-version=2023-05-01-preview"
|
| 4 |
+
headers = {
|
| 5 |
+
"Ocp-Apim-Subscription-Key": "c54eec632ae5413e8075e3f825727822",
|
| 6 |
+
"Content-Type": "application/json"
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
data = {
|
| 10 |
+
"metadataSchema": {
|
| 11 |
+
"fields": [
|
| 12 |
+
{
|
| 13 |
+
"name": "cameraId",
|
| 14 |
+
"searchable": False,
|
| 15 |
+
"filterable": True,
|
| 16 |
+
"type": "string"
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"name": "timestamp",
|
| 20 |
+
"searchable": False,
|
| 21 |
+
"filterable": True,
|
| 22 |
+
"type": "datetime"
|
| 23 |
+
}
|
| 24 |
+
]
|
| 25 |
+
},
|
| 26 |
+
"features": [
|
| 27 |
+
{
|
| 28 |
+
"name": "vision",
|
| 29 |
+
"domain": "surveillance"
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"name": "speech"
|
| 33 |
+
}
|
| 34 |
+
]
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
# Assuming you want to create a new index with a different name
|
| 38 |
+
# Update the index name in the URL to make it unique
|
| 39 |
+
url = "https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/new-video-index?api-version=2023-05-01-preview"
|
| 40 |
+
|
| 41 |
+
response = requests.put(url, json=data, headers=headers)
|
| 42 |
+
|
| 43 |
+
print("Response Status Code:", response.status_code)
|
| 44 |
+
print("Response Content:", response.text)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
url_index = "https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/my-video-index/ingestions/my-ingestion?api-version=2023-05-01-preview"
|
| 48 |
+
headers = {
|
| 49 |
+
"Ocp-Apim-Subscription-Key": "c54eec632ae5413e8075e3f825727822",
|
| 50 |
+
"Content-Type": "application/json"
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
data_index = {
|
| 55 |
+
"videos": [
|
| 56 |
+
{
|
| 57 |
+
"mode": "add",
|
| 58 |
+
"documentId": "sp=r&st=2024-02-09T12:33:24Z&se=2025-08-06T20:33:24Z&spr=https&sv=2022-11-02&sr=b&sig=V%2Fq56JjGcL60r0vt3oAPjzx%2FZMu5%2BJo%2BfjKkJF2ccgo%3D",
|
| 59 |
+
"documentUrl": "https://store1video.blob.core.windows.net/haptic-vid/test_video.mp4?sp=r&st=2024-02-09T12:33:24Z&se=2025-08-06T20:33:24Z&spr=https&sv=2022-11-02&sr=b&sig=V%2Fq56JjGcL60r0vt3oAPjzx%2FZMu5%2BJo%2BfjKkJF2ccgo%3D",
|
| 60 |
+
"metadata": {
|
| 61 |
+
"cameraId": "camera1",
|
| 62 |
+
"timestamp": "2024-02-09 00:02:14"
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
]
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
response_index = requests.put(url_index, json=data_index, headers=headers)
|
| 69 |
+
|
| 70 |
+
print("Index Ingestion - Response Status Code:", response_index.status_code)
|
| 71 |
+
print("Index Ingestion - Response Content:", response_index.text)
|
| 72 |
+
|
| 73 |
+
# Assuming you want to ingest another video with a different ingestion name
|
| 74 |
+
url_new_ingestion = "https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/my-video-index/ingestions/new-ingestion?api-version=2023-05-01-preview"
|
| 75 |
+
|
| 76 |
+
data_new_ingestion = {
|
| 77 |
+
"videos": [
|
| 78 |
+
{
|
| 79 |
+
"mode": "add",
|
| 80 |
+
"documentId": "new_document_id",
|
| 81 |
+
"documentUrl": "https://example.blob.core.windows.net/videos/new_video.mp4?sas_token_here",
|
| 82 |
+
"metadata": {
|
| 83 |
+
"cameraId": "camera3"
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
]
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
response_new_ingestion = requests.put(url_new_ingestion, json=data_new_ingestion, headers=headers)
|
| 90 |
+
|
| 91 |
+
print("New Ingestion - Response Status Code:", response_new_ingestion.status_code)
|
| 92 |
+
print("New Ingestion - Response Content:", response_new_ingestion.text)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
url_query = "https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/my-video-index:queryByText?api-version=2023-05-01-preview"
|
| 96 |
+
headers = {
|
| 97 |
+
"Ocp-Apim-Subscription-Key": "c54eec632ae5413e8075e3f825727822",
|
| 98 |
+
"Content-Type": "application/json"
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
data_query = {
|
| 102 |
+
"queryText": "Explosion",
|
| 103 |
+
"filters": {
|
| 104 |
+
"stringFilters": [
|
| 105 |
+
{
|
| 106 |
+
"fieldName": "cameraId",
|
| 107 |
+
"values": [
|
| 108 |
+
"camera1"
|
| 109 |
+
]
|
| 110 |
+
}
|
| 111 |
+
],
|
| 112 |
+
"featureFilters": ["vision"]
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
response_query = requests.post(url_query, json=data_query, headers=headers)
|
| 117 |
+
|
| 118 |
+
print("Query Response - Status Code:", response_query.status_code)
|
| 119 |
+
print("Query Response - Content:", response_query.text)
|