ysharma HF staff commited on
Commit
830976f
·
1 Parent(s): 330dc1c

update debugging steps for saving image

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -49,7 +49,9 @@ def chat(image_in, in_steps, in_guidance_scale, in_img_guidance_scale, image_hid
49
  if os.path.exists(img_name):
50
  print("***Image exists and will be deleted***")
51
  os.remove(img_name)
52
- edited_image.save(img_name) #, overwrite=True)
 
 
53
  counter_out += 1
54
  else:
55
  print("FIRST PASS")
@@ -64,9 +66,14 @@ def chat(image_in, in_steps, in_guidance_scale, in_img_guidance_scale, image_hid
64
  history = history or []
65
  #Resizing (or not) the image for better display and adding supportive sample text
66
  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?"]
67
- response = random.choice(add_text_list) + '<img src="/file=' + img_name + '">' # style="width: 200px; height: 200px;">'
68
- history.append((prompt, response))
69
- return history, history, edited_image, img_name, counter_out
 
 
 
 
 
70
 
71
  with gr.Blocks() as demo:
72
  gr.Markdown("""<h1><center> Chat Interface with InstructPix2Pix: Give Image Editing Instructions [Apologies for inconvenience, this Space is still very much a work in progress...] </h1></center>
@@ -87,7 +94,7 @@ with gr.Blocks() as demo:
87
  in_img_guidance_scale = gr.Slider(1,10, step=0.5, label="Set Image Guidance scale", value=1.5)
88
  image_hid = gr.Image(visible=False,type='pil')
89
  img_name_temp_out = gr.Textbox(visible=False)
90
- counter_out = gr.Number(visible=False, value=0)
91
  chatbot = gr.Chatbot()
92
  b1.click(chat,[image_in, in_steps, in_guidance_scale, in_img_guidance_scale, image_hid, img_name_temp_out,counter_out, text_in, state_in], [chatbot, state_in, image_hid, img_name_temp_out, counter_out]) #, queue=True)
93
  gr.Markdown(help_text)
 
49
  if os.path.exists(img_name):
50
  print("***Image exists and will be deleted***")
51
  os.remove(img_name)
52
+ temp_img_name = img_name
53
+ print(f"temp_img_name is :{temp_img_name}")
54
+ edited_image.save(temp_img_name) #, overwrite=True)
55
  counter_out += 1
56
  else:
57
  print("FIRST PASS")
 
66
  history = history or []
67
  #Resizing (or not) the image for better display and adding supportive sample text
68
  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?"]
69
+ if counter_out == 0:
70
+ response = random.choice(add_text_list) + '<img src="/file=' + img_name + '">' # style="width: 200px; height: 200px;">'
71
+ history.append((prompt, response))
72
+ return history, history, edited_image, temp_img_name, counter_out
73
+ else:
74
+ response = random.choice(add_text_list) + '<img src="/file=' + temp_img_name + '">' # style="width: 200px; height: 200px;">'
75
+ history.append((prompt, response))
76
+ return history, history, edited_image, img_name, counter_out
77
 
78
  with gr.Blocks() as demo:
79
  gr.Markdown("""<h1><center> Chat Interface with InstructPix2Pix: Give Image Editing Instructions [Apologies for inconvenience, this Space is still very much a work in progress...] </h1></center>
 
94
  in_img_guidance_scale = gr.Slider(1,10, step=0.5, label="Set Image Guidance scale", value=1.5)
95
  image_hid = gr.Image(visible=False,type='pil')
96
  img_name_temp_out = gr.Textbox(visible=False)
97
+ counter_out = gr.Number(visible=False, value=0, precision='int')
98
  chatbot = gr.Chatbot()
99
  b1.click(chat,[image_in, in_steps, in_guidance_scale, in_img_guidance_scale, image_hid, img_name_temp_out,counter_out, text_in, state_in], [chatbot, state_in, image_hid, img_name_temp_out, counter_out]) #, queue=True)
100
  gr.Markdown(help_text)