Leeps commited on
Commit
a367e0e
1 Parent(s): 7ac4da6

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. .env +2 -0
  2. index.py +30 -10
.env ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ REPLICATE_API_TOKEN=r8_DAzyOBdCwUdt0b26ZMPWLyvyHTh55uh2Lwb3c
2
+ OPENAI_API_KEY=sk-proj-6lTXmIwTYmNo7uUpQwujT3BlbkFJDMVzyH5hzblFbgYLLMCP
index.py CHANGED
@@ -23,22 +23,42 @@ REPLICATE_API_TOKEN = os.getenv('REPLICATE_API_TOKEN')
23
 
24
  client = OpenAI()
25
 
26
- def main(img, strength):
27
  mask = img['layers'][0]
 
 
 
 
 
 
28
 
29
  # Match prompt strength from .4 to 1 (total destruction)
30
  prompt_strength = round(-0.6 * strength + 1, 2)
31
 
32
  base_image = Image.fromarray(img['background'].astype('uint8'))
33
- img_base_64 = img_to_base64(base_image)
34
 
35
- if is_transparent(mask) == True:
36
- mask_base_64 = None
37
- else:
38
- mask_img = create_mask_image(mask)
39
- mask_base_64 = img_to_base64(mask_img)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
- prompt = call_openai(img_base_64)
 
42
  #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."
43
 
44
  output_urls = generate_image(prompt, img_base_64, mask_base_64, prompt_strength)
@@ -49,7 +69,7 @@ def main(img, strength):
49
  def generate_image(prompt, img, mask, prompt_strength):
50
  input_data = {
51
  "image": img,
52
- "prompt": prompt + " expensive",
53
  "refine": "no_refiner",
54
  "scheduler": "K_EULER",
55
  "lora_scale": 0.8,
@@ -160,7 +180,7 @@ black_brush = gr.Brush(colors=["#000000"], default_color="#000000", color_mode="
160
  # Using the ImageEditor component to enable drawing on the image with limited colors
161
  demo = gr.Interface(
162
  fn=main,
163
- inputs=[gr.ImageEditor(brush=black_brush), gr.Slider(0, 1, step=0.025, value=0.5, label="Image Strength")],
164
  #outputs=[gr.Image(type="pil"), gr.Image(type="pil"), gr.Image(type="pil"), gr.Image(type="pil")]
165
  outputs=["image", "image", "image", "image"]
166
  )
 
23
 
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
+
34
 
35
  # Match prompt strength from .4 to 1 (total destruction)
36
  prompt_strength = round(-0.6 * strength + 1, 2)
37
 
38
  base_image = Image.fromarray(img['background'].astype('uint8'))
 
39
 
40
+ # Resize the starter image if either dimension is larger than 768 pixels
41
+ if base_image.size[0] > 768 or base_image.size[1] > 768:
42
+ # Calculate the new size while maintaining the aspect ratio
43
+ if base_image.size[0] > base_image.size[1]:
44
+ # Width is larger than height
45
+ new_width = 768
46
+ new_height = int((768 / base_image.size[0]) * base_image.size[1])
47
+ else:
48
+ # Height is larger than width
49
+ new_height = 768
50
+ new_width = int((768 / base_image.size[1]) * base_image.size[0])
51
+
52
+ # Resize the image
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
+ #prompt = call_openai(img_base_64)
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)
 
69
  def generate_image(prompt, img, mask, prompt_strength):
70
  input_data = {
71
  "image": img,
72
+ "prompt": prompt,
73
  "refine": "no_refiner",
74
  "scheduler": "K_EULER",
75
  "lora_scale": 0.8,
 
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
  )