Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
| 5 |
import cv2
|
| 6 |
import numpy as np
|
| 7 |
import ast
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
# # Ensure GPU usage if available
|
|
@@ -98,10 +99,23 @@ def predict_answer(video, image, question):
|
|
| 98 |
|
| 99 |
answer = tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip()
|
| 100 |
answers.append(answer)
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
else:
|
| 104 |
-
|
| 105 |
|
| 106 |
promt_cat_dog = """
|
| 107 |
Annotate this image with this schema:
|
|
|
|
| 5 |
import cv2
|
| 6 |
import numpy as np
|
| 7 |
import ast
|
| 8 |
+
from collections import Counter
|
| 9 |
|
| 10 |
|
| 11 |
# # Ensure GPU usage if available
|
|
|
|
| 99 |
|
| 100 |
answer = tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip()
|
| 101 |
answers.append(answer)
|
| 102 |
+
|
| 103 |
+
# Modify this logic based on your specific needs
|
| 104 |
+
most_common_answer = Counter(answers).most_common(1)[0][0]
|
| 105 |
+
|
| 106 |
+
# Safely evaluate the most common answer assuming it's a string representation of a Python literal
|
| 107 |
+
try:
|
| 108 |
+
evaluated_answer = ast.literal_eval(most_common_answer)
|
| 109 |
+
except (ValueError, SyntaxError):
|
| 110 |
+
# Handle malformed answer string
|
| 111 |
+
evaluated_answer = f"Error evaluating answer: {most_common_answer}"
|
| 112 |
+
|
| 113 |
+
return evaluated_answer
|
| 114 |
+
|
| 115 |
+
# return ast.literal_eval(answers[0])
|
| 116 |
|
| 117 |
+
# else:
|
| 118 |
+
# return "Unsupported file type. Please upload an image or video."
|
| 119 |
|
| 120 |
promt_cat_dog = """
|
| 121 |
Annotate this image with this schema:
|