Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import torch
|
|
| 4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 5 |
import cv2
|
| 6 |
import numpy as np
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
# # Ensure GPU usage if available
|
|
@@ -100,8 +101,8 @@ def predict_answer(image, video, question, max_tokens=100):
|
|
| 100 |
# Process as a video
|
| 101 |
frames = video_to_frames(video)
|
| 102 |
answers = []
|
| 103 |
-
for
|
| 104 |
-
image = extract_frames(
|
| 105 |
image_tensor = model.image_preprocess([image])
|
| 106 |
|
| 107 |
# Generate the answer
|
|
@@ -113,7 +114,7 @@ def predict_answer(image, video, question, max_tokens=100):
|
|
| 113 |
|
| 114 |
answer = tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip()
|
| 115 |
answers.append(answer)
|
| 116 |
-
return answers
|
| 117 |
|
| 118 |
else:
|
| 119 |
return "Unsupported file type. Please upload an image or video."
|
|
|
|
| 4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 5 |
import cv2
|
| 6 |
import numpy as np
|
| 7 |
+
import ast
|
| 8 |
|
| 9 |
|
| 10 |
# # Ensure GPU usage if available
|
|
|
|
| 101 |
# Process as a video
|
| 102 |
frames = video_to_frames(video)
|
| 103 |
answers = []
|
| 104 |
+
for i in range(len(frames)):
|
| 105 |
+
image = extract_frames(frames[i])
|
| 106 |
image_tensor = model.image_preprocess([image])
|
| 107 |
|
| 108 |
# Generate the answer
|
|
|
|
| 114 |
|
| 115 |
answer = tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip()
|
| 116 |
answers.append(answer)
|
| 117 |
+
return ast.literal_eval(answers[0])
|
| 118 |
|
| 119 |
else:
|
| 120 |
return "Unsupported file type. Please upload an image or video."
|