File size: 1,484 Bytes
c4bf438
a2a8caa
5dfd4ff
 
 
 
 
a2a8caa
 
4630377
a2a8caa
4630377
 
 
 
 
 
a2a8caa
4630377
 
a2a8caa
 
 
 
 
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
import gradio as gr
#from diffusers import DiffusionPipeline
import torch
import numpy as np
import PIL
import cv2

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

print('DEBUG:   Pwd')
os.system('pwd')
os.system('ls -la')

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

print('DEBUG:   Pip install from the build of diffusers')
os.system('pip install git+file:///content/diffusers')

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

pipeline = DiffusionPipeline.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()