Spaces:
Paused
Paused
ManishThota
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -61,13 +61,13 @@ def extract_frames(frame):
|
|
61 |
|
62 |
return image_bgr
|
63 |
|
64 |
-
def predict_answer(video,image, question):
|
65 |
|
66 |
text = f"A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: <image>\n{question}? ASSISTANT:"
|
67 |
input_ids = tokenizer(text, return_tensors='pt').input_ids.to(device)
|
68 |
|
69 |
|
70 |
-
if image
|
71 |
# Process as an image
|
72 |
image = image.convert("RGB")
|
73 |
image_tensor = model.image_preprocess(image)
|
@@ -81,7 +81,7 @@ def predict_answer(video,image, question):
|
|
81 |
|
82 |
return tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip()
|
83 |
|
84 |
-
elif video
|
85 |
# Process as a video
|
86 |
frames = video_to_frames(video)
|
87 |
answers = []
|
@@ -103,8 +103,7 @@ def predict_answer(video,image, question):
|
|
103 |
else:
|
104 |
return "Unsupported file type. Please upload an image or video."
|
105 |
|
106 |
-
promt_cat_dog = """
|
107 |
-
Annotate this image with this schema:
|
108 |
{
|
109 |
“description”: “Is there a cat in the image?”,
|
110 |
“value”: “Cat”
|
@@ -148,7 +147,6 @@ promt_video = """
|
|
148 |
"""
|
149 |
test_examples = [[None, "Images/cat_dog.jpeg", promt_cat_dog],
|
150 |
[None,"Images/bus_people.jpeg", promt_bus_people],
|
151 |
-
["videos/v1.mp4",None,promt_video],
|
152 |
["videos/v2.mp4",None,promt_video],
|
153 |
["videos/v3.mp4",None,promt_video]]
|
154 |
|
|
|
61 |
|
62 |
return image_bgr
|
63 |
|
64 |
+
def predict_answer(video, image, question):
|
65 |
|
66 |
text = f"A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: <image>\n{question}? ASSISTANT:"
|
67 |
input_ids = tokenizer(text, return_tensors='pt').input_ids.to(device)
|
68 |
|
69 |
|
70 |
+
if image:
|
71 |
# Process as an image
|
72 |
image = image.convert("RGB")
|
73 |
image_tensor = model.image_preprocess(image)
|
|
|
81 |
|
82 |
return tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip()
|
83 |
|
84 |
+
elif video:
|
85 |
# Process as a video
|
86 |
frames = video_to_frames(video)
|
87 |
answers = []
|
|
|
103 |
else:
|
104 |
return "Unsupported file type. Please upload an image or video."
|
105 |
|
106 |
+
promt_cat_dog = """Annotate this image with this schema:
|
|
|
107 |
{
|
108 |
“description”: “Is there a cat in the image?”,
|
109 |
“value”: “Cat”
|
|
|
147 |
"""
|
148 |
test_examples = [[None, "Images/cat_dog.jpeg", promt_cat_dog],
|
149 |
[None,"Images/bus_people.jpeg", promt_bus_people],
|
|
|
150 |
["videos/v2.mp4",None,promt_video],
|
151 |
["videos/v3.mp4",None,promt_video]]
|
152 |
|