Add clear button to benchmark and fire clear_temp() via the UI
This commit is contained in:
parent
27d8d3809d
commit
f3158ed4c1
@ -20,7 +20,7 @@ import facefusion.globals
|
|||||||
from facefusion import wording, metadata
|
from facefusion import wording, metadata
|
||||||
from facefusion.predictor import predict_image, predict_video
|
from facefusion.predictor import predict_image, predict_video
|
||||||
from facefusion.processors.frame.core import get_frame_processors_modules
|
from facefusion.processors.frame.core import get_frame_processors_modules
|
||||||
from facefusion.utilities import is_image, is_video, detect_fps, create_video, extract_frames, get_temp_frame_paths, restore_audio, create_temp, move_temp, clean_temp, normalize_output_path, list_module_names, decode_execution_providers, encode_execution_providers
|
from facefusion.utilities import is_image, is_video, detect_fps, create_video, extract_frames, get_temp_frame_paths, restore_audio, create_temp, move_temp, clear_temp, normalize_output_path, list_module_names, decode_execution_providers, encode_execution_providers
|
||||||
|
|
||||||
warnings.filterwarnings('ignore', category = FutureWarning, module = 'insightface')
|
warnings.filterwarnings('ignore', category = FutureWarning, module = 'insightface')
|
||||||
warnings.filterwarnings('ignore', category = UserWarning, module = 'torchvision')
|
warnings.filterwarnings('ignore', category = UserWarning, module = 'torchvision')
|
||||||
@ -191,8 +191,8 @@ def process_video() -> None:
|
|||||||
update_status(wording.get('restoring_audio_issues'))
|
update_status(wording.get('restoring_audio_issues'))
|
||||||
restore_audio(facefusion.globals.target_path, facefusion.globals.output_path)
|
restore_audio(facefusion.globals.target_path, facefusion.globals.output_path)
|
||||||
# clean temp
|
# clean temp
|
||||||
update_status(wording.get('cleaning_temp'))
|
update_status(wording.get('clearing_temp'))
|
||||||
clean_temp(facefusion.globals.target_path)
|
clear_temp(facefusion.globals.target_path)
|
||||||
# validate video
|
# validate video
|
||||||
if is_video(facefusion.globals.target_path):
|
if is_video(facefusion.globals.target_path):
|
||||||
update_status(wording.get('processing_video_succeed'))
|
update_status(wording.get('processing_video_succeed'))
|
||||||
@ -230,5 +230,5 @@ def run() -> None:
|
|||||||
|
|
||||||
def destroy() -> None:
|
def destroy() -> None:
|
||||||
if facefusion.globals.target_path:
|
if facefusion.globals.target_path:
|
||||||
clean_temp(facefusion.globals.target_path)
|
clear_temp(facefusion.globals.target_path)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
@ -9,17 +9,19 @@ from facefusion import wording
|
|||||||
from facefusion.capturer import get_video_frame_total
|
from facefusion.capturer import get_video_frame_total
|
||||||
from facefusion.core import conditional_process
|
from facefusion.core import conditional_process
|
||||||
from facefusion.uis.typing import Update
|
from facefusion.uis.typing import Update
|
||||||
from facefusion.utilities import normalize_output_path
|
from facefusion.utilities import normalize_output_path, clear_temp
|
||||||
|
|
||||||
BENCHMARK_RESULT_DATAFRAME : Optional[gradio.Dataframe] = None
|
BENCHMARK_RESULT_DATAFRAME : Optional[gradio.Dataframe] = None
|
||||||
BENCHMARK_CYCLES_SLIDER : Optional[gradio.Button] = None
|
BENCHMARK_CYCLES_SLIDER : Optional[gradio.Button] = None
|
||||||
BENCHMARK_START_BUTTON : Optional[gradio.Button] = None
|
BENCHMARK_START_BUTTON : Optional[gradio.Button] = None
|
||||||
|
BENCHMARK_CLEAR_BUTTON : Optional[gradio.Button] = None
|
||||||
|
|
||||||
|
|
||||||
def render() -> None:
|
def render() -> None:
|
||||||
global BENCHMARK_RESULT_DATAFRAME
|
global BENCHMARK_RESULT_DATAFRAME
|
||||||
global BENCHMARK_CYCLES_SLIDER
|
global BENCHMARK_CYCLES_SLIDER
|
||||||
global BENCHMARK_START_BUTTON
|
global BENCHMARK_START_BUTTON
|
||||||
|
global BENCHMARK_CLEAR_BUTTON
|
||||||
|
|
||||||
with gradio.Box():
|
with gradio.Box():
|
||||||
BENCHMARK_RESULT_DATAFRAME = gradio.Dataframe(
|
BENCHMARK_RESULT_DATAFRAME = gradio.Dataframe(
|
||||||
@ -27,7 +29,7 @@ def render() -> None:
|
|||||||
headers =
|
headers =
|
||||||
[
|
[
|
||||||
'target_path',
|
'target_path',
|
||||||
'cycles',
|
'benchmark_cycles',
|
||||||
'average_run',
|
'average_run',
|
||||||
'fastest_run',
|
'fastest_run',
|
||||||
'slowest_run',
|
'slowest_run',
|
||||||
@ -52,11 +54,14 @@ def render() -> None:
|
|||||||
value = 3,
|
value = 3,
|
||||||
maximum = 10
|
maximum = 10
|
||||||
)
|
)
|
||||||
BENCHMARK_START_BUTTON = gradio.Button(wording.get('start_button_label'))
|
with gradio.Row():
|
||||||
|
BENCHMARK_START_BUTTON = gradio.Button(wording.get('start_button_label'))
|
||||||
|
BENCHMARK_CLEAR_BUTTON = gradio.Button(wording.get('clear_button_label'))
|
||||||
|
|
||||||
|
|
||||||
def listen() -> None:
|
def listen() -> None:
|
||||||
BENCHMARK_START_BUTTON.click(update, inputs = BENCHMARK_CYCLES_SLIDER, outputs = BENCHMARK_RESULT_DATAFRAME)
|
BENCHMARK_START_BUTTON.click(update, inputs = BENCHMARK_CYCLES_SLIDER, outputs = BENCHMARK_RESULT_DATAFRAME)
|
||||||
|
BENCHMARK_CLEAR_BUTTON.click(clear, outputs = BENCHMARK_RESULT_DATAFRAME)
|
||||||
|
|
||||||
|
|
||||||
def update(benchmark_cycles : int) -> Update:
|
def update(benchmark_cycles : int) -> Update:
|
||||||
@ -74,10 +79,10 @@ def update(benchmark_cycles : int) -> Update:
|
|||||||
return gradio.update(value = value)
|
return gradio.update(value = value)
|
||||||
|
|
||||||
|
|
||||||
def benchmark(target_path : str, cycles : int) -> List[Any]:
|
def benchmark(target_path : str, benchmark_cycles : int) -> List[Any]:
|
||||||
process_times = []
|
process_times = []
|
||||||
total_fps = 0.0
|
total_fps = 0.0
|
||||||
for i in range(cycles + 1):
|
for i in range(benchmark_cycles + 1):
|
||||||
facefusion.globals.target_path = target_path
|
facefusion.globals.target_path = target_path
|
||||||
facefusion.globals.output_path = normalize_output_path(facefusion.globals.source_path, facefusion.globals.target_path, tempfile.gettempdir())
|
facefusion.globals.output_path = normalize_output_path(facefusion.globals.source_path, facefusion.globals.target_path, tempfile.gettempdir())
|
||||||
video_frame_total = get_video_frame_total(facefusion.globals.target_path)
|
video_frame_total = get_video_frame_total(facefusion.globals.target_path)
|
||||||
@ -89,16 +94,22 @@ def benchmark(target_path : str, cycles : int) -> List[Any]:
|
|||||||
if i > 0:
|
if i > 0:
|
||||||
process_times.append(process_time)
|
process_times.append(process_time)
|
||||||
total_fps += fps
|
total_fps += fps
|
||||||
average_process_time = round(statistics.mean(process_times), 2)
|
average_run = round(statistics.mean(process_times), 2)
|
||||||
fastest_process_time = round(min(process_times), 2)
|
fastest_run = round(min(process_times), 2)
|
||||||
slowest_process_time = round(max(process_times), 2)
|
slowest_run = round(max(process_times), 2)
|
||||||
average_fps = round(total_fps / cycles, 2)
|
relative_fps = round(total_fps / benchmark_cycles, 2)
|
||||||
return\
|
return\
|
||||||
[
|
[
|
||||||
facefusion.globals.target_path,
|
facefusion.globals.target_path,
|
||||||
cycles,
|
benchmark_cycles,
|
||||||
average_process_time,
|
average_run,
|
||||||
fastest_process_time,
|
fastest_run,
|
||||||
slowest_process_time,
|
slowest_run,
|
||||||
average_fps
|
relative_fps
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def clear() -> Update:
|
||||||
|
if facefusion.globals.target_path:
|
||||||
|
clear_temp(facefusion.globals.target_path)
|
||||||
|
return gradio.update(value = None)
|
||||||
|
@ -5,7 +5,7 @@ import facefusion.globals
|
|||||||
from facefusion import wording
|
from facefusion import wording
|
||||||
from facefusion.core import conditional_process
|
from facefusion.core import conditional_process
|
||||||
from facefusion.uis.typing import Update
|
from facefusion.uis.typing import Update
|
||||||
from facefusion.utilities import is_image, is_video, normalize_output_path
|
from facefusion.utilities import is_image, is_video, normalize_output_path, clear_temp
|
||||||
|
|
||||||
OUTPUT_START_BUTTON : Optional[gradio.Button] = None
|
OUTPUT_START_BUTTON : Optional[gradio.Button] = None
|
||||||
OUTPUT_CLEAR_BUTTON : Optional[gradio.Button] = None
|
OUTPUT_CLEAR_BUTTON : Optional[gradio.Button] = None
|
||||||
@ -50,4 +50,6 @@ def update() -> Tuple[Update, Update]:
|
|||||||
|
|
||||||
|
|
||||||
def clear() -> Tuple[Update, Update]:
|
def clear() -> Tuple[Update, Update]:
|
||||||
|
if facefusion.globals.target_path:
|
||||||
|
clear_temp(facefusion.globals.target_path)
|
||||||
return gradio.update(value = None), gradio.update(value = None)
|
return gradio.update(value = None), gradio.update(value = None)
|
||||||
|
@ -129,7 +129,7 @@ def move_temp(target_path : str, output_path : str) -> None:
|
|||||||
shutil.move(temp_output_path, output_path)
|
shutil.move(temp_output_path, output_path)
|
||||||
|
|
||||||
|
|
||||||
def clean_temp(target_path : str) -> None:
|
def clear_temp(target_path : str) -> None:
|
||||||
temp_directory_path = get_temp_directory_path(target_path)
|
temp_directory_path = get_temp_directory_path(target_path)
|
||||||
parent_directory_path = os.path.dirname(temp_directory_path)
|
parent_directory_path = os.path.dirname(temp_directory_path)
|
||||||
if not facefusion.globals.keep_temp and os.path.isdir(temp_directory_path):
|
if not facefusion.globals.keep_temp and os.path.isdir(temp_directory_path):
|
||||||
|
@ -27,7 +27,7 @@ WORDING =\
|
|||||||
'execution_providers_help': 'choose from the available execution providers (choices: {choices}, ...)',
|
'execution_providers_help': 'choose from the available execution providers (choices: {choices}, ...)',
|
||||||
'execution_thread_count_help': 'specify the number of execution threads',
|
'execution_thread_count_help': 'specify the number of execution threads',
|
||||||
'execution_queue_count_help': 'specify the number of execution queries',
|
'execution_queue_count_help': 'specify the number of execution queries',
|
||||||
'creating_temp': 'creating temporary resources',
|
'creating_temp': 'Creating temporary resources',
|
||||||
'extracting_frames_fps': 'Extracting frames with {fps} FPS',
|
'extracting_frames_fps': 'Extracting frames with {fps} FPS',
|
||||||
'processing': 'Processing',
|
'processing': 'Processing',
|
||||||
'downloading': 'Downloading',
|
'downloading': 'Downloading',
|
||||||
@ -37,7 +37,7 @@ WORDING =\
|
|||||||
'skipping_audio': 'Skipping audio',
|
'skipping_audio': 'Skipping audio',
|
||||||
'restoring_audio': 'Restoring audio',
|
'restoring_audio': 'Restoring audio',
|
||||||
'restoring_audio_issues': 'Restoring audio might cause issues as fps are not kept',
|
'restoring_audio_issues': 'Restoring audio might cause issues as fps are not kept',
|
||||||
'cleaning_temp': 'Cleaning temporary resources',
|
'clearing_temp': 'Clearing temporary resources',
|
||||||
'processing_image_succeed': 'Processing to image succeed',
|
'processing_image_succeed': 'Processing to image succeed',
|
||||||
'processing_image_failed': 'Processing to image failed',
|
'processing_image_failed': 'Processing to image failed',
|
||||||
'processing_video_succeed': 'Processing to video succeed',
|
'processing_video_succeed': 'Processing to video succeed',
|
||||||
|
Loading…
Reference in New Issue
Block a user