Spaces:
Running
Running
| import os | |
| import gradio | |
| from facefusion import state_manager, wording | |
| from facefusion.uis import core as ui_core | |
| def render() -> None: | |
| with gradio.Row(): | |
| gradio.Markdown("## 🔄 Быстрая загрузка файлов") | |
| with gradio.Row(): | |
| with gradio.Column(): | |
| source_upload = gradio.UploadButton( | |
| "Выбрать Source", | |
| file_types=["image"], | |
| file_count="single" | |
| ) | |
| ui_core.register_ui_component('quick_source_upload', source_upload) | |
| source_preview = gradio.Image( | |
| type="filepath", | |
| label="Source превью" | |
| ) | |
| ui_core.register_ui_component('quick_source_preview', source_preview) | |
| source_status = gradio.Markdown("Source не загружен") | |
| ui_core.register_ui_component('quick_source_status', source_status) | |
| with gradio.Column(): | |
| target_upload = gradio.UploadButton( | |
| "Выбрать Target", | |
| file_types=["image"], | |
| file_count="single" | |
| ) | |
| ui_core.register_ui_component('quick_target_upload', target_upload) | |
| target_preview = gradio.Image( | |
| type="filepath", | |
| label="Target превью" | |
| ) | |
| ui_core.register_ui_component('quick_target_preview', target_preview) | |
| target_status = gradio.Markdown("Target не загружен") | |
| ui_core.register_ui_component('quick_target_status', target_status) | |
| def listen() -> None: | |
| source_upload = ui_core.get_ui_component('quick_source_upload') | |
| source_preview = ui_core.get_ui_component('quick_source_preview') | |
| source_status = ui_core.get_ui_component('quick_source_status') | |
| target_upload = ui_core.get_ui_component('quick_target_upload') | |
| target_preview = ui_core.get_ui_component('quick_target_preview') | |
| target_status = ui_core.get_ui_component('quick_target_status') | |
| def update_source(file_path): | |
| if file_path: | |
| state_manager.set_item('source_paths', [file_path]) | |
| return file_path, f"Загружен: {os.path.basename(file_path)}" | |
| return None, "Source не загружен" | |
| def update_target(file_path): | |
| if file_path: | |
| state_manager.set_item('target_path', file_path) | |
| return file_path, f"Загружен: {os.path.basename(file_path)}" | |
| return None, "Target не загружен" | |
| if source_upload and source_preview and source_status: | |
| source_upload.upload( | |
| fn=update_source, | |
| inputs=[source_upload], | |
| outputs=[source_preview, source_status] | |
| ) | |
| if target_upload and target_preview and target_status: | |
| target_upload.upload( | |
| fn=update_target, | |
| inputs=[target_upload], | |
| outputs=[target_preview, target_status] | |
| ) |