Ii commited on
Commit
7e981ff
·
verified ·
1 Parent(s): 8b9f861

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -57,10 +57,16 @@ def run(*vars):
57
  })
58
 
59
  # Call refacer to process video and get file path
60
- refaced_video_path = refacer.reface(video_path, faces) # refaced video path
61
- print(f"Refaced video can be found at {refaced_video_path}")
62
 
63
- return refaced_video_path # Return the file path to show in Gradio output
 
 
 
 
 
 
 
64
 
65
  # Prepare Gradio components
66
  origin = []
@@ -72,7 +78,7 @@ with gr.Blocks() as demo:
72
  gr.Markdown("# Refacer")
73
  with gr.Row():
74
  video = gr.Video(label="Original video", format="mp4")
75
- video2 = gr.Video(label="Refaced video", interactive=False, format="mp4")
76
 
77
  for i in range(0, num_faces):
78
  with gr.Tab(f"Face #{i+1}"):
@@ -85,6 +91,7 @@ with gr.Blocks() as demo:
85
  with gr.Row():
86
  button = gr.Button("Reface", variant="primary")
87
 
 
88
  button.click(fn=run, inputs=[video] + origin + destination + thresholds, outputs=[video2])
89
 
90
  # Launch the Gradio app
 
57
  })
58
 
59
  # Call refacer to process video and get file path
60
+ refaced_video_path = refacer.reface(video_path, faces)
 
61
 
62
+ # Convert the refaced video to bytes
63
+ with open(refaced_video_path, "rb") as f:
64
+ video_bytes = f.read()
65
+
66
+ # Delete the temporary video file
67
+ os.remove(refaced_video_path)
68
+
69
+ return video_bytes # Return the video bytes for Gradio output
70
 
71
  # Prepare Gradio components
72
  origin = []
 
78
  gr.Markdown("# Refacer")
79
  with gr.Row():
80
  video = gr.Video(label="Original video", format="mp4")
81
+ video2 = gr.Video(label="Refaced video", interactive=False, format="mp4") # Gradio UI only
82
 
83
  for i in range(0, num_faces):
84
  with gr.Tab(f"Face #{i+1}"):
 
91
  with gr.Row():
92
  button = gr.Button("Reface", variant="primary")
93
 
94
+ # Connect the button to the run function
95
  button.click(fn=run, inputs=[video] + origin + destination + thresholds, outputs=[video2])
96
 
97
  # Launch the Gradio app