Skip to content

Literal values in c2pa.types.X #85

@guiyrt

Description

@guiyrt

In the context of text-to-image generative models, I was looking into incorporating the ingredients c2pa.types.generator.seed and c2pa.types.generator.prompt for reproducibility. I couldn't find tests or examples for seed, so I ended up using "text/plain" for both. My questions are:

  1. Can ingredients not be associated with resources? I wanted to pass seed as 64-bit integer, for example, which doesn't need to be a resource, as it won't have a manifest to be verified (same applied to prompt text to some degree).
  2. In the manifest examples that I saw, many of them had action with the field ingredients in parameters, but I couldn't tell if that was the final generated manifest or input manifest. Can ingredients be pre-defined inside each action?
Code using Python API
import os
import io
import c2pa

# set up paths to the files we we are using
testFile = os.path.join("A.jpg")
pemFile = os.path.join("es256_certs.pem")
keyFile = os.path.join("es256_private.key")
testOutputFile = os.path.join("dnt.jpg")

# define a manifest with the do not train assertion
manifest_json = {
    "claim_generator_info": [{
        "name": "MyProgram",
        "version": "0.0.1"
    }],
    "title": "AI-generated Image",
    "assertions": [
        {
            "label": "c2pa.training-mining",
            "data": {
                "entries": {
                "c2pa.ai_generative_training": {"use": "allowed"},
                "c2pa.ai_inference": {"use": "allowed"},
                "c2pa.ai_training": {"use": "allowed"},
                "c2pa.data_mining": {"use": "allowed"}
                }
            }
        },
        {
            "label": "c2pa.actions",
            "data": {
                "actions": [
                    {
                        "action": "c2pa.created",
                        "digitalSourceType": "http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia",
                    }
                ]
            }
        }
    ],
    "ingredients": [
        {
            "title": "Prompt",
            "format": "text/plain",
            "relationship": "inputTo",
            "data": {
                "format": "text/plain",
                "identifier": "prompt",
                "data_types": [{"type": "c2pa.types.generator.prompt"}]
            }
        },
        {
            "title": "Seed",
            "format": "text/plain",
            "relationship": "inputTo",
            "data": {
                "format": "text/plain",
                "identifier": "seed",
                "data_types": [{"type": "c2pa.types.generator.seed"}]
            }
        }
    ]
}

# This could be implemented on a server using an HSM
key = open("ps256.pem","rb").read()
certs = open("ps256.pub","rb").read()

# Create a signer from a certificate pem file
builder = c2pa.Builder(manifest_json)

builder.add_resource("prompt", io.BytesIO(b"This is my prompt!"))
builder.add_resource("seed", io.BytesIO(b"42"))

if os.path.exists(testOutputFile):
    os.remove(testOutputFile)

signer = c2pa.create_signer(lambda data: c2pa.sign_ps256(data, key), c2pa.SigningAlg.PS256, certs, "http://timestamp.digicert.com")
result = builder.sign_file(signer, testFile, testOutputFile)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions