Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio
|
3 |
+
from diffusers import StableDiffusionPipeline
|
4 |
+
import requests
|
5 |
+
from PIL import Image
|
6 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
7 |
+
|
8 |
+
pipe = StableDiffusionPipeline.from_pretrained("ByteDance/sd2.1-base-zsnr-laionaes6")#.to("cuda")
|
9 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
|
10 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
|
11 |
+
|
12 |
+
def img2prompt(img):
|
13 |
+
raw_image = img.convert("RGB")
|
14 |
+
inputs = processor(raw_image, return_tensors="pt")
|
15 |
+
out = model.generate(**inputs)
|
16 |
+
output = processor.decode(out[0], skip_special_tokens=True)
|
17 |
+
return output
|
18 |
+
|
19 |
+
def prompt2img(prompt):
|
20 |
+
pipe = StableDiffusionPipeline.from_pretrained("ByteDance/sd2.1-base-zsnr-laionaes6").to("cuda")
|
21 |
+
img = pipe(prompt, guidance_scale=7.5, guidance_rescale=0.7).images[0]
|
22 |
+
return img
|
23 |
+
|
24 |
+
def wow_img2img(img):
|
25 |
+
return prompt2img(img2prompt(img))
|
26 |
+
|
27 |
+
app = gradio.Interface(fn=wow_img2img, inputs=gradio.Image(type="pil"), outputs=gradio.Image(type="pil"))
|
28 |
+
app.launch(share=True)
|