Update app.py
Browse files
app.py
CHANGED
@@ -81,12 +81,15 @@ def extract_frames(video_in, interval=24, output_format='.jpg'):
|
|
81 |
|
82 |
return frames
|
83 |
|
84 |
-
from transformers import AutoModelForCausalLM,
|
85 |
from PIL import Image
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
90 |
|
91 |
def process_image(image_in):
|
92 |
'''
|
@@ -100,9 +103,9 @@ def process_image(image_in):
|
|
100 |
print(result)
|
101 |
return result
|
102 |
'''
|
103 |
-
image = Image.open(
|
104 |
-
enc_image =
|
105 |
-
result =
|
106 |
print(result)
|
107 |
return result
|
108 |
|
|
|
81 |
|
82 |
return frames
|
83 |
|
84 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
85 |
from PIL import Image
|
86 |
|
87 |
+
model_id = "vikhyatk/moondream2"
|
88 |
+
revision = "2024-03-06"
|
89 |
+
model = AutoModelForCausalLM.from_pretrained(
|
90 |
+
model_id, trust_remote_code=True, revision=revision
|
91 |
+
)
|
92 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, revision=revision)
|
93 |
|
94 |
def process_image(image_in):
|
95 |
'''
|
|
|
103 |
print(result)
|
104 |
return result
|
105 |
'''
|
106 |
+
image = Image.open('<IMAGE_PATH>')
|
107 |
+
enc_image = model.encode_image(image)
|
108 |
+
result = model.answer_question(enc_image, "Describe the image in one sentence.", tokenizer)
|
109 |
print(result)
|
110 |
return result
|
111 |
|