Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
index.py
CHANGED
|
@@ -24,10 +24,12 @@ REPLICATE_API_TOKEN = os.getenv('REPLICATE_API_TOKEN')
|
|
| 24 |
client = OpenAI()
|
| 25 |
|
| 26 |
def main(img, strength, prompt):
|
|
|
|
|
|
|
|
|
|
| 27 |
mask = img['layers'][0]
|
| 28 |
if is_transparent(mask) == True:
|
| 29 |
mask_img = None
|
| 30 |
-
mask_base_64 = None
|
| 31 |
else:
|
| 32 |
mask_img = create_mask_image(mask)
|
| 33 |
|
|
@@ -53,12 +55,20 @@ def main(img, strength, prompt):
|
|
| 53 |
base_image = base_image.resize((new_width, new_height), Image.LANCZOS)
|
| 54 |
if mask_img is not None:
|
| 55 |
mask_img = mask_img.resize((new_width, new_height), Image.LANCZOS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
img_base_64 = img_to_base64(base_image)
|
| 58 |
-
mask_base_64 = img_to_base64(mask_img)
|
| 59 |
|
| 60 |
-
|
|
|
|
| 61 |
prompt = prompt
|
|
|
|
|
|
|
|
|
|
| 62 |
#prompt = "The image shows a person wearing sleek, over-ear headphones with a matte finish and a cool, light beige color (Pantone 7527 C), captured under soft, diffused natural lighting, emphasizing the smooth and minimalist design of the headphones."
|
| 63 |
|
| 64 |
output_urls = generate_image(prompt, img_base_64, mask_base_64, prompt_strength)
|
|
@@ -180,7 +190,7 @@ black_brush = gr.Brush(colors=["#000000"], default_color="#000000", color_mode="
|
|
| 180 |
# Using the ImageEditor component to enable drawing on the image with limited colors
|
| 181 |
demo = gr.Interface(
|
| 182 |
fn=main,
|
| 183 |
-
inputs=[gr.ImageEditor(brush=black_brush), gr.Slider(0, 1, step=0.025, value=0.5, label="Image Strength"), gr.Textbox(label="Describe the object in as much detail as possible")],
|
| 184 |
#outputs=[gr.Image(type="pil"), gr.Image(type="pil"), gr.Image(type="pil"), gr.Image(type="pil")]
|
| 185 |
outputs=["image", "image", "image", "image"]
|
| 186 |
)
|
|
|
|
| 24 |
client = OpenAI()
|
| 25 |
|
| 26 |
def main(img, strength, prompt):
|
| 27 |
+
print(prompt)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
mask = img['layers'][0]
|
| 31 |
if is_transparent(mask) == True:
|
| 32 |
mask_img = None
|
|
|
|
| 33 |
else:
|
| 34 |
mask_img = create_mask_image(mask)
|
| 35 |
|
|
|
|
| 55 |
base_image = base_image.resize((new_width, new_height), Image.LANCZOS)
|
| 56 |
if mask_img is not None:
|
| 57 |
mask_img = mask_img.resize((new_width, new_height), Image.LANCZOS)
|
| 58 |
+
|
| 59 |
+
if mask_img is not None:
|
| 60 |
+
mask_base_64 = img_to_base64(mask_img)
|
| 61 |
+
else:
|
| 62 |
+
mask_base_64 = None
|
| 63 |
|
| 64 |
img_base_64 = img_to_base64(base_image)
|
|
|
|
| 65 |
|
| 66 |
+
|
| 67 |
+
# Todo -- send just the masked out part to gpt
|
| 68 |
prompt = prompt
|
| 69 |
+
if prompt == "":
|
| 70 |
+
prompt = call_openai(img_base_64)
|
| 71 |
+
|
| 72 |
#prompt = "The image shows a person wearing sleek, over-ear headphones with a matte finish and a cool, light beige color (Pantone 7527 C), captured under soft, diffused natural lighting, emphasizing the smooth and minimalist design of the headphones."
|
| 73 |
|
| 74 |
output_urls = generate_image(prompt, img_base_64, mask_base_64, prompt_strength)
|
|
|
|
| 190 |
# Using the ImageEditor component to enable drawing on the image with limited colors
|
| 191 |
demo = gr.Interface(
|
| 192 |
fn=main,
|
| 193 |
+
inputs=[gr.ImageEditor(brush=black_brush), gr.Slider(0, 1, step=0.025, value=0.5, label="Image Strength"), gr.Textbox(label="Describe the object in as much detail as possible (include colors, materials, etc)")],
|
| 194 |
#outputs=[gr.Image(type="pil"), gr.Image(type="pil"), gr.Image(type="pil"), gr.Image(type="pil")]
|
| 195 |
outputs=["image", "image", "image", "image"]
|
| 196 |
)
|