nightfury commited on
Commit
754fee2
·
1 Parent(s): 4fe16e0

Create new file

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from torch import autocast
2
+ import requests
3
+ import torch
4
+ from PIL import Image
5
+ from io import BytesIO
6
+
7
+ from diffusers import StableDiffusionImg2ImgPipeline
8
+
9
+ # load the pipeline
10
+ device = "cuda"
11
+ model_id_or_path = "CompVis/stable-diffusion-v1-4"
12
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
13
+ model_id_or_path,
14
+ revision="fp16",
15
+ torch_dtype=torch.float16,
16
+ use_auth_token=True
17
+ )
18
+ # or download via git clone https://huggingface.co/CompVis/stable-diffusion-v1-4
19
+ # and pass `model_id_or_path="./stable-diffusion-v1-4"` without having to use `use_auth_token=True`.
20
+ pipe = pipe.to(device)
21
+
22
+ # let's download an initial image
23
+ url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
24
+
25
+ response = requests.get(url)
26
+ init_image = Image.open(BytesIO(response.content)).convert("RGB")
27
+ init_image = init_image.resize((768, 512))
28
+
29
+ prompt = "Lively, illustration of a [[[<king::4>]]], portrait, fantasy, intricate, Scenic, hyperdetailed, hyper realistic <king-hearthstone>, unreal engine, 4k, smooth, sharp focus, intricate, cinematic lighting, highly detailed, octane, digital painting, artstation, concept art, vibrant colors, Cinema4D, WLOP, 3d render, in the style of hearthstone::5 art by Artgerm and greg rutkowski and magali villeneuve, martina jackova, Giger"
30
+
31
+ with autocast("cuda"):
32
+ images = pipe(prompt=prompt, init_image=init_image, strength=0.75, guidance_scale=7.5).images
33
+
34
+ images[0].save("fantasy_landscape.png")