ysharma HF staff commited on
Commit
8841a51
·
1 Parent(s): 26049de

Updated code to save the image, remove bug causing same image to pick up

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -38,7 +38,7 @@ be to the input. This pipeline requires a value of at least `1`. It's possible y
38
  """
39
 
40
  def chat(image_in, in_steps, in_guidance_scale, in_img_guidance_scale, image_hid, img_name, prompt, history, progress=gr.Progress(track_tqdm=True)):
41
- #progress(0, desc="Starting...")
42
  global counter
43
  counter += 1
44
  #if message == "revert": --to add revert functionality later
@@ -46,12 +46,12 @@ def chat(image_in, in_steps, in_guidance_scale, in_img_guidance_scale, image_hid
46
  # Open the image
47
  image_in = Image.open(img_name) #("edited_image.png") #(img_nm)
48
  edited_image = pipe(prompt, image=image_in, num_inference_steps=int(in_steps), guidance_scale=float(in_guidance_scale), image_guidance_scale=float(in_img_guidance_scale)).images[0]
49
- edited_image.save(img_name)
50
  else:
51
  seed = random.randint(0, 1000000)
52
  img_name = f"edited_image_{seed}.png"
53
  edited_image = pipe(prompt, image=image_in, num_inference_steps=int(in_steps), guidance_scale=float(in_guidance_scale), image_guidance_scale=float(in_img_guidance_scale)).images[0]
54
- edited_image.save(img_name) #("/tmp/edited_image.png") #(img_nm)
55
  history = history or []
56
  #Resizing (or not) the image for better display and adding supportive sample text
57
  add_text_list = ["There you go", "Enjoy your image!", "Nice work! Wonder what you gonna do next!", "Way to go!", "Does this work for you?", "Something like this?"]
 
38
  """
39
 
40
  def chat(image_in, in_steps, in_guidance_scale, in_img_guidance_scale, image_hid, img_name, prompt, history, progress=gr.Progress(track_tqdm=True)):
41
+ progress(0, desc="Starting...")
42
  global counter
43
  counter += 1
44
  #if message == "revert": --to add revert functionality later
 
46
  # Open the image
47
  image_in = Image.open(img_name) #("edited_image.png") #(img_nm)
48
  edited_image = pipe(prompt, image=image_in, num_inference_steps=int(in_steps), guidance_scale=float(in_guidance_scale), image_guidance_scale=float(in_img_guidance_scale)).images[0]
49
+ edited_image.save(img_name, overwrite=True)
50
  else:
51
  seed = random.randint(0, 1000000)
52
  img_name = f"edited_image_{seed}.png"
53
  edited_image = pipe(prompt, image=image_in, num_inference_steps=int(in_steps), guidance_scale=float(in_guidance_scale), image_guidance_scale=float(in_img_guidance_scale)).images[0]
54
+ edited_image.save(img_name, overwrite=True) #("/tmp/edited_image.png") #(img_nm)
55
  history = history or []
56
  #Resizing (or not) the image for better display and adding supportive sample text
57
  add_text_list = ["There you go", "Enjoy your image!", "Nice work! Wonder what you gonna do next!", "Way to go!", "Does this work for you?", "Something like this?"]