Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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("start generating")
|
14 |
+
|
15 |
+
YOUR_TOKEN=MY_SECRET_TOKEN
|
16 |
+
|
17 |
+
device="cpu"
|
18 |
+
|
19 |
+
pipe = StableDiffusionPipeline.from_pretrained("AkiKagura/mkgen-diffusion", 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("okay")
|
39 |
+
|
40 |
+
title="Marco Generation"
|
41 |
+
description="Use 'mkmk woman' to get Marco pics. <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)
|