@@ -29,8 +29,8 @@ import requests
|
|||||||
|
|
||||||
processor = AutoProcessor.from_pretrained("google/paligemma-3b-pt-224")
|
processor = AutoProcessor.from_pretrained("google/paligemma-3b-pt-224")
|
||||||
|
|
||||||
prompt = "answer en Where is the cow standing?"
|
prompt = "answer en Where is the cat standing?"
|
||||||
url = "https://huggingface.co/gv-hf/PaliGemma-test-224px-hf/resolve/main/cow_beach_1.png"
|
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"
|
||||||
image = Image.open(requests.get(url, stream=True).raw)
|
image = Image.open(requests.get(url, stream=True).raw)
|
||||||
|
|
||||||
inputs = processor(text=prompt, images=image, return_tensors="pt")
|
inputs = processor(text=prompt, images=image, return_tensors="pt")
|
||||||
|
|||||||
@@ -1272,20 +1272,37 @@ class Gemma3ForConditionalGeneration(Gemma3PreTrainedModel, GenerationMixin):
|
|||||||
>>> import requests
|
>>> import requests
|
||||||
>>> from transformers import AutoProcessor, Gemma3ForConditionalGeneration
|
>>> from transformers import AutoProcessor, Gemma3ForConditionalGeneration
|
||||||
|
|
||||||
>>> model = Gemma3ForConditionalGeneration.from_pretrained("google/Gemma3-test-224px-hf")
|
>>> model = Gemma3ForConditionalGeneration.from_pretrained("google/gemma-3-4b-it")
|
||||||
>>> processor = AutoProcessor.from_pretrained("google/Gemma3-test-224px-hf")
|
>>> processor = AutoProcessor.from_pretrained("google/gemma-3-4b-it")
|
||||||
|
|
||||||
>>> prompt = "answer en Where is the cow standing?"
|
>>> messages = [
|
||||||
>>> url = "https://huggingface.co/gv-hf/Gemma3-test-224px-hf/resolve/main/cow_beach_1.png"
|
... {
|
||||||
>>> image = Image.open(requests.get(url, stream=True).raw)
|
... "role": "system",
|
||||||
|
... "content": [
|
||||||
>>> inputs = processor(images=image, text=prompt, return_tensors="pt")
|
... {"type": "text", "text": "You are a helpful assistant."}
|
||||||
|
... ]
|
||||||
|
... },
|
||||||
|
... {
|
||||||
|
... "role": "user", "content": [
|
||||||
|
... {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"},
|
||||||
|
... {"type": "text", "text": "Where is the cat standing?"},
|
||||||
|
... ]
|
||||||
|
... },
|
||||||
|
... ]
|
||||||
|
|
||||||
|
>>> inputs = processor.apply_chat_template(
|
||||||
|
... messages,
|
||||||
|
... tokenizer=True,
|
||||||
|
... return_dict=True,
|
||||||
|
... return_tensors="pt",
|
||||||
|
... add_generation_prompt=True
|
||||||
|
... )
|
||||||
>>> # Generate
|
>>> # Generate
|
||||||
>>> generate_ids = model.generate(**inputs, max_length=30)
|
>>> generate_ids = model.generate(**inputs)
|
||||||
>>> processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
>>> processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
||||||
"answer en Where is the cow standing?\nbeach"
|
"user\nYou are a helpful assistant.\n\n\n\n\n\nWhere is the cat standing?\nmodel\nBased on the image, the cat is standing in a snowy area, likely outdoors. It appears to"
|
||||||
```"""
|
```
|
||||||
|
"""
|
||||||
|
|
||||||
if (input_ids is None) ^ (inputs_embeds is not None):
|
if (input_ids is None) ^ (inputs_embeds is not None):
|
||||||
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
||||||
|
|||||||
@@ -883,20 +883,37 @@ class Gemma3ForConditionalGeneration(PaliGemmaForConditionalGeneration):
|
|||||||
>>> import requests
|
>>> import requests
|
||||||
>>> from transformers import AutoProcessor, Gemma3ForConditionalGeneration
|
>>> from transformers import AutoProcessor, Gemma3ForConditionalGeneration
|
||||||
|
|
||||||
>>> model = Gemma3ForConditionalGeneration.from_pretrained("google/Gemma3-test-224px-hf")
|
>>> model = Gemma3ForConditionalGeneration.from_pretrained("google/gemma-3-4b-it")
|
||||||
>>> processor = AutoProcessor.from_pretrained("google/Gemma3-test-224px-hf")
|
>>> processor = AutoProcessor.from_pretrained("google/gemma-3-4b-it")
|
||||||
|
|
||||||
>>> prompt = "answer en Where is the cow standing?"
|
>>> messages = [
|
||||||
>>> url = "https://huggingface.co/gv-hf/Gemma3-test-224px-hf/resolve/main/cow_beach_1.png"
|
... {
|
||||||
>>> image = Image.open(requests.get(url, stream=True).raw)
|
... "role": "system",
|
||||||
|
... "content": [
|
||||||
>>> inputs = processor(images=image, text=prompt, return_tensors="pt")
|
... {"type": "text", "text": "You are a helpful assistant."}
|
||||||
|
... ]
|
||||||
|
... },
|
||||||
|
... {
|
||||||
|
... "role": "user", "content": [
|
||||||
|
... {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"},
|
||||||
|
... {"type": "text", "text": "Where is the cat standing?"},
|
||||||
|
... ]
|
||||||
|
... },
|
||||||
|
... ]
|
||||||
|
|
||||||
|
>>> inputs = processor.apply_chat_template(
|
||||||
|
... messages,
|
||||||
|
... tokenizer=True,
|
||||||
|
... return_dict=True,
|
||||||
|
... return_tensors="pt",
|
||||||
|
... add_generation_prompt=True
|
||||||
|
... )
|
||||||
>>> # Generate
|
>>> # Generate
|
||||||
>>> generate_ids = model.generate(**inputs, max_length=30)
|
>>> generate_ids = model.generate(**inputs)
|
||||||
>>> processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
>>> processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
||||||
"answer en Where is the cow standing?\nbeach"
|
"user\nYou are a helpful assistant.\n\n\n\n\n\nWhere is the cat standing?\nmodel\nBased on the image, the cat is standing in a snowy area, likely outdoors. It appears to"
|
||||||
```"""
|
```
|
||||||
|
"""
|
||||||
|
|
||||||
if (input_ids is None) ^ (inputs_embeds is not None):
|
if (input_ids is None) ^ (inputs_embeds is not None):
|
||||||
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
||||||
|
|||||||
@@ -464,19 +464,19 @@ class PaliGemmaForConditionalGeneration(PaliGemmaPreTrainedModel, GenerationMixi
|
|||||||
>>> import requests
|
>>> import requests
|
||||||
>>> from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
|
>>> from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
|
||||||
|
|
||||||
>>> model = PaliGemmaForConditionalGeneration.from_pretrained("google/PaliGemma-test-224px-hf")
|
>>> model = PaliGemmaForConditionalGeneration.from_pretrained("google/paligemma2-3b-mix-224")
|
||||||
>>> processor = AutoProcessor.from_pretrained("google/PaliGemma-test-224px-hf")
|
>>> processor = AutoProcessor.from_pretrained("google/paligemma2-3b-mix-224")
|
||||||
|
|
||||||
>>> prompt = "answer en Where is the cow standing?"
|
>>> prompt = "Where is the cat standing?"
|
||||||
>>> url = "https://huggingface.co/gv-hf/PaliGemma-test-224px-hf/resolve/main/cow_beach_1.png"
|
>>> url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"
|
||||||
>>> image = Image.open(requests.get(url, stream=True).raw)
|
>>> image = Image.open(requests.get(url, stream=True).raw)
|
||||||
|
|
||||||
>>> inputs = processor(images=image, text=prompt, return_tensors="pt")
|
>>> inputs = processor(images=image, text=prompt, return_tensors="pt")
|
||||||
|
|
||||||
>>> # Generate
|
>>> # Generate
|
||||||
>>> generate_ids = model.generate(**inputs, max_length=30)
|
>>> generate_ids = model.generate(**inputs,)
|
||||||
>>> processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
>>> processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
||||||
"answer en Where is the cow standing?\nbeach"
|
"Where is the cat standing?\nsnow"
|
||||||
```"""
|
```"""
|
||||||
|
|
||||||
if (input_ids is None) ^ (inputs_embeds is not None):
|
if (input_ids is None) ^ (inputs_embeds is not None):
|
||||||
|
|||||||
Reference in New Issue
Block a user