Siyun He commited on
Commit
ccf40ad
·
1 Parent(s): 6c60e25

debug save function

Browse files
Files changed (2) hide show
  1. .DS_Store +0 -0
  2. app.py +27 -13
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
app.py CHANGED
@@ -290,20 +290,33 @@ def refresh_interface():
290
  # Return a message indicating the interface has been refreshed
291
  return "Interface refreshed!"
292
 
293
- def save_frame(frame):
294
- # Convert frame to RGB
295
- frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
 
 
 
 
 
 
296
 
297
- # Create a unique filename using the current timestamp
298
- filename = f"saved_frame_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png"
 
 
 
 
 
 
299
 
300
- # Save the frame
301
- cv2.imwrite(filename, frame)
302
 
303
- # Refresh the interfaceq
304
- refresh_interface()
305
 
306
- return f"Frame saved as '{filename}'"
 
307
 
308
  def webcam_input(frame, transform, lip_color):
309
  frame, face_shape, glass_shape = process_frame(frame)
@@ -321,7 +334,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="blue"))
321
  transform = gr.Dropdown(choices=["cartoon", "edges", "sepia", "negative", "sketch", "blur", "none"],
322
  value="none", label="Select Filter")
323
  lip_color = gr.Dropdown(choices=["classic_red", "deep_red", "cherry_red", "rose_red", "wine_red", "brick_red", "coral_red", "berry_red", "ruby_red", "crimson_red", "none"],
324
- value="none", label="Select Lip Color")
325
  gr.Markdown("Click the Webcam icon to start the camera, and then press the record button to start the virtual try-on.")
326
  input_img = gr.Image(sources=["webcam"], type="numpy", streaming=True)
327
  gr.Markdown("Face Shape and Recommended Glass Shape")
@@ -329,12 +342,13 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="blue"))
329
  glass_shape_output = gr.Textbox(label="Recommended Glass Shape")
330
  next_button = gr.Button("Next Glasses➡️")
331
  save_button = gr.Button("Save as a Picture📌")
 
332
 
333
  input_img.stream(webcam_input, [input_img, transform, lip_color], [input_img, face_shape_output, glass_shape_output], stream_every=0.1)
334
  with gr.Row():
335
- next_button.click(change_glasses, [], [])
336
  with gr.Row():
337
- save_button.click(save_frame, [input_img], [])
338
 
339
  if __name__ == "__main__":
340
  demo.launch(share=True)
 
290
  # Return a message indicating the interface has been refreshed
291
  return "Interface refreshed!"
292
 
293
+ # def save_frame(frame):
294
+ # # Convert frame to RGB
295
+ # frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
296
+
297
+ # # Create a unique filename using the current timestamp
298
+ # filename = f"saved_frame_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png"
299
+
300
+ # # Save the frame
301
+ # cv2.imwrite(filename, frame)
302
 
303
+ # # Refresh the interfaceq
304
+ # refresh_interface()
305
+
306
+ # return f"Frame saved as '{filename}'"
307
+
308
+ def save_frame(frame):
309
+ # Convert frame to RGB
310
+ frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
311
 
312
+ # Create a unique filename using the current timestamp
313
+ filename = f"saved_frame_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png"
314
 
315
+ # Save the frame to a temporary file
316
+ cv2.imwrite(filename, frame)
317
 
318
+ # Return the filename for download
319
+ return filename
320
 
321
  def webcam_input(frame, transform, lip_color):
322
  frame, face_shape, glass_shape = process_frame(frame)
 
334
  transform = gr.Dropdown(choices=["cartoon", "edges", "sepia", "negative", "sketch", "blur", "none"],
335
  value="none", label="Select Filter")
336
  lip_color = gr.Dropdown(choices=["classic_red", "deep_red", "cherry_red", "rose_red", "wine_red", "brick_red", "coral_red", "berry_red", "ruby_red", "crimson_red", "none"],
337
+ value="none", label="Select Lip Color")
338
  gr.Markdown("Click the Webcam icon to start the camera, and then press the record button to start the virtual try-on.")
339
  input_img = gr.Image(sources=["webcam"], type="numpy", streaming=True)
340
  gr.Markdown("Face Shape and Recommended Glass Shape")
 
342
  glass_shape_output = gr.Textbox(label="Recommended Glass Shape")
343
  next_button = gr.Button("Next Glasses➡️")
344
  save_button = gr.Button("Save as a Picture📌")
345
+ download_link = gr.File(label="Download Saved Image")
346
 
347
  input_img.stream(webcam_input, [input_img, transform, lip_color], [input_img, face_shape_output, glass_shape_output], stream_every=0.1)
348
  with gr.Row():
349
+ next_button.click(lambda: None, [], [])
350
  with gr.Row():
351
+ save_button.click(save_frame, [input_img], [download_link])
352
 
353
  if __name__ == "__main__":
354
  demo.launch(share=True)