|
21 | 21 | from ... import types |
22 | 22 | from .. import pytest_helper |
23 | 23 |
|
24 | | -PRODUCT_RECONTEXT_MODEL_LATEST = 'imagen-product-recontext-preview-06-30' |
25 | | - |
26 | 24 | VIRTUAL_TRY_ON_IMAGE_MODEL_LATEST = 'virtual-try-on-001' |
27 | 25 |
|
28 | | -BACKPACK1 = types.Image( |
29 | | - gcs_uri='gs://genai-sdk-tests/inputs/images/backpack1.png', |
30 | | -) |
31 | | - |
32 | | -BACKPACK2 = types.Image( |
33 | | - gcs_uri='gs://genai-sdk-tests/inputs/images/backpack2.png', |
34 | | -) |
35 | | - |
36 | | -BACKPACK3 = types.Image( |
37 | | - gcs_uri='gs://genai-sdk-tests/inputs/images/backpack3.png', |
38 | | -) |
39 | | - |
40 | 26 | PERSON_IMAGE = types.Image( |
41 | 27 | gcs_uri='gs://genai-sdk-tests/inputs/images/man.jpg', |
42 | 28 | ) |
|
46 | 32 | ) |
47 | 33 |
|
48 | 34 | test_table: list[pytest_helper.TestTableItem] = [ |
49 | | - pytest_helper.TestTableItem( |
50 | | - name='test_product_recontext', |
51 | | - exception_if_mldev='only supported in the Vertex AI client', |
52 | | - parameters=types._RecontextImageParameters( |
53 | | - model=PRODUCT_RECONTEXT_MODEL_LATEST, |
54 | | - source=types.RecontextImageSource( |
55 | | - prompt='On a school desk', |
56 | | - product_images=[ |
57 | | - types.ProductImage(product_image=BACKPACK1) |
58 | | - ], |
59 | | - ), |
60 | | - config=types.RecontextImageConfig( |
61 | | - number_of_images=1, |
62 | | - add_watermark=True, |
63 | | - output_mime_type='image/jpeg', |
64 | | - ), |
65 | | - ), |
66 | | - ), |
67 | | - pytest_helper.TestTableItem( |
68 | | - name='test_product_recontext_all_config', |
69 | | - exception_if_mldev='only supported in the Vertex AI client', |
70 | | - parameters=types._RecontextImageParameters( |
71 | | - model=PRODUCT_RECONTEXT_MODEL_LATEST, |
72 | | - source=types.RecontextImageSource( |
73 | | - prompt='On a school desk', |
74 | | - product_images=[ |
75 | | - types.ProductImage( |
76 | | - product_image=BACKPACK1, |
77 | | - ), |
78 | | - types.ProductImage( |
79 | | - product_image=BACKPACK2, |
80 | | - ), |
81 | | - types.ProductImage( |
82 | | - product_image=BACKPACK3, |
83 | | - ), |
84 | | - ], |
85 | | - ), |
86 | | - config=types.RecontextImageConfig( |
87 | | - number_of_images=1, |
88 | | - output_mime_type='image/jpeg', |
89 | | - base_steps=32, |
90 | | - seed=1337, |
91 | | - add_watermark=False, |
92 | | - safety_filter_level=types.SafetyFilterLevel.BLOCK_MEDIUM_AND_ABOVE, |
93 | | - person_generation=types.PersonGeneration.ALLOW_ADULT, |
94 | | - output_compression_quality=75, |
95 | | - enhance_prompt=False, |
96 | | - labels={'imagen_label_key': 'recontext_image'} |
97 | | - ), |
98 | | - ), |
99 | | - ), |
100 | 35 | pytest_helper.TestTableItem( |
101 | 36 | name='test_virtual_try_on', |
102 | 37 | exception_if_mldev='only supported in the Vertex AI client', |
|
149 | 84 | ) |
150 | 85 |
|
151 | 86 |
|
152 | | -@pytest.mark.asyncio |
153 | | -async def test_product_recontext_async(client): |
154 | | - with pytest_helper.exception_if_mldev(client, ValueError): |
155 | | - response = await client.aio.models.recontext_image( |
156 | | - model=PRODUCT_RECONTEXT_MODEL_LATEST, |
157 | | - source=types.RecontextImageSource( |
158 | | - prompt='On a school desk', |
159 | | - product_images=[ |
160 | | - types.ProductImage(product_image=BACKPACK1) |
161 | | - ], |
162 | | - ), |
163 | | - config=types.RecontextImageConfig( |
164 | | - number_of_images=1, |
165 | | - output_mime_type='image/jpeg', |
166 | | - ) |
167 | | - ) |
168 | | - assert len(response.generated_images) == 1 |
169 | | - assert response.generated_images[0].image.image_bytes |
170 | | - |
171 | | - |
172 | 87 | @pytest.mark.asyncio |
173 | 88 | async def test_virtual_try_on_async(client): |
174 | 89 | with pytest_helper.exception_if_mldev(client, ValueError): |
|
0 commit comments