foxelas commited on
Commit
0e3a5b8
·
1 Parent(s): 0e85509

add initial code

Browse files
Files changed (7) hide show
  1. .gitignore +5 -0
  2. README.md +12 -0
  3. app.py +58 -0
  4. input.jpg +0 -0
  5. output.jpg +0 -0
  6. requirements.txt +5 -0
  7. run_results.JPG +0 -0
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ /access_token.txt
2
+ /docs/
3
+ /docs/*
4
+ /.idea/
5
+ /.idea/*
README.md CHANGED
@@ -11,3 +11,15 @@ license: mit
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
+
15
+
16
+ ## Room Decoration
17
+ Tools for Room Decoration with AI
18
+
19
+ ## Status
20
+
21
+ Currently under development
22
+
23
+ ## Cite this Project
24
+
25
+ foxelas, Tools for Room Decoration with AI, 2023
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #from huggingface_hub import login
2
+ #login()
3
+ access_token = ""
4
+ with open("access_token.txt", "r") as f:
5
+ access_token = f.read()
6
+
7
+ import torch
8
+ from diffusers import StableDiffusionImg2ImgPipeline
9
+ model_path = "CompVis/stable-diffusion-v1-4"
10
+ import requests
11
+ from io import BytesIO
12
+ from PIL import Image
13
+
14
+ run_on_cpu = not(torch.cuda.is_available())
15
+ if run_on_cpu:
16
+ device = torch.device("cpu")
17
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
18
+ model_path,
19
+ use_auth_token=access_token
20
+ )
21
+ pipe = pipe.to(device)
22
+ pipe.enable_attention_slicing()
23
+
24
+ else:
25
+ device = torch.device("cuda")
26
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
27
+ model_path,
28
+ revision="fp16",
29
+ torch_dtype=torch.float16,
30
+ use_auth_token=access_token
31
+ )
32
+ pipe = pipe.to(device)
33
+ #pipe.enable_attention_slicing()
34
+
35
+ #######################################################
36
+ ## Input and Parameters
37
+ target_url = "https://t4.ftcdn.net/jpg/03/46/82/87/360_F_346828778_LM1vQWt1RLsrlHZMeNYeHnBBP90APQab.jpg"
38
+ prompt = "A living room decorated in boho style with lots of furniture."
39
+ strength = 0.75
40
+ guidance_scale = 7.5
41
+
42
+ #######################################################
43
+ response = requests.get(target_url)
44
+ init_img = Image.open(BytesIO(response.content)).convert("RGB")
45
+ init_img = init_img.resize((768, 512))
46
+ init_img.save("input.jpg")
47
+ print("Saved input image as [input.jpg] in local directory.")
48
+
49
+ generator = torch.Generator(device=device).manual_seed(1024)
50
+ if run_on_cpu:
51
+ image = pipe(prompt=prompt, init_image=init_img, strength=strength, guidance_scale=guidance_scale, generator=generator).images[0]
52
+ else:
53
+ with torch.autocast("cuda"):
54
+ image = pipe(prompt=prompt, init_image=init_img, strength=strength, guidance_scale=guidance_scale, generator=generator).images[0]
55
+
56
+ image.save("output.jpg")
57
+
58
+ print("Saved output image as [output.jpg] in local directory.")
input.jpg ADDED
output.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ torch~=1.13.1
3
+ requests~=2.28.1
4
+ diffusers~=0.8.0
5
+ Pillow~=9.4.0
run_results.JPG ADDED