Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -121,25 +121,29 @@ def check_condition(prompt, base64Frames):
|
|
121 |
|
122 |
# Save frames as images
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
|
|
|
|
|
|
143 |
try:
|
144 |
jsonNew = json.loads(api_response)
|
145 |
print('result', response.usage.total_tokens, jsonNew)
|
|
|
121 |
|
122 |
# Save frames as images
|
123 |
|
124 |
+
try:
|
125 |
+
messages = [
|
126 |
+
{"role": "system", "content": """You are analyzing video to check if the user's condition is met.
|
127 |
+
Please respond with a JSON object in the following format:
|
128 |
+
{"condition_met": true/false, "details": "optional details or summary. in the summary DON'T mention the words: image, images, frame, or frames. Instead, make it look like you were provided with video input and avoid referring to individual images or frames explicitly."}"""},
|
129 |
+
{"role": "user", "content": [prompt, *map(lambda x: {"type": "image_url", "image_url": {"url": f'data:image/jpg;base64,{x}', "detail": "low"}}, base64Frames)]}
|
130 |
+
]
|
131 |
+
|
132 |
+
response = client.chat.completions.create(
|
133 |
+
model="gpt-4o",
|
134 |
+
messages=messages,
|
135 |
+
temperature=0,
|
136 |
+
response_format={ "type": "json_object" }
|
137 |
+
)
|
138 |
+
|
139 |
+
end_time = time.time()
|
140 |
+
processing_time = end_time - start_time
|
141 |
+
frames_count = len(base64Frames)
|
142 |
+
api_response = response.choices[0].message.content
|
143 |
+
except Error as e:
|
144 |
+
print('error from openai', e)
|
145 |
+
return 0, 0, {"condition_met": False}
|
146 |
+
|
147 |
try:
|
148 |
jsonNew = json.loads(api_response)
|
149 |
print('result', response.usage.total_tokens, jsonNew)
|