File size: 12,939 Bytes
e158b55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b16d75f
 
 
 
e158b55
 
fd1dd45
 
b16d75f
 
 
 
e158b55
b16d75f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
597a3e1
 
 
 
 
 
 
 
b16d75f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3036fa
b16d75f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e158b55
 
 
 
b16d75f
 
 
 
 
 
 
 
 
 
c93d198
 
b16d75f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60b70ab
b16d75f
 
 
 
 
 
 
6eeaadf
 
 
 
597a3e1
 
 
6eeaadf
 
b16d75f
 
 
 
 
6eeaadf
fd1dd45
 
 
 
 
 
 
 
6eeaadf
fd1dd45
b16d75f
 
 
 
 
 
 
 
6eeaadf
b16d75f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e158b55
b16d75f
 
 
 
 
 
 
 
60b70ab
b16d75f
 
 
 
 
 
 
 
60b70ab
b16d75f
 
 
 
 
 
 
 
 
c93d198
b16d75f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e158b55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />

    <!-- Bootstrap CSS -->
    <link
      href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
      rel="stylesheet"
      integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
      crossorigin="anonymous"
    />

    <script
      src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
      integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
      crossorigin="anonymous"
    ></script>

    <link rel="stylesheet" href="style.css" type="text/css" />

    <script
      type="module"
      src="https://display.truepic.com/truepic_display.es.js"
    ></script>
  </head>
  <body>
    <div class="container-fluid mt-2" id="head">
      <div class="container">
        <div class="row">
          <div class="col position-relative">
            <div class="row">
              <div class="col">
                <h1>
                  Title of Space
                  <div class="badge bg-secondary">experimental</div>
                </h1>
                <p>
                  Brief intro explaining the high level concept of this tool.
                  Eget consequat at proin sed dolor morbi urna. Quam aliquam
                  imperdiet est lobortis lectus sit vel.
                </p>
              </div>
            </div>
            <div class="d-flex flex-row position-absolute bottom-0 tabs">
              <div id="generateTab" class="active">
                <img src="images/generate_icon.svg" /> Generate
              </div>
              <div id="verifyTab">
                <img src="images/verify_icon.svg" /> Verify
              </div>
            </div>
          </div>
          <div class="col right-column">
            <div class="alert alert-secondary" role="alert">
              <h4>Support our work!</h4>
              <p>Like this Space in the nav above</p>
              <p>Joining the conversation in the Community tab</p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="container-fluid" id="body">
      <div class="container">
        <div class="row">
          <div class="col">
            <div class="display-generate">
              <div class="image-container">
                <img src="images/placeholder.png" id="placeholder" />
                <img
                  src="images/spinner.svg"
                  id="spinner"
                  style="display: none"
                />
              </div>
            </div>
            <div class="display-verify">
              <p>Contains Credentials: <span id="contentCredentialResults"></span></p>
              <p>Digital Watermark: <span id="digitalWatermarkResults"></span></p>
              <p>Original Media: <span id="originalMedia"></span></p>
              <!--
                <div class="image-container">

                </div>
              -->
            </div>
          </div>
          <div class="col right-column">
            <div class="display-generate">
              <form class="image-gen-form">
                <div class="form-group mb-3">
                  <label for="prompt">Image prompt</label>
                  <textarea id="prompt" class="form-control"></textarea>
                </div>

                <div class="form-group mb-3">
                  <label>Model</label>
                  <div class="custom-select">
                    <select id="model" class="form-control">
                      <option disabled selected value>Select</option>
                      <option value="runwayml/stable-diffusion-v1-5,1.5">
                        runwayml/stable-diffusion-v1-5
                      </option>
                      <option value="CompVis/stable-diffusion-v1-4,1.4">
                        CompVis/stable-diffusion-v1-4
                      </option>
                      <option value="stabilityai/stable-diffusion-2-1,2.1">
                        stabilityai/stable-diffusion-2-1
                      </option>
                    </select>
                  </div>
                </div>

                <div class="form-check mb-3">
                  <input
                    class="form-check-input"
                    type="checkbox"
                    value=""
                    id="terms"
                  />
                  <label class="form-check-label" for="defaultCheck1">
                    By using this demo you agree to the
                    <a href="#">Terms and Conditions of Truepic and Steg.AI</a>
                  </label>
                </div>

                <button type="submit" class="btn btn-primary">Submit</button>
              </form>

              <h3>How it works</h3>

              <p>
                Images are generated using a hosted model and AI disclosure is
                added to the file. This information, referred to as Content
                Credentials, serves as a nutrition label for the content. We
                employ the tamper-evident open C2PA standard, which utilizes PKI
                and is resistant to forgery. You can download and transfer the
                image to supported editing tools like Photoshop, where your edit
                history can also be securely added to the file. This historical
                information, known as provenance, accompanies your media and can
                be extracted and displayed using a tool or website.
              </p>
              <p>Want to know more? Read our community blog post.</p>
            </div>
            <div class="display-verify">
              <form class="verify-upload-form" enctype="multipart/form-data">
                <div class="form-group mb-3">
                  <label>Upload image</label>
                  <div class="custom-select">
                    <input type="file" class="form-control" name="fileUpload" id="fileUpload" />
                  </div>
                </div>

                <div class="form-check mb-3">
                  <input
                    class="form-check-input"
                    type="checkbox"
                    value=""
                    id="terms"
                  />
                  <label class="form-check-label" for="defaultCheck1">
                    By using this demo you agree to the
                    <a href="#">Terms and Conditions of Truepic and Steg.AI</a>
                  </label>
                </div>

                <button type="submit" class="btn btn-primary">Submit</button>
              </form>

              <h3>How it works</h3>

              <p>
                Images are generated using a hosted model and AI disclosure is
                added to the file. This information, referred to as Content
                Credentials, serves as a nutrition label for the content. We
                employ the tamper-evident open C2PA standard, which utilizes PKI
                and is resistant to forgery. You can download and transfer the
                image to supported editing tools like Photoshop, where your edit
                history can also be securely added to the file. This historical
                information, known as provenance, accompanies your media and can
                be extracted and displayed using a tool or website.
              </p>
              <p>Want to know more? Read our community blog post.</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </body>

  <script>
    const generateTab = document.querySelector("#generateTab");
    const verifyTab = document.querySelector("#verifyTab");
    const displayVerify = document.querySelectorAll(".display-verify");
    const displayGenerate = document.querySelectorAll(".display-generate");
    const uploadForm = document.querySelector(".verify-upload-form");
    const imageGenForm = document.querySelector(".image-gen-form");
    const placeholder = document.getElementById("placeholder");
    const spinner = document.getElementById("spinner");
    const imagePrompt = document.getElementById("prompt");
    const model = document.getElementById("model");
    const generateImageContainer = document.querySelector(".display-generate .image-container");
    

    generateTab.addEventListener("click", (event) => {
      event.target.classList.add("active");
      verifyTab.classList.remove("active");

      setGenerateElementsDisplay("block");
      setVerifyElementsDisplay("none");
    });

    verifyTab.addEventListener("click", (event) => {
      event.target.classList.add("active");
      generateTab.classList.remove("active");

      setGenerateElementsDisplay("none");
      setVerifyElementsDisplay("block");
    });

    function setGenerateElementsDisplay(displayStatus) {
      displayGenerate.forEach((item) => {
        item.style.display = displayStatus;
      });
    }

    function setVerifyElementsDisplay(displayStatus) {
      displayVerify.forEach((item) => {
        item.style.display = displayStatus;
      });
    }

    uploadForm.addEventListener("submit", (e) => {
      e.preventDefault();
      submitForm();
    });

    function submitForm() {
      const formData = new FormData(uploadForm);

      // Add additional form data as needed
      //formData.append('additionalData', 'additionalValue');

      // Call function to submit form data
      submitFormData(formData);
    }

    function submitFormData(formData) {
      fetch("verify", {
        method: "POST",
        body: formData,
      })
        .then((response) => response.json())
        .then((data) => {
          console.log(data);

          console.log("contains_c2pa", data.contains_c2pa);
          console.log("contains_watermark", data.contains_watermark);
          console.log("original_media", data.original_media);

          document.getElementById("contentCredentialResults").innerHTML =  data.contains_c2pa;
          document.getElementById("digitalWatermarkResults").innerHTML =  data.contains_watermark;
          document.getElementById("originalMedia").innerHTML =  data.original_media;

/*
          const path = "/" + data.response;

          var resultsContainer = document.getElementById("image-container");

          var truepicDisplay = document.createElement("truepic-display");
          
    truepicDisplay.addEventListener(
      "validate",
      setVerificationOutputFromValidation
    );
    truepicDisplay.addEventListener(
      "validate",
      setCertificateOutputFromValidation
    );
    

          truepicDisplay.setAttribute("id", "result");
          truepicDisplay.setAttribute("active", "");
          var truepic = document.createElement("img");
          truepic.src = path;

          truepicDisplay.appendChild(truepic);

          resultsContainer.appendChild(truepicDisplay);
          */
          // Handle response data
        })
        .catch((error) => {
          console.log(error);
          // Handle errors
        });
    }

    const generateImage = async (text, model) => {
      const inferResponse = await fetch(
        `generate?prompt=${text}&model=${model}`
      );
      const inferJson = await inferResponse.json();

      return inferJson.response;
    };

    imageGenForm.addEventListener("submit", async (event) => {
      event.preventDefault();

      // verificationDetails.style.display = "none";
      // parameters.style.display = "none";
      // downloadLink.style.display = "none";

      try {
        if (placeholder) placeholder.remove();

        if (document.getElementById("result"))
          document.getElementById("result").remove();
        spinner.style.display = "block";

        const resp = await generateImage(imagePrompt.value, model.value);
        const path = "/" + resp;

        var truepicDisplay = document.createElement("truepic-display");
        /*
        truepicDisplay.addEventListener(
          "validate",
          setVerificationOutputFromValidation
        );
        truepicDisplay.addEventListener(
          "validate",
          setCertificateOutputFromValidation
        );
        */

        truepicDisplay.setAttribute("id", "result");
        truepicDisplay.setAttribute("active", "");
        var truepic = document.createElement("img");
        truepic.src = path;

        truepicDisplay.appendChild(truepic);

        spinner.style.display = "none";
        generateImageContainer.appendChild(truepicDisplay);

        /*
    downloadLink.style.display = "block";
    downloadLink.href = path;
    downloadLink.download = resp;

    modelParam.innerHTML = model.value;
    promptParam.innerHTML = textGenInput.value;
    parameters.style.display = "block";
    */
      } catch (err) {
        console.error(err);
      }
    });
  </script>
</html>