Update app.py
Browse files
app.py
CHANGED
|
@@ -106,8 +106,7 @@ def check_condition(prompt, base64Frames):
|
|
| 106 |
messages = [
|
| 107 |
{"role": "system", "content": """You are analyzing video to check if the user's condition is met.
|
| 108 |
Please respond with a JSON object in the following format:
|
| 109 |
-
{"condition_met": true/false, "details": "optional details or summary."}
|
| 110 |
-
in the response make sure you don't use the words frames or images at all!"""},
|
| 111 |
{"role": "user", "content": [prompt, *map(lambda x: {"type": "image_url", "image_url": {"url": f'data:image/jpg;base64,{x}', "detail": "low"}}, base64Frames)]}
|
| 112 |
]
|
| 113 |
response = client.chat.completions.create(
|
|
@@ -123,6 +122,8 @@ def check_condition(prompt, base64Frames):
|
|
| 123 |
api_response = response.choices[0].message.content
|
| 124 |
try:
|
| 125 |
jsonNew = json.loads(api_response)
|
|
|
|
|
|
|
| 126 |
print('result', response.usage.total_tokens, jsonNew)
|
| 127 |
return frames_count, processing_time, jsonNew
|
| 128 |
except:
|
|
|
|
| 106 |
messages = [
|
| 107 |
{"role": "system", "content": """You are analyzing video to check if the user's condition is met.
|
| 108 |
Please respond with a JSON object in the following format:
|
| 109 |
+
{"condition_met": true/false, "details": "optional details or summary."}"""},
|
|
|
|
| 110 |
{"role": "user", "content": [prompt, *map(lambda x: {"type": "image_url", "image_url": {"url": f'data:image/jpg;base64,{x}', "detail": "low"}}, base64Frames)]}
|
| 111 |
]
|
| 112 |
response = client.chat.completions.create(
|
|
|
|
| 122 |
api_response = response.choices[0].message.content
|
| 123 |
try:
|
| 124 |
jsonNew = json.loads(api_response)
|
| 125 |
+
if jsonNew.condition_met == True and jsonNew.details != None:
|
| 126 |
+
jsonNew.details = jsonNew.details.replace('frames', 'video').replace('images', 'video').replace('frame', 'video').replace('image', 'video')
|
| 127 |
print('result', response.usage.total_tokens, jsonNew)
|
| 128 |
return frames_count, processing_time, jsonNew
|
| 129 |
except:
|