Spaces:
Paused
Paused
Basic Outpainting Framework
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio
|
2 |
+
import torch
|
3 |
+
import PIL
|
4 |
+
from torchvision import transforms
|
5 |
+
|
6 |
+
from diffusers import StableDiffusionInpaintPipeline
|
7 |
+
|
8 |
+
pipeline = StableDiffusionInpaintPipeline.from_pretrained("runwayml/stable-diffusion-inpainting",
|
9 |
+
revision="fp16",
|
10 |
+
torch_dtype=torch.float16,
|
11 |
+
safety_checker=lambda images, **kwargs: (images, False))
|
12 |
+
|
13 |
+
pipeline.to("cuda")
|
14 |
+
#generator = torch.Generator(device).manual_seed(seed)
|
15 |
+
|
16 |
+
def diffuse(prompt, negativePrompt, inputImage, mask, guidanceScale, numInferenceSteps):
|
17 |
+
return pipeline(prompt=prompt,
|
18 |
+
negative_prompt=negativePrompt,
|
19 |
+
image=inputImage,
|
20 |
+
mask_image=mask,
|
21 |
+
guidance_scale=guidanceScale,
|
22 |
+
num_inference_steps=numInferenceSteps).images[0]
|
23 |
+
|
24 |
+
prompt = gradio.Textbox(label="Prompt", placeholder="A person in a room", lines=3)
|
25 |
+
negativePrompt = gradio.Textbox(label="Negative Prompt", placeholder="Text", lines=3)
|
26 |
+
|
27 |
+
inputImage = gradio.Image(label="Input Image", type="pil")
|
28 |
+
#inputFeed = gradio.Image(label="Input Feed", source="webcam", streaming=True)
|
29 |
+
mask = gradio.Image(label="Mask", type="pil")
|
30 |
+
outputImage = gradio.Image(label="Extrapolated Field of View")
|
31 |
+
guidanceScale = gradio.Slider(label="Guidance Scale", maximum=1, value = 0.75)
|
32 |
+
numInferenceSteps = gradio.Slider(label="Number of Inference Steps", maximum=100, value = 0)
|
33 |
+
|
34 |
+
ux = gradio.Interface(fn=diffuse, title="View Diffusion", inputs=[prompt, negativePrompt, inputImage, mask, guidanceScale, numInferenceSteps], outputs=outputImage, live=True)
|
35 |
+
ux.launch()
|