Problem: Zugriff auf ein privates Speicherkonto mit Computer Vision für die Datenaufnahme nicht möglich
Erwartetes Ergebnis: Erfolgreich Daten in ein privates Speicherkonto aufnehmen
Tatsächliches Ergebnis: Die Aufnahme funktioniert nur, wenn das Speicherkonto auf öffentlich eingestellt ist.
Ich habe sichergestellt, dass ich meine IP im Azure-Portal hinzugefügt habe, während ich Python ausgeführt habe Code.
Ich habe unten als Referenz für die Entwicklung meines Codes verwendet
https://learn.microsoft.com/en-us/azure/ai -services/computer-vision/reference-video-search
Bitte finden Sie den Code als Referenz. Lassen Sie mich wissen, wenn Sie Vorschläge für den folgenden Code haben.
< pre class="lang-py Prettyprint-override">
Code: Select all
def add_video_to_index(vision_api_endpoint: str, vision_api_key: str, index_name: str, video_url: str, video_id: str,
ingestion_name: str) -> object:
"""Function to add a Video to the Retrieval Index created in the Computer Vision API.
Args:
vision_api_endpoint (str): URL Endpoint for the Computer Vision API service
vision_api_key (str): Key to access the Vision API service
index_name (str): Name to be provided to the created index
video_url (str): SAS URL from the Blob storage account for the video
video_id (str): ID of the Video Docoument being added to the index
ingestion_name (str): Name with whcich the ingestion needs to be created
Returns:
Response: Returns a response object after a put call to the Indexes endpoint of th Vision API retrieval service
"""
# Setup the Computer Vision Video Indexing service URL
url = (
f"{vision_api_endpoint}/computervision/retrieval/indexes/{index_name}"
f"/ingestions/{ingestion_name}?api-version=2023-05-01-preview"#2024-10-01 #2023-05-01-preview
)
headers = {"Ocp-Apim-Subscription-Key": vision_api_key, "Content-Type": "application/json"}
# Setup data in add mode
data = {
"videos": [{"mode": "add", "documentId": video_id, "documentUrl": video_url}],
"generateInsightIntervals": False,
"moderation": False,
"filterDefectedFrames": False,
# "includeSpeechTranscrpt": True,
}
# Return a response from the URL request
return requests.put(url, headers=headers, data=json.dumps(data), timeout=600)
def wait_for_ingestion_completion(vision_api_endpoint: str, vision_api_key: str, index_name: str, ingestion_name: str, max_retries: int = 30) -> bool:
"""Function to wait for CV Indxing Ingestion request to complete
Args:
vision_api_endpoint (str): API Endpoint for the Computer Vision service from the Azure AI Services suite
vision_api_key (str): API key for Computer Vision service
index_name (str): Video Index name to which thev ingestion request was created
max_retries (int): No of attempts to be made before exiting the status check
Returns:
bool: Returns True of False based on the success or failure of the ingestion to the Computer Vision Indexing API
"""
# Setup the Computer Vision Video Indexing service URL
url = (
f"{vision_api_endpoint}/computervision/retrieval/indexes/{index_name}/ingestions/{ingestion_name}?api-version=2023-05-01-preview" #2024-10-01"
)
headers = {"Ocp-Apim-Subscription-Key": vision_api_key}
# Start the status check loop
retries = 0
while retries < max_retries:
response = requests.get(url, headers=headers)
state_data = response.json()
print(state_data)
# Return or continue based on status
if response.status_code == 200:
if "value" in state_data.keys():
if state_data["value"][0]["state"] == "Completed":
print("Ingestion completed.")
return True
if state_data["value"][0]["state"] == "Failed":
print("Ingestion failed.")
return False
else:
if state_data["state"] == "Completed":
print("Ingestion completed.")
return True
if state_data["state"] == "Failed":
print("Ingestion failed.")
return False
time.sleep(60) #60 sec wait between respective checks
retries += 1