HussainLatiff commited on
Commit
775e795
Β·
verified Β·
1 Parent(s): 83aa815

Rename apiTest.py to videoAnalysis.py

Browse files

fixed issues with multiple videos being given unique indexes

Files changed (1) hide show
  1. apiTest.py β†’ videoAnalysis.py +23 -15
apiTest.py β†’ videoAnalysis.py RENAMED
@@ -1,7 +1,15 @@
1
  import requests
2
 
 
 
3
  def videoAnalysis(sas_token, sas_url, search):
4
- url = "https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/my-video-index?api-version=2023-05-01-preview"
 
 
 
 
 
 
5
  headers = {
6
  "Ocp-Apim-Subscription-Key": "c54eec632ae5413e8075e3f825727822",
7
  "Content-Type": "application/json"
@@ -35,18 +43,15 @@ def videoAnalysis(sas_token, sas_url, search):
35
  ]
36
  }
37
 
38
- # Assuming you want to create a new index with a different name
39
- # Update the index name in the URL to make it unique
40
- url = "https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/new-video-index?api-version=2023-05-01-preview"
41
 
42
  response = requests.put(url, json=data, headers=headers)
43
 
44
  #test code for errors
45
- #print("Response Status Code:", response.status_code)
46
- #print("Response Content:", response.text)
47
 
48
 
49
- url_index = "https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/my-video-index/ingestions/my-ingestion?api-version=2023-05-01-preview"
50
  headers = {
51
  "Ocp-Apim-Subscription-Key": "c54eec632ae5413e8075e3f825727822",
52
  "Content-Type": "application/json"
@@ -70,11 +75,11 @@ def videoAnalysis(sas_token, sas_url, search):
70
  response_index = requests.put(url_index, json=data_index, headers=headers)
71
 
72
  #test code for errors
73
- #print("Index Ingestion - Response Status Code:", response_index.status_code)
74
- #print("Index Ingestion - Response Content:", response_index.text)
75
 
76
  # Assuming you want to ingest another video with a different ingestion name
77
- url_new_ingestion = "https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/my-video-index/ingestions/new-ingestion?api-version=2023-05-01-preview"
78
 
79
  data_new_ingestion = {
80
  "videos": [
@@ -92,11 +97,11 @@ def videoAnalysis(sas_token, sas_url, search):
92
  response_new_ingestion = requests.put(url_new_ingestion, json=data_new_ingestion, headers=headers)
93
 
94
  #used to test code for errors
95
- #print("New Ingestion - Response Status Code:", response_new_ingestion.status_code)
96
- #print("New Ingestion - Response Content:", response_new_ingestion.text)
97
 
98
 
99
- url_query = "https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/my-video-index:queryByText?api-version=2023-05-01-preview"
100
  headers = {
101
  "Ocp-Apim-Subscription-Key": "c54eec632ae5413e8075e3f825727822",
102
  "Content-Type": "application/json"
@@ -119,6 +124,9 @@ def videoAnalysis(sas_token, sas_url, search):
119
 
120
  response_query = requests.post(url_query, json=data_query, headers=headers)
121
 
 
 
 
122
  return response_query.text
123
 
124
  #Enter the sas token
@@ -133,9 +141,9 @@ test_explosion = videoAnalysis(sas_token_1, sas_url_1, instance_1)
133
  print(test_explosion)
134
 
135
  #Enter the sas token
136
- sas_token_2 = "sp=r&st=2024-03-17T11:55:51Z&se=2026-04-30T19:55:51Z&spr=https&sv=2022-11-02&sr=b&sig=RNdeiWnjbULMa3icBc1%2FqYuIVrdEMquvksokWZMVL20%3D"
137
  #the sas url
138
- sas_url_2= "https://store1video.blob.core.windows.net/haptic-vid/suv-in-the-dust.mp4?sp=r&st=2024-03-17T11:55:51Z&se=2026-04-30T19:55:51Z&spr=https&sv=2022-11-02&sr=b&sig=RNdeiWnjbULMa3icBc1%2FqYuIVrdEMquvksokWZMVL20%3D"
139
  #query of what you are looking for
140
  instance_2 = "Vehicle racing"
141
 
 
1
  import requests
2
 
3
+ index_counter = 0 # Global counter for video indexes
4
+
5
  def videoAnalysis(sas_token, sas_url, search):
6
+
7
+ global index_counter # Access the global counter variable
8
+
9
+ index_counter += 1
10
+ index_name = f"video-index-{index_counter}"
11
+
12
+ url = f"https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/{index_name}?api-version=2023-05-01-preview"
13
  headers = {
14
  "Ocp-Apim-Subscription-Key": "c54eec632ae5413e8075e3f825727822",
15
  "Content-Type": "application/json"
 
43
  ]
44
  }
45
 
 
 
 
46
 
47
  response = requests.put(url, json=data, headers=headers)
48
 
49
  #test code for errors
50
+ print("Response Status Code:", response.status_code)
51
+ print("Response Content:", response.text)
52
 
53
 
54
+ url_index = f"https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/{index_name}/ingestions/my-ingestion?api-version=2023-05-01-preview"
55
  headers = {
56
  "Ocp-Apim-Subscription-Key": "c54eec632ae5413e8075e3f825727822",
57
  "Content-Type": "application/json"
 
75
  response_index = requests.put(url_index, json=data_index, headers=headers)
76
 
77
  #test code for errors
78
+ print("Index Ingestion - Response Status Code:", response_index.status_code)
79
+ print("Index Ingestion - Response Content:", response_index.text)
80
 
81
  # Assuming you want to ingest another video with a different ingestion name
82
+ url_new_ingestion = f"https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/{index_name}/ingestions/new-ingestion?api-version=2023-05-01-preview"
83
 
84
  data_new_ingestion = {
85
  "videos": [
 
97
  response_new_ingestion = requests.put(url_new_ingestion, json=data_new_ingestion, headers=headers)
98
 
99
  #used to test code for errors
100
+ print("New Ingestion - Response Status Code:", response_new_ingestion.status_code)
101
+ print("New Ingestion - Response Content:", response_new_ingestion.text)
102
 
103
 
104
+ url_query = f"https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/{index_name}:queryByText?api-version=2023-05-01-preview"
105
  headers = {
106
  "Ocp-Apim-Subscription-Key": "c54eec632ae5413e8075e3f825727822",
107
  "Content-Type": "application/json"
 
124
 
125
  response_query = requests.post(url_query, json=data_query, headers=headers)
126
 
127
+ if response_query.text == """{"error":{"code":"InvalidRequest","message":"Value for indexName is invalid."}}""":
128
+ videoAnalysis(sas_token,sas_url, search)
129
+
130
  return response_query.text
131
 
132
  #Enter the sas token
 
141
  print(test_explosion)
142
 
143
  #Enter the sas token
144
+ sas_token_2 = "sp=r&st=2024-03-18T08:37:02Z&se=2027-04-22T16:37:02Z&spr=https&sv=2022-11-02&sr=b&sig=UqvmHzf1jzdD6njwO1S7YhD5a%2B7hZHrd3q3FaeV1WNg%3D"
145
  #the sas url
146
+ sas_url_2= "https://store1video.blob.core.windows.net/haptic-vid/desert_vehicle.mp4?sp=r&st=2024-03-18T08:37:02Z&se=2027-04-22T16:37:02Z&spr=https&sv=2022-11-02&sr=b&sig=UqvmHzf1jzdD6njwO1S7YhD5a%2B7hZHrd3q3FaeV1WNg%3D"
147
  #query of what you are looking for
148
  instance_2 = "Vehicle racing"
149