Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,31 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
def greet(name):
|
4 |
return "Hello " + name + "!!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
iface = gr.Interface(fn=
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from diffusers import DiffusionPipeline
|
3 |
+
import torch
|
4 |
+
import numpy as np
|
5 |
+
import PIL
|
6 |
+
from google.colab.patches import cv2_imshow
|
7 |
+
import cv2
|
8 |
+
|
9 |
+
pipeline = DiffusionPipeline.from_pretrained("fusing/latent-diffusion-text2im-large")
|
10 |
+
generator = torch.manual_seed(42)
|
11 |
|
12 |
def greet(name):
|
13 |
return "Hello " + name + "!!"
|
14 |
+
|
15 |
+
def genimage(prompt, iterations):
|
16 |
+
image = pipeline([prompt], generator=generator, eta=0.3, guidance_scale=6.0, num_inference_steps=iterations)
|
17 |
+
|
18 |
+
image_processed = image.cpu().permute(0, 2, 3, 1)
|
19 |
+
image_processed = image_processed * 255.
|
20 |
+
image_processed = image_processed.numpy().astype(np.uint8)
|
21 |
+
image_pil = PIL.Image.fromarray(image_processed[0])
|
22 |
+
|
23 |
+
# save image
|
24 |
+
file_name = "test.png"
|
25 |
+
image_pil.save(file_name)
|
26 |
+
img = cv2.imread(file_name)
|
27 |
+
#cv2_imshow(img)
|
28 |
+
return img
|
29 |
|
30 |
+
iface = gr.Interface(fn=genimage, inputs=["text", "number"], outputs="image")
|
31 |
iface.launch()
|