jclyo1 commited on
Commit
5973045
1 Parent(s): d39afe7
Files changed (3) hide show
  1. main.py +19 -18
  2. static/index.html +0 -9
  3. static/script.js +5 -6
main.py CHANGED
@@ -13,37 +13,38 @@ from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler, Eule
13
  app = FastAPI()
14
 
15
  @app.get("/generate")
16
- def generate_image(prompt, inference_steps, 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=int(inference_steps), 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, indent=4)
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
 
48
  return {"response": filename}
49
 
 
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, indent=4)
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', assertion, '--output', (os.getcwd() + '/static/' + filename)])
48
 
49
  return {"response": filename}
50
 
static/index.html CHANGED
@@ -57,15 +57,6 @@
57
  id="text-gen-input"
58
  ></textarea>
59
 
60
- <label>Inference Steps: </label>
61
- <select id="inference_steps">
62
- <option disabled selected value>Select</option>
63
- <option value="50">50</option>
64
- <option value="20">20</option>
65
- <option value="10">10</option>
66
- <option value="5">5</option>
67
- </select>
68
-
69
  <label>Model: </label>
70
  <select id="model">
71
  <option disabled selected value>Select</option>
 
57
  id="text-gen-input"
58
  ></textarea>
59
 
 
 
 
 
 
 
 
 
 
60
  <label>Model: </label>
61
  <select id="model">
62
  <option disabled selected value>Select</option>
static/script.js CHANGED
@@ -1,7 +1,6 @@
1
 
2
  const textGenForm = document.querySelector('.text-gen-form');
3
  const textGenInput = document.getElementById('text-gen-input');
4
- const inferenceSteps = document.getElementById('inference_steps');
5
  const model = document.getElementById('model');
6
  const textGenSubmit = document.getElementById('text-gen-submit');
7
  const spinner = document.getElementById('spinner');
@@ -14,21 +13,21 @@ const certificateOutput = document.getElementById('certificate-output');
14
  const verificationDetails = document.querySelector('.verification-details');
15
 
16
 
17
- [textGenInput, inferenceSteps, model].forEach(item => {
18
  item.addEventListener('change', async (event) => {
19
  setButtonStatus()
20
  });
21
  })
22
 
23
  const setButtonStatus = () => {
24
- if (textGenInput.value && inferenceSteps.value && model.value)
25
  textGenSubmit.classList.add("active");
26
  else
27
  textGenSubmit.classList.remove("active");
28
  }
29
 
30
- const generateImage = async (text, inference_steps, model) => {
31
- const inferResponse = await fetch(`generate?prompt=${text}&inference_steps=${inference_steps}&model=${model}`);
32
  const inferJson = await inferResponse.json();
33
 
34
  return inferJson.response;
@@ -45,7 +44,7 @@ textGenForm.addEventListener('submit', async (event) => {
45
  if (document.getElementById('result')) document.getElementById('result').remove();
46
  spinner.style.display = "block";
47
 
48
- const resp = await generateImage(textGenInput.value, inferenceSteps.value, model.value);
49
  const path = "/" + resp;
50
 
51
  var resultsContainer = document.getElementById('image-container');
 
1
 
2
  const textGenForm = document.querySelector('.text-gen-form');
3
  const textGenInput = document.getElementById('text-gen-input');
 
4
  const model = document.getElementById('model');
5
  const textGenSubmit = document.getElementById('text-gen-submit');
6
  const spinner = document.getElementById('spinner');
 
13
  const verificationDetails = document.querySelector('.verification-details');
14
 
15
 
16
+ [textGenInput, model].forEach(item => {
17
  item.addEventListener('change', async (event) => {
18
  setButtonStatus()
19
  });
20
  })
21
 
22
  const setButtonStatus = () => {
23
+ if (textGenInput.value && model.value)
24
  textGenSubmit.classList.add("active");
25
  else
26
  textGenSubmit.classList.remove("active");
27
  }
28
 
29
+ const generateImage = async (text, model) => {
30
+ const inferResponse = await fetch(`generate?prompt=${text}&model=${model}`);
31
  const inferJson = await inferResponse.json();
32
 
33
  return inferJson.response;
 
44
  if (document.getElementById('result')) document.getElementById('result').remove();
45
  spinner.style.display = "block";
46
 
47
+ const resp = await generateImage(textGenInput.value, model.value);
48
  const path = "/" + resp;
49
 
50
  var resultsContainer = document.getElementById('image-container');