milyiyo commited on
Commit
c4fdf8d
·
1 Parent(s): 97f8d6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -32
app.py CHANGED
@@ -1,30 +1,11 @@
1
  import gradio as gr
2
- #from diffusers import DiffusionPipeline
3
  from diffusers import LDMTextToImagePipeline
4
  import torch
5
  import numpy as np
6
  import PIL
7
  import cv2
8
 
9
- # -----------------
10
- #import os
11
- #print('\nDEBUG: Cloning diffusers project')
12
- #os.system('git clone https://github.com/huggingface/diffusers')
13
-
14
- #print('\nDEBUG: Pwd')
15
- #os.system('pwd')
16
- #os.system('ls -la')
17
-
18
- #print('\nDEBUG: Install dependencies of diffusers')
19
- #os.system('cd diffusers && pip install -e .')
20
-
21
- #print('\nDEBUG: Pip install from the build of diffusers')
22
- #os.system('pip install git+file:///home/user/app/diffusers')
23
-
24
- #from diffusers import DiffusionPipeline
25
- # -----------------
26
-
27
- print('\nDEBUG: Version: 2')
28
 
29
  #pipeline = LDMTextToImagePipeline.from_pretrained("fusing/latent-diffusion-text2im-large")
30
  pipeline = LDMTextToImagePipeline.from_pretrained("CompVis/ldm-text2im-large-256")
@@ -36,19 +17,23 @@ def greet(name):
36
  return "Hello " + name + "!!"
37
 
38
  def genimage(prompt, iterations):
39
- image = pipeline([prompt], generator=generator, eta=0.3, guidance_scale=6.0, num_inference_steps=iterations)
 
40
 
41
- image_processed = image.cpu().permute(0, 2, 3, 1)
42
- image_processed = image_processed * 255.
43
- image_processed = image_processed.numpy().astype(np.uint8)
44
- image_pil = PIL.Image.fromarray(image_processed[0])
45
 
46
  # save image
47
- file_name = "test.png"
48
- image_pil.save(file_name)
49
- img = cv2.imread(file_name)
50
- #cv2_imshow(img)
51
- return img
52
-
53
- iface = gr.Interface(fn=genimage, inputs=["text", "number"], outputs="image")
 
 
 
54
  iface.launch()
 
1
  import gradio as gr
 
2
  from diffusers import LDMTextToImagePipeline
3
  import torch
4
  import numpy as np
5
  import PIL
6
  import cv2
7
 
8
+ print('\nDEBUG: Version: 3')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  #pipeline = LDMTextToImagePipeline.from_pretrained("fusing/latent-diffusion-text2im-large")
11
  pipeline = LDMTextToImagePipeline.from_pretrained("CompVis/ldm-text2im-large-256")
 
17
  return "Hello " + name + "!!"
18
 
19
  def genimage(prompt, iterations):
20
+ image = pipeline([prompt], generator=generator, eta=0.3, guidance_scale=6.0, num_inference_steps=iterations)["sample"]
21
+ return image[0]
22
 
23
+ #image_processed = image.cpu().permute(0, 2, 3, 1)
24
+ #image_processed = image_processed * 255.
25
+ #image_processed = image_processed.numpy().astype(np.uint8)
26
+ #image_pil = PIL.Image.fromarray(image_processed[0])
27
 
28
  # save image
29
+ #file_name = "test.png"
30
+ #image_pil.save(file_name)
31
+ #img = cv2.imread(file_name)
32
+ ##cv2_imshow(img)
33
+ #return img
34
+
35
+ iface = gr.Interface(
36
+ fn=genimage,
37
+ inputs=["text", "number"],
38
+ outputs=gr.Image(shape=[256,256], type="pil", elem_id="output_image"))
39
  iface.launch()