mkrzyzan commited on
Commit
ac94249
β€’
1 Parent(s): ec52b67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -34
app.py CHANGED
@@ -1,39 +1,29 @@
1
  import gradio as gr
2
- import numpy as np
3
- from diffusers import DDPMPipeline, DDIMPipeline, PNDMPipeline
4
 
5
- model_id = "google/ddpm-cat-256"
6
- ddpm = DDPMPipeline.from_pretrained(model_id)
 
 
 
 
7
 
8
- def flip_text(text):
9
- return text[::-1]
 
 
 
 
 
 
 
10
 
11
- def flip_img(img):
12
- return np.flipud(img)
 
 
 
 
13
 
14
- def show_cat():
15
- return ddpm(num_inference_steps=10).images[0]
16
-
17
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
18
- gr.Markdown("flip the text or image using this demo")
19
- with gr.Tab("Flip Text"):
20
- text_input = gr.Textbox();
21
- text_output = gr.Textbox();
22
- text_btn = gr.Button("Flip");
23
- with gr.Tab("Flip Img"):
24
- with gr.Row():
25
- image_input = gr.Image(source="webcam");
26
- image_outpt = gr.Image();
27
- image_btn = gr.Button("Flip");
28
- with gr.Tab("Goolg Cat"):
29
- img_cat = gr.Image()
30
- cat_btn = gr.Button("Show Cat")
31
- with gr.Accordion("Open for more"):
32
- gr.Markdown("Look at me");
33
-
34
- text_btn.click(flip_text, inputs=text_input, outputs=text_output)
35
- image_btn.click(flip_img, inputs=image_input, outputs=image_outpt)
36
- cat_btn.click(show_cat, outputs=img_cat)
37
-
38
-
39
- demo.launch()
 
1
  import gradio as gr
2
+ from diffusers import StableDiffusionInpaintPipeline
3
+ import torch
4
 
5
+ pipeline = StableDiffusionInpaintPipeline.from_pretrained(
6
+ "runwayml/stable-diffusion-inpainting",
7
+ torch_dtype=torch.float16,
8
+ )
9
+
10
+ pipeline = pipeline.to("cuda")
11
 
12
+ def predict(mask_img):
13
+ prompt = "a green frog, highly detailed, natural lighting"
14
+ image = pipeline(prompt=prompt,
15
+ num_inference_steps=35,
16
+ image=mask_img["image"],
17
+ mask_image=mask_img["mask"],
18
+ guidance_scale=9).images[0]
19
+
20
+ return image
21
 
22
+ demo = gr.Interface(
23
+ fn=predict,
24
+ inputs=gr.Image(),
25
+ outputs=gr.Image(),
26
+ title="Stable Diffusion Inpainting"
27
+ )
28
 
29
+ demo.launch()