File size: 1,591 Bytes
c4bf438
63989d3
 
5dfd4ff
 
 
 
 
a2a8caa
637faa2
 
 
4630377
637faa2
 
 
4630377
637faa2
 
4630377
637faa2
 
a2a8caa
637faa2
a2a8caa
 
3a65207
 
63989d3
5dfd4ff
c4bf438
4630377
 
c4bf438
 
5dfd4ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c4bf438
5dfd4ff
c4bf438
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
import gradio as gr
#from diffusers import DiffusionPipeline
from diffusers import LDMTextToImagePipeline
import torch
import numpy as np
import PIL
import cv2

# -----------------
#import os
#print('\nDEBUG:   Cloning diffusers project')
#os.system('git clone https://github.com/huggingface/diffusers')

#print('\nDEBUG:   Pwd')
#os.system('pwd')
#os.system('ls -la')

#print('\nDEBUG:   Install dependencies of diffusers')
#os.system('cd diffusers && pip install -e .')

#print('\nDEBUG:   Pip install from the build of diffusers')
#os.system('pip install git+file:///home/user/app/diffusers')

#from diffusers import DiffusionPipeline
# -----------------

print('\nDEBUG:   Version: 1')

pipeline = LDMTextToImagePipeline.from_pretrained("fusing/latent-diffusion-text2im-large")
generator = torch.manual_seed(42)

FOOTER = '<img id="visitor-badge" alt="visitor badge" src="https://visitor-badge.glitch.me/badge?page_id=milyiyo.testing-diffusers" />'

def greet(name):
    return "Hello " + name + "!!"
    
def genimage(prompt, iterations):
  image = pipeline([prompt], generator=generator, eta=0.3, guidance_scale=6.0, num_inference_steps=iterations)

  image_processed = image.cpu().permute(0, 2, 3, 1)
  image_processed = image_processed  * 255.
  image_processed = image_processed.numpy().astype(np.uint8)
  image_pil = PIL.Image.fromarray(image_processed[0])

  # save image
  file_name = "test.png"
  image_pil.save(file_name)
  img = cv2.imread(file_name)
  #cv2_imshow(img)
  return img

iface = gr.Interface(fn=genimage, inputs=["text", "number"], outputs="image")
iface.launch()