amgad59 commited on
Commit
d7e7902
·
1 Parent(s): 549fc64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -41
app.py CHANGED
@@ -1,43 +1,23 @@
1
  import gradio as gr
2
- #import torch
3
- #from torch import autocast // only for GPU
4
-
5
- from PIL import Image
6
-
7
- import os
8
- MY_SECRET_TOKEN=os.environ.get('HF_TOKEN_SD')
9
-
10
  from diffusers import StableDiffusionPipeline
11
- #from diffusers import StableDiffusionImg2ImgPipeline
12
-
13
- print("hello sylvain")
14
-
15
- YOUR_TOKEN=MY_SECRET_TOKEN
16
-
17
- device="cpu"
18
-
19
- pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", use_auth_token=YOUR_TOKEN)
20
- pipe.to(device)
21
-
22
- gallery = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery").style(grid=[2], height="auto")
23
-
24
- def infer(prompt):
25
-
26
- #image = pipe(prompt, init_image=init_image)["sample"][0]
27
- images_list = pipe([prompt] * 4)
28
- images = []
29
- safe_image = Image.open(r"unsafe.png")
30
- for i, image in enumerate(images_list["images"]):
31
- if(images_list["nsfw_content_detected"][i]):
32
- images.append(safe_image)
33
- else:
34
- images.append(image)
35
-
36
- return images
37
-
38
- print("Great sylvain ! Everything is working fine !")
39
-
40
- title="Stable Diffusion CPU"
41
- description="Stable Diffusion example using CPU and HF token. <br />Warning: Slow process... ~5/10 min inference time. <b>NSFW filter enabled.</b>"
42
-
43
- gr.Interface(fn=infer, inputs="text", outputs=gallery,title=title,description=description).queue(max_size=10).launch(enable_queue=True)
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
2
  from diffusers import StableDiffusionPipeline
3
+ import torch
4
+
5
+ pipe = StableDiffusionPipeline.from_pretrained("MohamedRashad/diffusion_fashion", torch_dtype=torch.float32)
6
+ pipe.to("cpu")
7
+
8
+ def generate_image(text):
9
+ images = pipe(text).images
10
+ image = images[0]
11
+ return image
12
+
13
+ diffusion_interface = gr.Interface(
14
+ generate_image,
15
+ gr.Textbox(lines=1, label="Input"),
16
+ gr.Image(type="pil", label="Output"),
17
+ title="Diffusion4Fashion: Generate cool clothes!",
18
+ description="<center><p>Enter a description about a piece of cloth and the model will generate an image.</p></center>",
19
+ examples=["A photo of a dress, made in 2019, color is Red, Casual usage, Women's cloth, something for the summer season, on white background"],
20
+ cache_examples=True,
21
+ )
22
+
23
+ diffusion_interface.launch()