EnigmaOfTheWorld CobaltZvc commited on
Commit
9ed4ad4
0 Parent(s):

Duplicate from CobaltZvc/Interior_home

Browse files

Co-authored-by: Vishwesh V Bhat <CobaltZvc@users.noreply.huggingface.co>

Files changed (4) hide show
  1. .gitattributes +34 -0
  2. README.md +13 -0
  3. app.py +145 -0
  4. requirements.txt +11 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Interior Home
3
+ emoji: 🐢
4
+ colorFrom: yellow
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 3.33.1
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: CobaltZvc/Interior_home
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import cohere as co
3
+ import random
4
+ import io
5
+ import os
6
+ import warnings
7
+ from IPython.display import display
8
+ from PIL import Image
9
+ from stability_sdk import client
10
+ import stability_sdk.interfaces.gooseai.generation.generation_pb2 as generation
11
+ from PIL import Image
12
+ import re
13
+ import matplotlib.pyplot as plt
14
+ import torch
15
+ from diffusers import StableDiffusionPipeline
16
+ import gradio as gr
17
+
18
+ STABILITY_HOST = 'grpc.stability.ai:443'#'<ADD >' # os.environ["STABILITY_HOST"]
19
+ STABILITY_KEY = 'sk-LMwG6TPz8NHVPDHw4LAXdgLiSH37XB12r5wTGx9mD2b0oivS' # os.environ["STABILITY_KEY"] # IF NOT SECRET ADD STABILITY AI API KEY WITHIN ''
20
+ cohere_key = 'EZbtz80P7j0R4ZyoyTNz13CPuZdyWPKtVlBU7dzr' # os.environ["cohere_key"] # IF NOT SECRET ADD COHERE API KEY WITHIN ''
21
+
22
+
23
+ def generate_caption_keywords(promptz, model='command-xlarge-20221108', max_tokens=200, temperature=random.uniform(0.1, 2), k=0, p=0.75, frequency_penalty=0, presence_penalty=0, stop_sequences=[]):
24
+
25
+ response = co.generate(
26
+ model='command-xlarge-20221108',
27
+ prompt=f'write prompts for interior designs which does not exist\n\nexterior design of house = Peaceful wooden mansion, unreal engine 5 tech demo, zillow interior, living room, cozy, Frank Lloyd Wright\n##\nexterior design of house = Double story suburban house,it is raining, night time , peaceful atmosphere, moody lighting , digital art , highly detailed , high contrast, beautiful lighting, award winning , trending on art station, photorealistic, 8k \n##\nexterior design of house =cute chubby house, 3 d render, minimalistic, octane, 1 0 0 mm, depth of field, diorama, blue background \n##\nexterior design of house =elevation of a modern luxurious villa in a rich urban area, photorealist, 4 k \n##\ninterior design of of kitchen room = Full modern kitchen, purple furniture, star wallpaper, digital Painting, ultradetailed, artstation, oil Painting, ultradetailed, artstation\n##\ninterior design of of bathroom =bathroom design archi-viz biopunck grean schem, by Stanley Artgerm Lau, WLOP, Rossdraws, James Jean, Andrei Riabovitchevy, Marc Simonetti, and Sakimichan, trending on artstation\n##\ninterior design of bathroom = modern bathroom, gloomy and foggy atmosphere, octane render, artstation trending, horror scene, highly detailed \n##\n{promptz} =',
28
+ max_tokens=25,
29
+ temperature=0.6,
30
+ k=0,
31
+ p=1,
32
+ frequency_penalty=0,
33
+ presence_penalty=0,
34
+ stop_sequences=["##"],
35
+ return_likelihoods='NONE')
36
+
37
+ def highlight_keywords(text):
38
+ keywords = []
39
+ text = text.lower()
40
+ text = re.sub(r'[^a-z\s]', '', text) # remove punctuation
41
+ text = re.sub(r'\b(the|and|of)\b', '', text) # remove stop words
42
+ words = text.split()
43
+ for word in words:
44
+ if word not in keywords:
45
+ keywords.append(word)
46
+ return keywords
47
+
48
+ caption = response.generations[0].text
49
+ keywords = highlight_keywords(caption)
50
+ keywords_string = ', '.join(keywords)
51
+
52
+ return caption, keywords_string
53
+
54
+ # def g_search(image):
55
+
56
+
57
+ def img2img(design,is_prompt,is_GPU,custom_prompt,cfg_scale,steps):
58
+ try:
59
+ caption, keywords = generate_caption_keywords(design)
60
+ prompt = design+keywords
61
+ except:
62
+ prompt = design
63
+
64
+ if is_prompt == True:
65
+ prompt = custom_prompt
66
+
67
+
68
+ if is_GPU == True:
69
+ model_id = "CompVis/stable-diffusion-v1-4"
70
+ device = "cuda"
71
+
72
+
73
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16")
74
+ pipe = pipe.to(device)
75
+
76
+ # prompt = "a photo of an astronaut riding a horse on mars"
77
+ img = pipe(prompt).images[0]
78
+ import matplotlib.pyplot as plt
79
+ # img.save(f"{prompt}image")
80
+
81
+ else:
82
+
83
+
84
+
85
+ engine="stable-diffusion-v1-5"
86
+ # Set up our connection to the API.
87
+ stability_api = client.StabilityInference(
88
+ key= 'sk-LMwG6TPz8NHVPDHw4LAXdgLiSH37XB12r5wTGx9mD2b0oivS', # os.environ['STABILITY_KEY'], # API Key reference.
89
+ verbose=True, # Print debug messages.
90
+ engine=engine, # Set the engine to use for generation.
91
+ # Available engines: stable-diffusion-v1 stable-diffusion-v1-5 stable-diffusion-512-v2-0 stable-inpainting-v1-0 stable-inpainting-512-v2-0
92
+ )
93
+
94
+ # Set up our initial generation parameters.
95
+ answers = stability_api.generate(
96
+ prompt=prompt,
97
+ seed=random.seed(), # If a seed is provided, the resulting generated image will be deterministic.
98
+ # What this means is that as long as all generation parameters remain the same, you can always recall the same image simply by generating it again.
99
+ # Note: This isn't quite the case for Clip Guided generations, which we'll tackle in a future example notebook.
100
+ steps=steps, # Amount of inference steps performed on image generation. Defaults to 30.
101
+ cfg_scale=cfg_scale, # Influences how strongly your generation is guided to match your prompt.
102
+ # Setting this value higher increases the strength in which it tries to match your prompt.
103
+ # Defaults to 7.0 if not specified.
104
+ width=512, # Generation width, defaults to 512 if not included.
105
+ height=512, # Generation height, defaults to 512 if not included.
106
+ samples=1, # Number of images to generate, defaults to 1 if not included.
107
+ sampler=generation.SAMPLER_K_DPMPP_2M # Choose which sampler we want to denoise our generation with.
108
+ # Defaults to k_dpmpp_2m if not specified. Clip Guidance only supports ancestral samplers.
109
+ # (Available Samplers: ddim, plms, k_euler, k_euler_ancestral, k_heun, k_dpm_2, k_dpm_2_ancestral, k_dpmpp_2s_ancestral, k_lms, k_dpmpp_2m)
110
+ )
111
+
112
+ for resp in answers:
113
+ for artifact in resp.artifacts:
114
+ if artifact.finish_reason == generation.FILTER:
115
+ warnings.warn(
116
+ "Your request activated the API's safety filters and could not be processed."
117
+ "Please modify the prompt and try again.")
118
+ if artifact.type == generation.ARTIFACT_IMAGE:
119
+ img = Image.open(io.BytesIO(artifact.binary))
120
+
121
+ img.save(f"new_image{prompt}{cfg_scale}{steps}{random.seed()}.jpg")
122
+ print(prompt)
123
+ return img ,prompt+'steps'+str(steps)+'strength'+str(cfg_scale)+str(random.seed())
124
+
125
+ gr.Interface(img2img, [
126
+ gr.Dropdown(['exterior design of home',
127
+ 'interior design of living room',
128
+
129
+ 'interior design of kitchen',
130
+
131
+ 'interior design of bathroom'
132
+ ],label="Click here to select your design by Cohere command Langauge model",value = 'interior design'),
133
+
134
+ gr.Checkbox(label="Check Custom design if you already have prompt refer https://lexica.art/?q=interior+design for inpiration",value = False),
135
+ gr.Checkbox(label="click to use GPU (not working in Huggingface space )",value = False),
136
+
137
+ gr.Textbox(label = ' Input custom Prompt Text'),
138
+
139
+ gr.Slider(2, 15, value = 7, label = 'Guidence Scale'),
140
+ gr.Slider(10, 50, value = 50, step = 1, label = 'Number of steps / Iterations')
141
+ ],
142
+ [gr.Image(),gr.Textbox(label="Prompt for future reference",lines=2 )],
143
+
144
+ title = "" +'Baith ul Ahsan🏡(the best house),Create Aesthetic exteriors and interiors of house with power of COhere Language model and Stable Diffusion '+ "",
145
+ description="Baith ul Ahsan(the best house) 🏡 is a web app that uses the power of artificial intelligence to create Aesthetic exteriors and interiors . With the Cohere language Command model, it can generate descriptions of exterior or interior of your home, and the Stable Diffusion algorithm creates relevant appealing images to bring your vision to your thoughts. Give Baith al ahsan a try and see how it can elevate your interior design.--if you want to scale / reaserch / build mobile app on this space konnect me @[here](https://www.linkedin.com/in/sallu-mandya/)").launch( debug = True)
requirements.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ stability-sdk
2
+ cohere
3
+ IPython
4
+ torch
5
+ diffusers
6
+ git+https://github.com/huggingface/diffusers.git
7
+ git+https://github.com/huggingface/transformers
8
+ scipy
9
+ ftfy
10
+ accelerate
11
+ gradio