Leeps commited on
Commit
6f1f6df
1 Parent(s): b494390

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. index.py +16 -12
index.py CHANGED
@@ -26,9 +26,12 @@ REPLICATE_API_TOKEN = os.getenv('REPLICATE_API_TOKEN')
26
 
27
  client = OpenAI()
28
 
29
- def main(img):
30
  mask = img['layers'][0]
31
 
 
 
 
32
  base_image = Image.fromarray(img['background'].astype('uint8'))
33
  img_base_64 = img_to_base64(base_image)
34
 
@@ -39,17 +42,17 @@ def main(img):
39
  mask_base_64 = img_to_base64(mask_img)
40
 
41
  prompt = call_openai(img_base_64)
 
42
 
43
- output_urls = generate_image(prompt, img_base_64, mask_base_64)
44
-
45
  output_images = [download_image(url) for url in output_urls[3:]] # Start from the 4th image
46
 
47
  return output_images
48
 
49
- def generate_image(prompt, img, mask):
50
  input_data = {
51
  "image": img,
52
- "prompt": prompt + ", expensive",
53
  "refine": "no_refiner",
54
  "scheduler": "K_EULER",
55
  "lora_scale": 0.8,
@@ -57,10 +60,10 @@ def generate_image(prompt, img, mask):
57
  "controlnet_1": "edge_canny",
58
  "controlnet_2": "depth_midas",
59
  "controlnet_3": "lineart",
60
- "guidance_scale": 7.5,
61
  "apply_watermark": False,
62
- "negative_prompt":"worst quality, low quality, illustration, 2d, painting, cartoons, sketch",
63
- "prompt_strength": 0.75,
64
  "sizing_strategy": "controlnet_1_image",
65
  "controlnet_1_end": 1,
66
  "controlnet_2_end": 1,
@@ -80,7 +83,7 @@ def generate_image(prompt, img, mask):
80
  if mask is not None:
81
  input_data["mask"] = mask
82
  else:
83
- input_data["prompt_strength"] = .6
84
 
85
  output = replicate.run(
86
  "fofr/realvisxl-v3-multi-controlnet-lora:90a4a3604cd637cb9f1a2bdae1cfa9ed869362ca028814cdce310a78e27daade",
@@ -133,7 +136,7 @@ def call_openai(image_data):
133
  {
134
  "role": "user",
135
  "content": [
136
- {"type": "text", "text": "Please describe this image in one sentence, with a focus on the material and specific color (like pantone level specificity) and details of the main object in the scene. Mention the type of lighting as well."},
137
  {
138
  "type": "image_url",
139
  "image_url": {
@@ -160,8 +163,9 @@ 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),
164
- outputs=[gr.Image(type="pil"), gr.Image(type="pil"), gr.Image(type="pil"), gr.Image(type="pil")]
 
165
  )
166
 
167
  demo.launch(share=False)
 
26
 
27
  client = OpenAI()
28
 
29
+ def main(img, strength):
30
  mask = img['layers'][0]
31
 
32
+ # Match prompt strength from .4 to 1 (total destruction)
33
+ prompt_strength = round(-0.6 * strength + 1, 2)
34
+
35
  base_image = Image.fromarray(img['background'].astype('uint8'))
36
  img_base_64 = img_to_base64(base_image)
37
 
 
42
  mask_base_64 = img_to_base64(mask_img)
43
 
44
  prompt = call_openai(img_base_64)
45
+ #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."
46
 
47
+ output_urls = generate_image(prompt, img_base_64, mask_base_64, prompt_strength)
 
48
  output_images = [download_image(url) for url in output_urls[3:]] # Start from the 4th image
49
 
50
  return output_images
51
 
52
+ def generate_image(prompt, img, mask, prompt_strength):
53
  input_data = {
54
  "image": img,
55
+ "prompt": prompt + " expensive",
56
  "refine": "no_refiner",
57
  "scheduler": "K_EULER",
58
  "lora_scale": 0.8,
 
60
  "controlnet_1": "edge_canny",
61
  "controlnet_2": "depth_midas",
62
  "controlnet_3": "lineart",
63
+ "guidance_scale": 4,
64
  "apply_watermark": False,
65
+ "negative_prompt":"worst quality, low quality, illustration, 2d, painting, cartoons, sketch, logo",
66
+ "prompt_strength": prompt_strength,
67
  "sizing_strategy": "controlnet_1_image",
68
  "controlnet_1_end": 1,
69
  "controlnet_2_end": 1,
 
83
  if mask is not None:
84
  input_data["mask"] = mask
85
  else:
86
+ input_data["prompt_strength"] = .3
87
 
88
  output = replicate.run(
89
  "fofr/realvisxl-v3-multi-controlnet-lora:90a4a3604cd637cb9f1a2bdae1cfa9ed869362ca028814cdce310a78e27daade",
 
136
  {
137
  "role": "user",
138
  "content": [
139
+ {"type": "text", "text": "Please describe this image in one sentence, with a focus on the material, finish and specific color (color is really important, so provide specific pantone colors), whether the color is warm or cool, and details of the main object in the scene. Mention the type of lighting as well."},
140
  {
141
  "type": "image_url",
142
  "image_url": {
 
163
  # Using the ImageEditor component to enable drawing on the image with limited colors
164
  demo = gr.Interface(
165
  fn=main,
166
+ inputs=[gr.ImageEditor(brush=black_brush), gr.Slider(0, 1, step=0.025, value=0.5, label="Image Strength")],
167
+ #outputs=[gr.Image(type="pil"), gr.Image(type="pil"), gr.Image(type="pil"), gr.Image(type="pil")]
168
+ outputs=["image", "image", "image", "image"]
169
  )
170
 
171
  demo.launch(share=False)