Spaces:
Sleeping
Sleeping
Fernando Cervan
commited on
Commit
·
f5d0236
1
Parent(s):
f8138f2
Salvando alterações
Browse files
app.py
CHANGED
@@ -1,28 +1,31 @@
|
|
1 |
-
from transformers import
|
2 |
-
PaliGemmaProcessor,
|
3 |
-
PaliGemmaForConditionalGeneration,
|
4 |
-
)
|
5 |
-
from transformers.image_utils import load_image
|
6 |
import torch
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
1 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
2 |
import torch
|
3 |
|
4 |
+
pipe = pipeline(
|
5 |
+
"image-text-to-text",
|
6 |
+
model="google/gemma-3-4b-it",
|
7 |
+
device="cuda",
|
8 |
+
torch_dtype=torch.bfloat16
|
9 |
+
)
|
10 |
+
messages = [
|
11 |
+
{
|
12 |
+
"role": "system",
|
13 |
+
"content": [{"type": "text", "text": "You are a helpful assistant."}]
|
14 |
+
},
|
15 |
+
{
|
16 |
+
"role": "user",
|
17 |
+
"content": [
|
18 |
+
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
|
19 |
+
{"type": "text", "text": "What animal is on the candy?"}
|
20 |
+
]
|
21 |
+
}
|
22 |
+
]
|
23 |
|
24 |
+
output = pipe(text=messages, max_new_tokens=200)
|
25 |
+
print("=" * 20)
|
26 |
+
print(output[0]["generated_text"][-1]["content"])
|
27 |
+
print("=" * 20)
|
28 |
+
print("FIM PROCESSO")
|
29 |
+
# Okay, let's take a look!
|
30 |
+
# Based on the image, the animal on the candy is a **turtle**.
|
31 |
+
# You can see the shell shape and the head and legs.
|