root
commited on
Commit
·
ca82116
1
Parent(s):
b040c7e
fixing ifrbease update path
Browse files- __pycache__/handler.cpython-310.pyc +0 -0
- handler.py +55 -5
- sampler.py +5 -5
__pycache__/handler.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/handler.cpython-310.pyc and b/__pycache__/handler.cpython-310.pyc differ
|
|
|
handler.py
CHANGED
|
@@ -290,10 +290,10 @@ class EndpointHandler():
|
|
| 290 |
video_url = inputs.get("video_url", "")
|
| 291 |
width = inputs.get("width", 512)
|
| 292 |
height = inputs.get("height", 768)
|
| 293 |
-
length = inputs.get("length",
|
| 294 |
-
num_inference_steps = inputs.get("num_inference_steps",
|
| 295 |
cfg = inputs.get("cfg", 3.5)
|
| 296 |
-
seed = inputs.get("seed",
|
| 297 |
firebase_doc_id = inputs.get("firebase_doc_id", "")
|
| 298 |
|
| 299 |
base_dir = os.path.dirname(os.path.abspath(__file__))
|
|
@@ -323,6 +323,33 @@ class EndpointHandler():
|
|
| 323 |
ref_image_no_bg_path = os.path.join(video_root, "ref_image_no_bg.png")
|
| 324 |
ref_image_no_bg.save(ref_image_no_bg_path)
|
| 325 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
torch.manual_seed(seed)
|
| 327 |
|
| 328 |
pose_images = read_frames(downloaded_video_path)
|
|
@@ -361,15 +388,38 @@ class EndpointHandler():
|
|
| 361 |
if swap_result.returncode != 0:
|
| 362 |
raise RuntimeError(f"Error running face swap: {swap_result.stderr}")
|
| 363 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
torch.cuda.empty_cache()
|
| 365 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
with open(swapped_face_video_path, "rb") as video_file:
|
| 367 |
video_base64 = base64.b64encode(video_file.read()).decode("utf-8")
|
| 368 |
|
| 369 |
# Upload video to Firebase Storage
|
| 370 |
bucket = storage.bucket()
|
| 371 |
blob = bucket.blob(f"videos/{firebase_doc_id}/swapped_face_output.mp4")
|
| 372 |
-
blob.upload_from_filename(
|
| 373 |
|
| 374 |
# Make the file publicly accessible
|
| 375 |
blob.make_public()
|
|
@@ -379,6 +429,6 @@ class EndpointHandler():
|
|
| 379 |
# Update Firestore document
|
| 380 |
db = firestore.client()
|
| 381 |
doc_ref = db.collection('danceResults').document(firebase_doc_id)
|
| 382 |
-
doc_ref.update({"
|
| 383 |
|
| 384 |
return {"video": video_base64}
|
|
|
|
| 290 |
video_url = inputs.get("video_url", "")
|
| 291 |
width = inputs.get("width", 512)
|
| 292 |
height = inputs.get("height", 768)
|
| 293 |
+
length = inputs.get("length", 96)
|
| 294 |
+
num_inference_steps = inputs.get("num_inference_steps", 15)
|
| 295 |
cfg = inputs.get("cfg", 3.5)
|
| 296 |
+
seed = inputs.get("seed", -1)
|
| 297 |
firebase_doc_id = inputs.get("firebase_doc_id", "")
|
| 298 |
|
| 299 |
base_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
| 323 |
ref_image_no_bg_path = os.path.join(video_root, "ref_image_no_bg.png")
|
| 324 |
ref_image_no_bg.save(ref_image_no_bg_path)
|
| 325 |
|
| 326 |
+
# pose_output_path = os.path.join(temp_dir, "pose_videos")
|
| 327 |
+
|
| 328 |
+
# print("we are number 1")
|
| 329 |
+
# # Run the extract_dwpose_from_vid.py script
|
| 330 |
+
# extract_pose_path = os.path.join(base_dir, 'extract_dwpose_from_vid.py')
|
| 331 |
+
# command = f'python3 {extract_pose_path} --video_root {video_root}'
|
| 332 |
+
|
| 333 |
+
# # Run the command with shell=True
|
| 334 |
+
# result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
| 335 |
+
# if result.returncode != 0:
|
| 336 |
+
# raise RuntimeError(f"Error running extract_dwpose_from_vid.py: {result.stderr}")
|
| 337 |
+
# print("we are number 2")
|
| 338 |
+
|
| 339 |
+
# # Locate the extracted pose video
|
| 340 |
+
# save_dir = video_root + "_dwpose"
|
| 341 |
+
# print(f"Expected save directory: {save_dir}") # Debug statement
|
| 342 |
+
# pose_video_path = os.path.join(save_dir, "downloaded_video.mp4")
|
| 343 |
+
|
| 344 |
+
# if not os.path.exists(pose_video_path):
|
| 345 |
+
# print("Contents of the temporary directory:")
|
| 346 |
+
# self.print_directory_contents(temp_dir)
|
| 347 |
+
# raise FileNotFoundError(f"The pose video was not found at: {pose_video_path}")
|
| 348 |
+
|
| 349 |
+
# Speed up the pose video by 4x
|
| 350 |
+
# sped_up_pose_video_path = os.path.join(temp_dir, "sped_up_pose_video.mp4")
|
| 351 |
+
# self.speed_up_video(downloaded_video_path, sped_up_pose_video_path, factor=2)
|
| 352 |
+
|
| 353 |
torch.manual_seed(seed)
|
| 354 |
|
| 355 |
pose_images = read_frames(downloaded_video_path)
|
|
|
|
| 388 |
if swap_result.returncode != 0:
|
| 389 |
raise RuntimeError(f"Error running face swap: {swap_result.stderr}")
|
| 390 |
|
| 391 |
+
# Slow down the produced video by 4x
|
| 392 |
+
# self.print_directory_contents(temp_dir)
|
| 393 |
+
# slowed_down_animation_path = os.path.join(save_dir, "slowed_down_animation_output.mp4")
|
| 394 |
+
# self.slow_down_video(swapped_face_video_path, slowed_down_animation_path, factor=2)
|
| 395 |
+
|
| 396 |
+
|
| 397 |
torch.cuda.empty_cache()
|
| 398 |
|
| 399 |
+
#remove background
|
| 400 |
+
# self.print_directory_contents()
|
| 401 |
+
# removed_background_output_path = os.path.join(save_dir, "removed_background_result.mp4")
|
| 402 |
+
# remove_background_script_path = os.path.join(base_dir, "rembg_video.py")
|
| 403 |
+
# remove_background_command = f'python3 {remove_background_script_path} {swapped_face_video_path} {removed_background_output_path}'
|
| 404 |
+
# print("Command is " + remove_background_command)
|
| 405 |
+
# remove_background_result = subprocess.run(remove_background_command, shell=True, capture_output=True, text=True)
|
| 406 |
+
# if remove_background_result.returncode != 0:
|
| 407 |
+
# raise RuntimeError(f"Error running removing backgriund: {remove_background_result.stderr}")
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
# Perform RIFE interpolation
|
| 411 |
+
# self.print_directory_contents(temp_dir)
|
| 412 |
+
# rife_output_path = os.path.join(save_dir, "completed_result.mp4")
|
| 413 |
+
# self.run_rife_interpolation(swapped_face_video_path, rife_output_path, multi=2, scale=0.5)
|
| 414 |
+
|
| 415 |
+
|
| 416 |
with open(swapped_face_video_path, "rb") as video_file:
|
| 417 |
video_base64 = base64.b64encode(video_file.read()).decode("utf-8")
|
| 418 |
|
| 419 |
# Upload video to Firebase Storage
|
| 420 |
bucket = storage.bucket()
|
| 421 |
blob = bucket.blob(f"videos/{firebase_doc_id}/swapped_face_output.mp4")
|
| 422 |
+
blob.upload_from_filename(slowed_down_animation_path)
|
| 423 |
|
| 424 |
# Make the file publicly accessible
|
| 425 |
blob.make_public()
|
|
|
|
| 429 |
# Update Firestore document
|
| 430 |
db = firestore.client()
|
| 431 |
doc_ref = db.collection('danceResults').document(firebase_doc_id)
|
| 432 |
+
doc_ref.update({"videoResultUrl": video_url})
|
| 433 |
|
| 434 |
return {"video": video_base64}
|
sampler.py
CHANGED
|
@@ -22,12 +22,12 @@ handler = EndpointHandler()
|
|
| 22 |
# Define sample inputs
|
| 23 |
inputs = {
|
| 24 |
"inputs": {
|
| 25 |
-
"ref_image_url": "https://media.discordapp.net/attachments/1237667074210267217/
|
| 26 |
-
"video_url": "https://firebasestorage.googleapis.com/v0/b/quiz-app-edffe.appspot.com/o/
|
| 27 |
-
"length":
|
| 28 |
-
"num_inference_steps":
|
| 29 |
"cfg": 3.5,
|
| 30 |
-
"seed":
|
| 31 |
"firebase_doc_id" : "0gkm91Ao0GsmQ2WdLP9c"
|
| 32 |
}
|
| 33 |
}
|
|
|
|
| 22 |
# Define sample inputs
|
| 23 |
inputs = {
|
| 24 |
"inputs": {
|
| 25 |
+
"ref_image_url": "https://media.discordapp.net/attachments/1237667074210267217/1247398713228263494/image.jpg?ex=665fe214&is=665e9094&hm=ba3863d8149e4e43c6ec271b09fcd4027b6a58cc65b7a658797ab9fbc74b4808&=&format=webp&width=896&height=1194",
|
| 26 |
+
"video_url": "https://firebasestorage.googleapis.com/v0/b/quiz-app-edffe.appspot.com/o/tell_my_bf_shortened_pose.mp4?alt=media&token=d3b7cb47-6fbb-435c-94a7-2cbd62705efb",
|
| 27 |
+
"length": 48,
|
| 28 |
+
"num_inference_steps": 15,
|
| 29 |
"cfg": 3.5,
|
| 30 |
+
"seed": -1,
|
| 31 |
"firebase_doc_id" : "0gkm91Ao0GsmQ2WdLP9c"
|
| 32 |
}
|
| 33 |
}
|