Spaces:
Runtime error
Runtime error
Update app.py
Browse filesvideo api test
app.py
CHANGED
|
@@ -1,10 +1,42 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def video_identity(video):
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
demo = gr.Interface(video_identity,
|
| 10 |
gr.Video(),
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
import requests
|
| 4 |
|
| 5 |
+
# Define your endpoint URL and subscription key
|
| 6 |
+
endpoint_url = "https://https://explosion.cognitiveservices.azure.com//computervision/retrieval/indexes/my-video-index:queryByText?api-version=2023-05-01-preview"
|
| 7 |
+
subscription_key = "c54eec632ae5413e8075e3f825727822"
|
| 8 |
|
| 9 |
def video_identity(video):
|
| 10 |
+
# Send a request to query the video index
|
| 11 |
+
query_text = 'explosion'
|
| 12 |
+
filters = {
|
| 13 |
+
'stringFilters': [
|
| 14 |
+
{
|
| 15 |
+
'fieldName': 'cameraId',
|
| 16 |
+
'values': ['camera1']
|
| 17 |
+
}
|
| 18 |
+
],
|
| 19 |
+
'featureFilters': ['vision']
|
| 20 |
+
}
|
| 21 |
+
headers = {
|
| 22 |
+
"Ocp-Apim-Subscription-Key": subscription_key,
|
| 23 |
+
"Content-Type": "application/json"
|
| 24 |
+
}
|
| 25 |
+
data = {
|
| 26 |
+
'queryText': query_text,
|
| 27 |
+
'filters': filters
|
| 28 |
+
}
|
| 29 |
+
response = requests.post(endpoint_url, headers=headers, json=data)
|
| 30 |
|
| 31 |
+
# Process the response
|
| 32 |
+
if response.status_code == 200:
|
| 33 |
+
result = response.json() # Extract the result from the JSON response
|
| 34 |
+
# Process the result here, you can modify this based on your requirements
|
| 35 |
+
return result
|
| 36 |
+
else:
|
| 37 |
+
print("Failed to query video index. Status code:", response.status_code)
|
| 38 |
+
print("Error message:", response.text)
|
| 39 |
+
return None
|
| 40 |
|
| 41 |
demo = gr.Interface(video_identity,
|
| 42 |
gr.Video(),
|