Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffusers import StableDiffusionXLInpaintPipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import numpy as np
|
| 4 |
+
import imageio
|
| 5 |
+
from PIL import Image
|
| 6 |
+
import torch
|
| 7 |
+
import modin.pandas as pd
|
| 8 |
+
|
| 9 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
+
pipe = StableDiffusionXLInpaintPipeline.from_pretrained("stabilityai/sdxl-turbo", safety_checker=None)
|
| 11 |
+
pipe = pipe.to(device)
|
| 12 |
+
|
| 13 |
+
def resize(value,img):
|
| 14 |
+
img = Image.open(img)
|
| 15 |
+
img = img.resize((value,value))
|
| 16 |
+
return img
|
| 17 |
+
|
| 18 |
+
def img2img(source_img, prompt, strength):
|
| 19 |
+
imageio.imwrite("data.png", source_img['image'])
|
| 20 |
+
imageio.imwrite("data_mask.png", source_img["mask"])
|
| 21 |
+
src = resize(768, "data.png")
|
| 22 |
+
src.save("src.png")
|
| 23 |
+
mask = resize(768, "data_mask.png")
|
| 24 |
+
mask.save("mask.png")
|
| 25 |
+
image = pipe(prompt=prompt, image=src, mask_image=mask, num_inference_steps=6, strength=strength, guidance_scale=0.0).images[0]
|
| 26 |
+
return image
|
| 27 |
+
|
| 28 |
+
title="GoldExtra Zeichnung zu 2.5D"
|
| 29 |
+
description="OpenCV.js > i2i > 3D"
|
| 30 |
+
gr.Interface(fn=img2img, inputs=[gr.Image(source="upload", tool="sketch", label="Source Image"),
|
| 31 |
+
gr.Textbox(label='What you want the AI to Generate, 77 Token limit'),
|
| 32 |
+
gr.Slider(minimum=.5, maximum=1, value=.75, step=.025, label='Strength')],
|
| 33 |
+
outputs='image',
|
| 34 |
+
title=title,
|
| 35 |
+
description=description,
|
| 36 |
+
article = "Code Monkey: <a href=\"https://huggingface.co/Manjushri\">Manjushri</a>").launch(max_threads=True, debug=True)
|