Spaces:
No application file
No application file
Tharunika1601
commited on
Commit
•
37e8503
1
Parent(s):
8a1fc90
Rename image-app to image.py
Browse files
image-app
DELETED
File without changes
|
image.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
|
6 |
+
# Model and tokenizer loading
|
7 |
+
model_id = "vikhyatk/moondream2"
|
8 |
+
revision = "2024-03-06"
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(
|
10 |
+
model_id, trust_remote_code=True, revision=revision
|
11 |
+
)
|
12 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, revision=revision)
|
13 |
+
|
14 |
+
# Image loading
|
15 |
+
image_path = 'demp.png'
|
16 |
+
image = Image.open(image_path)
|
17 |
+
|
18 |
+
# Display the image
|
19 |
+
image.show()
|
20 |
+
|
21 |
+
# Encoding the image
|
22 |
+
enc_image = model.encode_image(image)
|
23 |
+
|
24 |
+
# Asking the model to describe the image
|
25 |
+
description = model.answer_question(enc_image, "Describe this image.", tokenizer)
|
26 |
+
print("Generated Description:", description)
|