Spaces:
Runtime error
Runtime error
Commit
·
331687d
1
Parent(s):
2cdf938
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffusers import StableDiffusionPipeline
|
2 |
+
import torch
|
3 |
+
from PIL import Image
|
4 |
+
import math
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
pipeline = StableDiffusionPipeline.from_pretrained("MohamedRashad/diffusion_fashion", torch_dtype=torch.float16)
|
8 |
+
|
9 |
+
|
10 |
+
def image_grid(imgs, rows, cols):
|
11 |
+
assert len(imgs) == rows*cols
|
12 |
+
|
13 |
+
w, h = imgs[0].size
|
14 |
+
grid = Image.new('RGB', size=(cols*w, rows*h))
|
15 |
+
grid_w, grid_h = grid.size
|
16 |
+
|
17 |
+
for i, img in enumerate(imgs):
|
18 |
+
grid.paste(img, box=(i%cols*w, i//cols*h))
|
19 |
+
return grid
|
20 |
+
|
21 |
+
|
22 |
+
def generate_image2(prompt,num_images):
|
23 |
+
# num_images = 3
|
24 |
+
num_images=math.floor(num_images)
|
25 |
+
prompt = [prompt] * num_images
|
26 |
+
#r=num_images//2
|
27 |
+
#c=2
|
28 |
+
images = pipeline(prompt).images
|
29 |
+
#print(images)
|
30 |
+
grid = image_grid(images, rows=1, cols=num_images)
|
31 |
+
|
32 |
+
grid.save(f"prompt.png")
|
33 |
+
return grid
|
34 |
+
|
35 |
+
|
36 |
+
text_input = gr.inputs.Textbox(label="Enter prompt")
|
37 |
+
number_input = gr.inputs.Number(label="Enter Number of images")
|
38 |
+
|
39 |
+
demo2=gr.Interface(
|
40 |
+
fn=generate_image2,
|
41 |
+
inputs=[text_input, number_input],
|
42 |
+
outputs="image",
|
43 |
+
title="Image Generation",
|
44 |
+
description="Enter a prompt and see a grid of generated images.",
|
45 |
+
layout="vertical",
|
46 |
+
)
|
47 |
+
|
48 |
+
demo2.launch(inline=False)
|