jclyo1 commited on
Commit
e79973b
·
1 Parent(s): 0ee138d
Files changed (4) hide show
  1. main.py +41 -22
  2. static/index.html +4 -0
  3. static/script.js +8 -0
  4. static/style.css +7 -0
main.py CHANGED
@@ -8,49 +8,68 @@ import json
8
  import uuid
9
 
10
  import torch
11
- from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler, EulerDiscreteScheduler
 
 
 
 
 
 
12
 
13
- app = FastAPI()
14
 
15
  @app.get("/generate")
16
  def generate_image(prompt, model):
17
  torch.cuda.empty_cache()
18
 
19
- pipeline = StableDiffusionPipeline.from_pretrained(str(model), torch_dtype=torch.float16)
 
 
20
  pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config)
21
  pipeline = pipeline.to("cuda")
22
-
23
  image = pipeline(prompt, num_inference_steps=50, height=512, width=512).images[0]
24
 
25
  filename = str(uuid.uuid4()) + ".jpg"
26
  image.save(filename)
27
-
28
  assertion = {
29
- "assertions": [
30
- {
31
- "label": "com.truepic.custom.ai",
32
- "data": {
33
- "model_name": model,
34
- "model_version": "1.0",
35
- "prompt": prompt
36
- }
37
- }
38
- ]
39
- }
40
 
41
  json_object = json.dumps(assertion)
42
- # with open("assertion.json", "w") as outfile:
43
- # outfile.write(json_object)
44
 
45
- subprocess.check_output(['./truepic-sign', 'init', 'file-system', '--api-key', os.environ.get("api_key")])
46
- # subprocess.check_output(['./truepic-sign', 'sign', filename, '--assertions-file', 'assertion.json', '--output', (os.getcwd() + '/static/' + filename)])
47
- subprocess.check_output(['./truepic-sign', 'sign', filename, '--assertions', json_object, '--output', (os.getcwd() + '/static/' + filename)])
48
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  return {"response": filename}
50
 
51
 
52
  app.mount("/", StaticFiles(directory="static", html=True), name="static")
53
 
 
54
  @app.get("/")
55
  def index() -> FileResponse:
56
  return FileResponse(path="/app/static/index.html", media_type="text/html")
 
8
  import uuid
9
 
10
  import torch
11
+ from diffusers import (
12
+ StableDiffusionPipeline,
13
+ DPMSolverMultistepScheduler,
14
+ EulerDiscreteScheduler,
15
+ )
16
+
17
+ app = FastAPI()
18
 
 
19
 
20
  @app.get("/generate")
21
  def generate_image(prompt, model):
22
  torch.cuda.empty_cache()
23
 
24
+ pipeline = StableDiffusionPipeline.from_pretrained(
25
+ str(model), torch_dtype=torch.float16
26
+ )
27
  pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config)
28
  pipeline = pipeline.to("cuda")
29
+
30
  image = pipeline(prompt, num_inference_steps=50, height=512, width=512).images[0]
31
 
32
  filename = str(uuid.uuid4()) + ".jpg"
33
  image.save(filename)
34
+
35
  assertion = {
36
+ "assertions": [
37
+ {
38
+ "label": "com.truepic.custom.ai",
39
+ "data": {"model_name": model, "model_version": "1.0", "prompt": prompt},
40
+ }
41
+ ]
42
+ }
 
 
 
 
43
 
44
  json_object = json.dumps(assertion)
 
 
45
 
46
+ subprocess.check_output(
47
+ [
48
+ "./truepic-sign",
49
+ "init",
50
+ "file-system",
51
+ "--api-key",
52
+ os.environ.get("api_key"),
53
+ ]
54
+ )
55
+ subprocess.check_output(
56
+ [
57
+ "./truepic-sign",
58
+ "sign",
59
+ filename,
60
+ "--assertions",
61
+ json_object,
62
+ "--output",
63
+ (os.getcwd() + "/static/" + filename),
64
+ ]
65
+ )
66
+
67
  return {"response": filename}
68
 
69
 
70
  app.mount("/", StaticFiles(directory="static", html=True), name="static")
71
 
72
+
73
  @app.get("/")
74
  def index() -> FileResponse:
75
  return FileResponse(path="/app/static/index.html", media_type="text/html")
static/index.html CHANGED
@@ -35,6 +35,10 @@
35
  </div>
36
  <a href="#" target="_blank" id="download-link"><img src="images/download.png" id="download" /></a>
37
  </div>
 
 
 
 
38
  </div>
39
  <section class="verification-details">
40
  <nav>
 
35
  </div>
36
  <a href="#" target="_blank" id="download-link"><img src="images/download.png" id="download" /></a>
37
  </div>
38
+ <div class="parameters">
39
+ Image prompt: “<span class="prompt">dog on a swing</span>”<br/>
40
+ Model: <span class="model">stabilityai/stable-diffusion-xl-base-1.0</span>
41
+ </div>
42
  </div>
43
  <section class="verification-details">
44
  <nav>
static/script.js CHANGED
@@ -11,6 +11,10 @@ const certificateNav = document.getElementById('certificate-nav');
11
  const verificationOutput = document.getElementById('verification-output');
12
  const certificateOutput = document.getElementById('certificate-output');
13
  const verificationDetails = document.querySelector('.verification-details');
 
 
 
 
14
 
15
 
16
  [textGenInput, model].forEach(item => {
@@ -66,6 +70,10 @@ textGenForm.addEventListener('submit', async (event) => {
66
  downloadLink.style.display = "block";
67
  downloadLink.href = path;
68
  downloadLink.download = resp;
 
 
 
 
69
  } catch (err) {
70
  console.error(err);
71
  }
 
11
  const verificationOutput = document.getElementById('verification-output');
12
  const certificateOutput = document.getElementById('certificate-output');
13
  const verificationDetails = document.querySelector('.verification-details');
14
+ const parameters = document.querySelector('.parameters');
15
+ const modelParam = document.querySelector('.parameters .model');
16
+ const promptParam = document.querySelector('.parameters .prompt');
17
+
18
 
19
 
20
  [textGenInput, model].forEach(item => {
 
70
  downloadLink.style.display = "block";
71
  downloadLink.href = path;
72
  downloadLink.download = resp;
73
+
74
+ modelParam.innerHTML = model.value;
75
+ promptParam.innerHTML = textGenInput.value;
76
+ parameters.style.display = "block";
77
  } catch (err) {
78
  console.error(err);
79
  }
static/style.css CHANGED
@@ -52,6 +52,13 @@ textarea {
52
  border-bottom: 1px solid rgba(227, 234, 240, 1);
53
  }
54
 
 
 
 
 
 
 
 
55
  #logo {
56
  width: 156px;
57
  padding: 2rem 10rem;
 
52
  border-bottom: 1px solid rgba(227, 234, 240, 1);
53
  }
54
 
55
+ #column-one .container .parameters {
56
+ display: none;
57
+ color: rgba(86, 104, 122, 1);
58
+ font-size: 12px;
59
+ padding-bottom: 2rem;
60
+ }
61
+
62
  #logo {
63
  width: 156px;
64
  padding: 2rem 10rem;