Skip to content

Commit 33d70cf

Browse files
author
Richard Kennedy
committed
Update terminology to use Content Credentials instead of C2PA
1 parent 3560d57 commit 33d70cf

File tree

5 files changed

+65
-35
lines changed

5 files changed

+65
-35
lines changed

src/stability_sdk/api.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def generate(
122122
guidance_strength: float = 0.0,
123123
preset: Optional[str] = None,
124124
return_request: bool = False,
125-
c2pa_add_default_manifest: bool = False,
125+
content_credentials_add_default: bool = False,
126126
) -> Dict[int, List[Any]]:
127127
"""
128128
Generate an image from a set of weighted prompts.
@@ -165,7 +165,7 @@ def generate(
165165
start_schedule = 1.0 - init_strength
166166
image_params = self._build_image_params(width, height, sampler, steps, seed, samples, cfg_scale,
167167
start_schedule, init_noise_scale, masked_area_init,
168-
guidance_preset, guidance_cuts, guidance_strength, c2pa_add_default_manifest)
168+
guidance_preset, guidance_cuts, guidance_strength, content_credentials_add_default)
169169

170170
extras = Struct()
171171
if preset and preset.lower() != 'none':
@@ -236,7 +236,7 @@ def inpaint(
236236
start_schedule = 1.0-init_strength
237237
image_params = self._build_image_params(width, height, sampler, steps, seed, samples, cfg_scale,
238238
start_schedule, init_noise_scale, masked_area_init,
239-
guidance_preset, guidance_cuts, guidance_strength, c2pa_add_default_manifest=False)
239+
guidance_preset, guidance_cuts, guidance_strength, ccontent_credentials_add_default=False)
240240

241241
extras = Struct()
242242
if preset and preset.lower() != 'none':
@@ -539,7 +539,7 @@ def _adjust_request_for_retry(self, request: generation.Request, attempt: int):
539539

540540
def _build_image_params(self, width, height, sampler, steps, seed, samples, cfg_scale,
541541
schedule_start, init_noise_scale, masked_area_init,
542-
guidance_preset, guidance_cuts, guidance_strength, c2pa_add_default_manifest):
542+
guidance_preset, guidance_cuts, guidance_strength, ccontent_credentials_add_default):
543543

544544
if not seed:
545545
seed = [random.randrange(0, 4294967295)]
@@ -569,11 +569,11 @@ def _build_image_params(self, width, height, sampler, steps, seed, samples, cfg_
569569
)
570570
]
571571
)
572-
# empty C2PA Parameters will result in images not being signed by the C2PA server
573-
c2pa_params = generation.C2PAParameters()
574-
if c2pa_add_default_manifest:
575-
c2pa_params = generation.C2PAParameters(
576-
model_metadata=generation._C2PAPARAMETERS_MODELMETADATA.values_by_name[
572+
# empty Content Credentials Parameters will result in images not being signed by the Content Credentials server
573+
content_credentials_params = generation.ContentCredentialsParameters()
574+
if ccontent_credentials_add_default:
575+
content_credentials_params = generation.ContentCredentialsParameters(
576+
model_metadata=generation._CONTENTCREDENTIALSPARAMETERS_MODELMETADATA.values_by_name[
577577
'MODEL_METADATA_SIGN_WITH_ENGINE_ID'].number)
578578

579579
return generation.ImageParameters(
@@ -585,7 +585,7 @@ def _build_image_params(self, width, height, sampler, steps, seed, samples, cfg_
585585
samples=samples,
586586
masked_area_init=masked_area_init,
587587
parameters=[generation.StepParameter(**step_parameters)],
588-
c2pa_parameters=c2pa_params
588+
content_credentials_parameters=content_credentials_params
589589
)
590590

591591
def _process_response(self, response) -> Dict[int, List[Any]]:

src/stability_sdk/client.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def generate(
171171
guidance_strength: Optional[float] = None,
172172
guidance_prompt: Union[str, generation.Prompt] = None,
173173
guidance_models: List[str] = None,
174-
c2pa_add_default_manifest: bool = False,
174+
content_credentials_add_default: bool = False,
175175
) -> Generator[generation.Answer, None, None]:
176176
"""
177177
Generate images from a prompt.
@@ -195,7 +195,7 @@ def generate(
195195
:param guidance_strength: Strength of the guidance. We recommend values in range [0.0,1.0]. A good default is 0.25
196196
:param guidance_prompt: Prompt to use for guidance, defaults to `prompt` argument (above) if not specified.
197197
:param guidance_models: Models to use for guidance.
198-
:param c2pa_add_default_manifest: Add default C2PA manifest or not.
198+
:param content_credentials_add_default: Add default Content Credentials or not.
199199
:return: Generator of Answer objects.
200200
"""
201201
if (prompt is None) and (init_image is None):
@@ -280,11 +280,11 @@ def generate(
280280
if sampler:
281281
transform=generation.TransformType(diffusion=sampler)
282282

283-
# empty C2PA Parameters will result in images not being signed by the C2PA server
284-
c2pa_params = generation.C2PAParameters()
285-
if c2pa_add_default_manifest:
286-
c2pa_params = generation.C2PAParameters(
287-
model_metadata=generation._C2PAPARAMETERS_MODELMETADATA.values_by_name[
283+
# empty Content Credential Parameters will result in images not being signed by the Content Credential server
284+
content_credentials_params = generation.ContentCredentialsParameters()
285+
if content_credentials_add_default:
286+
content_credentials_params = generation.ContentCredentialsParameters(
287+
model_metadata=generation._CONTENTCREDENTIALSPARAMETERS_MODELMETADATA.values_by_name[
288288
'MODEL_METADATA_SIGN_WITH_ENGINE_ID'].number)
289289

290290
image_parameters=generation.ImageParameters(
@@ -295,7 +295,7 @@ def generate(
295295
steps=steps,
296296
samples=samples,
297297
parameters=[generation.StepParameter(**step_parameters)],
298-
c2pa_parameters=c2pa_params,
298+
content_credentials_parameters=content_credentials_params,
299299
)
300300

301301
return self.emit_request(prompt=prompts, image_parameters=image_parameters)
@@ -509,7 +509,7 @@ def process_cli(logger: logging.Logger = None,
509509
"--width", "-W", type=int, default=512, help="[512] width of image"
510510
)
511511
parser_generate.add_argument(
512-
"--c2pa_add_default_manifest", type=bool, action='store_true', default=False, help="Attatch a signed manifest to artifacts using C2PA. The default manifest will contain engine id and publisher name (Stability AI)"
512+
"--content_credentials_add_default", type=bool, action='store_true', default=False, help="Attatch a signed manifest to artifacts using C2PA. The default manifest will contain engine id and publisher name (Stability AI)"
513513
)
514514
parser_generate.add_argument(
515515
"--start_schedule",
@@ -644,7 +644,7 @@ def process_cli(logger: logging.Logger = None,
644644
"samples": args.num_samples,
645645
"init_image": args.init_image,
646646
"mask_image": args.mask_image,
647-
"c2pa_add_default_manifest": args.c2pa_add_default_manifest,
647+
"content_credentials_add_default": args.content_credentials_add_default,
648648
}
649649

650650
if args.sampler:

tests/test_api.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,27 @@ def test_api_generate():
9999
assert isinstance(image, Image.Image)
100100
assert image.size == (width, height)
101101

102-
def test_api_generate_c2pa_signing_set():
103-
class C2PAMockStub(MockStub):
102+
def test_api_generate_content_credentials_signing_set():
103+
class ContentCredentialsMockStub(MockStub):
104104
def Generate(self, request: generation.Request, **kwargs) -> Generator[generation.Answer, None, None]:
105-
assert request.image.c2pa_parameters.model_metadata == \
106-
generation._C2PAPARAMETERS_MODELMETADATA.values_by_name['MODEL_METADATA_SIGN_WITH_ENGINE_ID'].number
105+
assert request.image.content_credentials_parameters.model_metadata == \
106+
generation._CONTENTCREDENTIALSPARAMETERS_MODELMETADATA.values_by_name['MODEL_METADATA_SIGN_WITH_ENGINE_ID'].number
107107
return super().Generate(request, **kwargs)
108-
api = Context(stub=C2PAMockStub())
108+
api = Context(stub=ContentCredentialsMockStub())
109109
width, height = 512, 768
110-
results = api.generate(prompts=["foo bar"], weights=[1.0], width=width, height=height, c2pa_add_default_manifest=True)
110+
results = api.generate(prompts=["foo bar"], weights=[1.0], width=width, height=height, content_credentials_add_default=True)
111111

112-
def test_api_generate_c2pa_signing_unset():
113-
class C2PAMockStub(MockStub):
112+
def test_api_generate_content_credentials_signing_unset():
113+
class ContentCredentialsMockStub(MockStub):
114114
def Generate(self, request: generation.Request, **kwargs) -> Generator[generation.Answer, None, None]:
115-
assert request.image.c2pa_parameters.model_metadata == \
116-
generation._C2PAPARAMETERS_MODELMETADATA.values_by_name['MODEL_METADATA_UNSPECIFIED'].number
115+
assert request.image.content_credentials_parameters.model_metadata == \
116+
generation._CONTENTCREDENTIALSPARAMETERS_MODELMETADATA.values_by_name['MODEL_METADATA_UNSPECIFIED'].number
117117
return super().Generate(request, **kwargs)
118-
api = Context(stub=C2PAMockStub())
118+
api = Context(stub=ContentCredentialsMockStub())
119119
width, height = 512, 768
120-
# sign_with_c2pa should default to false.
120+
# content_credentials_add_default should default to false.
121121
results = api.generate(prompts=["foo bar"], weights=[1.0], width=width, height=height)
122122

123-
124123
def test_api_inpaint():
125124
api = Context(stub=MockStub())
126125
width, height = 512, 768

tests/test_client.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,40 @@
11
from PIL import Image
2-
from typing import Generator
2+
from google.protobuf.struct_pb2 import Struct
3+
from typing import Generator, Optional
34

45
from stability_sdk import client
56
from stability_sdk.api import generation
67

8+
class TestStabilityInferenceImageParameters(client.StabilityInference):
9+
def emit_request(
10+
self,
11+
prompt: generation.Prompt,
12+
image_parameters: generation.ImageParameters,
13+
extra_parameters: Optional[Struct] = None,
14+
engine_id: str = None,
15+
request_id: str = None,
16+
):
17+
return image_parameters
18+
19+
20+
def test_content_credentials_not_set():
21+
class_instance = TestStabilityInferenceImageParameters(
22+
host='foo.bar.baz', key='thisIsNotARealKey')
23+
image_params = class_instance.generate(prompt="foo bar")
24+
25+
assert image_params.content_credentials_parameters.model_metadata == \
26+
generation._CONTENTCREDENTIALSPARAMETERS_MODELMETADATA.values_by_name[
27+
'MODEL_METADATA_UNSPECIFIED'].number
28+
29+
def test_content_credentials_set():
30+
class_instance = TestStabilityInferenceImageParameters(
31+
host='foo.bar.baz', key='thisIsNotARealKey')
32+
image_params = class_instance.generate(prompt="foo bar",
33+
content_credentials_add_default=True)
34+
35+
assert image_params.content_credentials_parameters.model_metadata == \
36+
generation._CONTENTCREDENTIALSPARAMETERS_MODELMETADATA.values_by_name[
37+
'MODEL_METADATA_SIGN_WITH_ENGINE_ID'].number
738

839
def test_StabilityInference_init():
940
_ = client.StabilityInference(key='thisIsNotARealKey')

0 commit comments

Comments
 (0)