Akjava commited on
Commit
7ee85b7
·
1 Parent(s): 4666324
.ipynb_checkpoints/README-checkpoint.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: StableDiffusionUpscaleImage
3
+ emoji: 💻
4
+ colorFrom: red
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 4.40.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
.ipynb_checkpoints/app-checkpoint.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ import upscale_image
4
+
5
+ @spaces.GPU(duration=120)
6
+ def gradio_upscale(image):
7
+ """画像を反転させる関数"""
8
+ return uscale_image.execute(Image)
9
+
10
+
11
+
12
+ if __name__ == "__main__":
13
+ # Gradio UIの設定
14
+ iface = gr.Interface(
15
+ fn=reverse_image,
16
+ inputs="image",
17
+ outputs="image",
18
+ title="Image Reverser",
19
+ description="Upload an image to see it reversed.",
20
+ )
21
+ # インターフェースを公開
22
+ iface.launch(share=True)
.ipynb_checkpoints/output-checkpoint.jpg ADDED
.ipynb_checkpoints/requirements-checkpoint.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ torch
2
+ diffusers
3
+ pillow
4
+ transformers
5
+ xformers
6
+ spaces
.ipynb_checkpoints/sample-checkpoint.jpg ADDED
.ipynb_checkpoints/upscale_image-checkpoint.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from diffusers import AutoencoderKL
3
+ from diffusers import StableDiffusionUpscalePipeline
4
+ from PIL import Image
5
+
6
+ device = "cuda"
7
+
8
+ def execute(input_image):
9
+ model_id = "stabilityai/stable-diffusion-x4-upscaler"
10
+ # GPUを使用する場合
11
+ pipe = StableDiffusionUpscalePipeline.from_pretrained(model_id, torch_dtype=torch.float16, variant="fp16") #not support vae?
12
+ pipe = pipe.to(device)
13
+ pipe.enable_attention_slicing()
14
+ #pipe.enable_model_cpu_offload()
15
+ pipe.enable_xformers_memory_efficient_attention()
16
+ #pipe.enable_vae_tiling()
17
+ pipe.vae.enable_tiling()
18
+ # 画像のパスとプロンプト
19
+ prompt = "beautiful girl"
20
+ first_resize_w = 128
21
+ first_resize_h = 128
22
+
23
+ # 画像の読み込みとリサイズ
24
+ image = input_image.convert("RGB")
25
+ low_res_img = image
26
+ if first_resize_w!=0 and first_resize_h!=0:
27
+ low_res_img = image.resize((first_resize_w, first_resize_h))
28
+ upscaled_image = upscale(pipe, prompt, low_res_img)
29
+ return upscaled_image
30
+
31
+ def upscale(pipe, prompt, img, step=50, guidance_scale=7.5):
32
+ generator = torch.Generator(device).manual_seed(seed)
33
+ return pipe(prompt=prompt,generator=generator, image=img, num_inference_steps=step, guidance_scale=guidance_scale).images[0]
34
+
35
+
36
+ if __name__ == "__main__":
37
+ image = Image.open("sample.jpg")
38
+ upscaled_image = execute(image)
39
+ upscaled_image.save("output.jpg")
40
+
__pycache__/upscale_image.cpython-310.pyc ADDED
Binary file (1.36 kB). View file
 
output.jpg ADDED
requirements.txt CHANGED
@@ -2,4 +2,5 @@ torch
2
  diffusers
3
  pillow
4
  transformers
5
- xformers
 
 
2
  diffusers
3
  pillow
4
  transformers
5
+ xformers
6
+ spaces
sample.jpg ADDED