Spaces:
Runtime error
Runtime error
File size: 4,992 Bytes
ef8d465 2a06a6d 4dd61ad 19e6ee3 4dd61ad ef8d465 2991621 ef8d465 fbb92a7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
import os
os.environ['STABILITY_HOST'] = 'grpc.stability.ai:443'
STABILITY_KEY = os.environ["STABILITY_KEY"]
cohere_key = os.environ["cohere_key"]
import cohere
import random
co = cohere.Client(cohere_key)
import io
import os
import warnings
from IPython.display import display
from PIL import Image
from stability_sdk import client
import stability_sdk.interfaces.gooseai.generation.generation_pb2 as generation
from PIL import Image
stability_api = client.StabilityInference(
key=os.environ['STABILITY_KEY'],
verbose=True,
)
def generate_caption_keywords(prompt, 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=[]):
response = co.generate(
model=model,
prompt=prompt,
max_tokens=max_tokens,
temperature=temperature,
k=k,
p=p,
frequency_penalty=frequency_penalty,
presence_penalty=presence_penalty,
stop_sequences=stop_sequences,
return_likelihoods='NONE')
def highlight_keywords(text):
keywords = []
text = text.lower()
text = re.sub(r'[^a-z\s]', '', text) # remove punctuation
text = re.sub(r'\b(the|and|of)\b', '', text) # remove stop words
words = text.split()
for word in words:
if word not in keywords:
keywords.append(word)
return keywords
caption = response.generations[0].text
keywords = highlight_keywords(caption)
keywords_string = ', '.join(keywords)
return caption, keywords_string
def img2img( path ,is_HD,design,x_prompt,alt_prompt,strength,guidance_scale,steps):
img = Image.open(path)
try:
caption, keywords = generate_caption_keywords(design)
prompt = keywords
except:
prompt = design
if x_prompt == True:
prompt=alt_prompt
answers = stability_api.generate(
prompt,
init_image=img,
seed=54321, # if we're passing in an image generated by SD, you may get better results by providing a different seed value than was used to generate the image
start_schedule=strength, # this controls the "strength" of the prompt relative to the init image
)
# iterating over the generator produces the api response
for resp in answers:
for artifact in resp.artifacts:
if artifact.finish_reason == generation.FILTER:
warnings.warn(
"Your request activated the API's safety filters and could not be processed."
"Please modify the prompt and try again.")
if artifact.type == generation.ARTIFACT_IMAGE:
img2 = Image.open(io.BytesIO(artifact.binary))
im1 = img2.save("new_image.jpg")
print(type(img2))
return img2
import gradio as gr
gr.Interface(img2img, [gr.Image(source="upload", type="filepath", label="Input Image"),
gr.Checkbox(label="Click HD to get HD output(Not working in HF spaces ,contact for Colab)",value = False),
gr.Dropdown(['interior design of living room',
'interior design of gaming room',
'interior design of kitchen',
'interior design of bedroom',
'interior design of bathroom',
'interior design of office',
'interior design of meeting room',
'interior design of personal room'],label="Click here to select your design",value = 'interior design'),
gr.Checkbox(label="Custom design",value = False),
gr.Textbox(label = ' Input custom Prompt Text'),
gr.Slider(label='Strength', minimum = 0, maximum = 1, step = .01, value = .65),
gr.Slider(2, 15, value = 7, label = 'Guidence Scale'),
gr.Slider(10, 50, value = 50, step = 1, label = 'Number of Iterations')
],
gr.Image(), title = "" +'Baith-al-suroor بَیتُ الْسرور 🏡💡🤖, Transform your space with the power of artificial intelligence. '+ "",
description="Baith al suroor بَیتُ الْسرور (house of happiness in Arabic) 🏡💡🤖 is a simple app that uses the power of artificial intelligence to transform your space. With the Cohere language Command model, it can generate descriptions of your desired design, and the Stable Diffusion algorithm creates relevant images to bring your vision to life. Give Baith AI 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) |