Spaces:
Paused
Paused
Commit
•
0b1b270
1
Parent(s):
2724204
Update app.py
Browse files
app.py
CHANGED
@@ -64,7 +64,7 @@ def predict_answer(image, video, question, max_tokens=100):
|
|
64 |
input_ids = tokenizer(text, return_tensors='pt').input_ids.to(device)
|
65 |
|
66 |
|
67 |
-
if image
|
68 |
# Process as an image
|
69 |
image = image.convert("RGB")
|
70 |
image_tensor = model.image_preprocess(image)
|
@@ -78,12 +78,12 @@ def predict_answer(image, video, question, max_tokens=100):
|
|
78 |
|
79 |
return tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip()
|
80 |
|
81 |
-
elif video
|
82 |
# Process as a video
|
83 |
frames = video_to_frames(video)
|
84 |
answers = []
|
85 |
for frame in frames:
|
86 |
-
image = extract_frames(frame)
|
87 |
image_tensor = model.image_preprocess(image)
|
88 |
|
89 |
# Generate the answer
|
@@ -95,7 +95,7 @@ def predict_answer(image, video, question, max_tokens=100):
|
|
95 |
|
96 |
answer = tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip()
|
97 |
answers.append(answer)
|
98 |
-
return
|
99 |
|
100 |
else:
|
101 |
return "Unsupported file type. Please upload an image or video."
|
|
|
64 |
input_ids = tokenizer(text, return_tensors='pt').input_ids.to(device)
|
65 |
|
66 |
|
67 |
+
if image:
|
68 |
# Process as an image
|
69 |
image = image.convert("RGB")
|
70 |
image_tensor = model.image_preprocess(image)
|
|
|
78 |
|
79 |
return tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip()
|
80 |
|
81 |
+
elif video:
|
82 |
# Process as a video
|
83 |
frames = video_to_frames(video)
|
84 |
answers = []
|
85 |
for frame in frames:
|
86 |
+
image = Image.open(extract_frames(frame)).convert("RGB")
|
87 |
image_tensor = model.image_preprocess(image)
|
88 |
|
89 |
# Generate the answer
|
|
|
95 |
|
96 |
answer = tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip()
|
97 |
answers.append(answer)
|
98 |
+
return answers
|
99 |
|
100 |
else:
|
101 |
return "Unsupported file type. Please upload an image or video."
|