Skip to content

Commit cf24854

Browse files
Xeelee33paullizer
andauthored
Bugfix - MAG Video Indexer API & Tweak to Speech Service Defaults (#344)
* Delete logfile.log * Removed external these are pending release and will show up in next version. * Update route_external_health.py * Adding health check * Added health check feature * updating app.py, removed external * Updated to v0.215.36 * Update app.py * v0.215.37 * v0.215.37 * updated so video indexer api default changes based on public/government cloud and is not read-only in the admin settings, removed hardcoded commercial speech_service_endpoint and speech_service_location * added placeholder for speech_service_endpoint to show default endpoint format based on location and cloud type * added reminders to save pending changes before fetching GPT models in admin settings * Added process to delete videos from VI service when deleted from front end/blob/cosmos. Includes adding the file's video indexer ID to the file metadata in cosmos. * Added unmerged files from Development branch --------- Co-authored-by: Paul Lizer <[email protected]> Co-authored-by: Paul Lizer <[email protected]>
1 parent 343dccd commit cf24854

File tree

5 files changed

+49
-9
lines changed

5 files changed

+49
-9
lines changed

application/single_app/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@
133133
else:
134134
AUTHORITY = f"https://login.microsoftonline.us/{TENANT_ID}"
135135

136+
# Commercial Azure Video Indexer Endpoint
137+
video_indexer_endpoint = "https://api.videoindexer.ai"
138+
136139
WORD_CHUNK_SIZE = 400
137140

138141
if AZURE_ENVIRONMENT == "usgovernment":
@@ -141,7 +144,9 @@
141144
authority = AzureAuthorityHosts.AZURE_GOVERNMENT
142145
credential_scopes=[resource_manager + "/.default"]
143146
cognitive_services_scope = "https://cognitiveservices.azure.us/.default"
147+
video_indexer_endpoint = "https://api.videoindexer.ai.azure.us"
144148
search_resource_manager = "https://search.azure.us"
149+
145150
elif AZURE_ENVIRONMENT == "custom":
146151
resource_manager = CUSTOM_RESOURCE_MANAGER_URL_VALUE
147152
authority = CUSTOM_IDENTITY_URL_VALUE

application/single_app/functions_documents.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,17 @@ def to_seconds(ts: str) -> float:
359359
raise ValueError("no video ID returned")
360360
print(f"[VIDEO] UPLOAD OK, videoId={vid}", flush=True)
361361
update_callback(status=f"VIDEO: uploaded id={vid}")
362+
try:
363+
# Update the document's metadata with the video indexer ID
364+
update_document(
365+
document_id=document_id,
366+
user_id=user_id,
367+
group_id=group_id,
368+
video_indexer_id=vid
369+
)
370+
except Exception as e:
371+
print(f"[VIDEO] Failed to update document metadata with video_indexer_id: {e}", flush=True)
372+
362373
except Exception as e:
363374
print(f"[VIDEO] UPLOAD ERROR: {e}", flush=True)
364375
update_callback(status=f"VIDEO: upload failed → {e}")
@@ -1444,8 +1455,29 @@ def delete_document(user_id, document_id, group_id=None, public_workspace_id=Non
14441455

14451456
# Get the file name from the document to use for blob deletion
14461457
file_name = document_item.get('file_name')
1447-
1448-
# First try to delete from blob storage
1458+
file_ext = os.path.splitext(file_name)[1].lower() if file_name else None
1459+
1460+
# First try to delete video from Video Indexer if applicable
1461+
if file_ext in ('.mp4', '.mov', '.avi', '.mkv', '.flv'):
1462+
try:
1463+
settings = get_settings()
1464+
vi_ep = settings.get("video_indexer_endpoint")
1465+
vi_loc = settings.get("video_indexer_location")
1466+
vi_acc = settings.get("video_indexer_account_id")
1467+
token = get_video_indexer_account_token(settings)
1468+
# You need to store the video ID in the document metadata when uploading
1469+
video_id = document_item.get("video_indexer_id")
1470+
if video_id:
1471+
delete_url = f"{vi_ep}/{vi_loc}/Accounts/{vi_acc}/Videos/{video_id}?accessToken={token}"
1472+
resp = requests.delete(delete_url, timeout=60)
1473+
resp.raise_for_status()
1474+
print(f"Deleted video from Video Indexer: {video_id}")
1475+
else:
1476+
print("No video_indexer_id found in document metadata; skipping Video Indexer deletion.")
1477+
except Exception as e:
1478+
print(f"Error deleting video from Video Indexer: {e}")
1479+
1480+
# Second try to delete from blob storage
14491481
try:
14501482
if file_name:
14511483
delete_from_blob_storage(document_id, user_id, file_name, group_id, public_workspace_id)

application/single_app/functions_settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def get_settings():
294294
'enable_external_healthcheck': False,
295295

296296
# Video file settings with Azure Video Indexer Settings
297-
'video_indexer_endpoint': 'https://api.videoindexer.ai',
297+
'video_indexer_endpoint': video_indexer_endpoint,
298298
'video_indexer_location': '',
299299
'video_indexer_account_id': '',
300300
'video_indexer_api_key': '',
@@ -305,8 +305,8 @@ def get_settings():
305305
'video_index_timeout': 600,
306306

307307
# Audio file settings with Azure speech service
308-
"speech_service_endpoint": "https://eastus.api.cognitive.microsoft.com",
309-
"speech_service_location": "eastus",
308+
"speech_service_endpoint": '',
309+
"speech_service_location": '',
310310
"speech_service_locale": "en-US",
311311
"speech_service_key": ""
312312
}

application/single_app/route_frontend_admin_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ def is_valid_url(url):
570570
'default_system_prompt': form_data.get('default_system_prompt', '').strip(),
571571

572572
# Video file settings with Azure Video Indexer Settings
573-
'video_indexer_endpoint': form_data.get('video_indexer_endpoint', 'https://api.videoindexer.ai').strip(),
573+
'video_indexer_endpoint': form_data.get('video_indexer_endpoint', video_indexer_endpoint).strip(),
574574
'video_indexer_location': form_data.get('video_indexer_location', '').strip(),
575575
'video_indexer_account_id': form_data.get('video_indexer_account_id', '').strip(),
576576
'video_indexer_api_key': form_data.get('video_indexer_api_key', '').strip(),

application/single_app/templates/admin_settings.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ <h6>External Links</h6>
10121012
<div class="mb-3">
10131013
<label for="gpt_model" class="form-label">Azure OpenAI GPT Model Selection</label>
10141014
<br><small>Each selected model will be available in the Chat UI as an option for the User. You can select multiple models.</small>
1015+
<br><small>Save Pending Changes to settings before clicking Fetch Models</small>
10151016
<div id="gpt_models_list" class="mt-2 mb-3">
10161017

10171018
</div>
@@ -1153,6 +1154,7 @@ <h6>External Links</h6>
11531154
<div id="embedding_models_list" class="mt-2 mb-3">
11541155

11551156
</div>
1157+
<small>Save pending changes to settings before clicking Fetch Embedding Models</small>
11561158

11571159
<input type="hidden" name="embedding_model_json" id="embedding_model_json" />
11581160

@@ -1599,14 +1601,14 @@ <h5>Video Indexer Settings</h5>
15991601

16001602
<div class="mb-3">
16011603
<label for="video_indexer_endpoint" class="form-label">Endpoint</label>
1602-
<input type="text" readonly class="form-control"
1604+
<input type="text" class="form-control"
16031605
id="video_indexer_endpoint" name="video_indexer_endpoint"
16041606
value="{{ settings.video_indexer_endpoint or 'https://api.videoindexer.ai' }}">
16051607
</div>
16061608

16071609
<div class="mb-3">
16081610
<label for="video_indexer_arm_api_version" class="form-label">ARM API Version</label>
1609-
<input type="text" readonly class="form-control"
1611+
<input type="text" class="form-control"
16101612
id="video_indexer_arm_api_version" name="video_indexer_arm_api_version"
16111613
value="{{ settings.video_indexer_arm_api_version or '2021-11-10-preview' }}">
16121614
</div>
@@ -1687,7 +1689,8 @@ <h5>Speech Service Settings</h5>
16871689
<label for="speech_service_endpoint" class="form-label">Endpoint</label>
16881690
<input type="text" class="form-control"
16891691
id="speech_service_endpoint" name="speech_service_endpoint"
1690-
value="{{ settings.speech_service_endpoint or '' }}">
1692+
value="{{ settings.speech_service_endpoint or '' }}"
1693+
placeholder="https://<location>.cognitiveservices.azure.<com or us>/">
16911694
</div>
16921695

16931696
<div class="mb-3">

0 commit comments

Comments
 (0)