Selim321 commited on
Commit
8ba6f46
1 Parent(s): a48aeeb

Created app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import torch
4
+ from PIL import Image
5
+ from io import BytesIO
6
+ from diffusers import StableDiffusionImg2ImgPipeline
7
+
8
+ device = "cuda"
9
+ model_id_or_path = "runwayml/stable-diffusion-v1-5"
10
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
11
+ pipe = pipe.to(device)
12
+
13
+
14
+ def transform (init_image, textPrompt, strength=0.5, guidance_scale=15):
15
+ init_image = Image.open(init_image).convert("RGB")
16
+ init_image = init_image.resize((768, 512))
17
+ images = pipe(prompt=textPrompt, image=init_image, strength=strength, guidance_scale=guidance_scale).images
18
+ image = images[0]
19
+ return image
20
+
21
+ demo = gr.Interface(
22
+ fn=transform,
23
+ inputs=[gr.Image(type='filepath'), "text", gr.Slider(0,1), gr.Slider(1,30)],
24
+ outputs=["image"],
25
+ allow_flagging="never"
26
+ )
27
+ demo.launch()