mirror of
https://github.com/Wan-Video/Wan2.1.git
synced 2025-11-04 14:16:57 +00:00
merged
This commit is contained in:
commit
132aee82d8
@ -52,9 +52,14 @@ def get_root_logger(logger_name='basicsr', log_level=logging.INFO, log_file=None
|
|||||||
initialized_logger[logger_name] = True
|
initialized_logger[logger_name] = True
|
||||||
return logger
|
return logger
|
||||||
|
|
||||||
|
match = re.match(r"^([0-9]+)\.([0-9]+)\.([0-9]+)", torch.__version__)
|
||||||
IS_HIGH_VERSION = [int(m) for m in list(re.findall(r"^([0-9]+)\.([0-9]+)\.([0-9]+)([^0-9][a-zA-Z0-9]*)?(\+git.*)?$",\
|
if match:
|
||||||
torch.__version__)[0][:3])] >= [1, 12, 0]
|
version_tuple = match.groups()
|
||||||
|
IS_HIGH_VERSION = [int(v) for v in version_tuple] >= [1, 12, 0]
|
||||||
|
else:
|
||||||
|
logger = get_root_logger()
|
||||||
|
logger.warning(f"Could not parse torch version '{torch.__version__}'. Assuming it's not a high version >= 1.12.0.")
|
||||||
|
IS_HIGH_VERSION = False
|
||||||
|
|
||||||
def gpu_is_available():
|
def gpu_is_available():
|
||||||
if IS_HIGH_VERSION:
|
if IS_HIGH_VERSION:
|
||||||
|
|||||||
112
wgp.py
112
wgp.py
@ -34,6 +34,8 @@ import atexit
|
|||||||
import shutil
|
import shutil
|
||||||
import glob
|
import glob
|
||||||
|
|
||||||
|
from tqdm import tqdm
|
||||||
|
import requests
|
||||||
global_queue_ref = []
|
global_queue_ref = []
|
||||||
AUTOSAVE_FILENAME = "queue.zip"
|
AUTOSAVE_FILENAME = "queue.zip"
|
||||||
PROMPT_VARS_MAX = 10
|
PROMPT_VARS_MAX = 10
|
||||||
@ -50,6 +52,30 @@ task_id = 0
|
|||||||
# progress_tracker = {}
|
# progress_tracker = {}
|
||||||
# tracker_lock = threading.Lock()
|
# tracker_lock = threading.Lock()
|
||||||
|
|
||||||
|
def download_ffmpeg():
|
||||||
|
if os.name != 'nt': return
|
||||||
|
exes = ['ffmpeg.exe', 'ffprobe.exe', 'ffplay.exe']
|
||||||
|
if all(os.path.exists(e) for e in exes): return
|
||||||
|
api_url = 'https://api.github.com/repos/GyanD/codexffmpeg/releases/latest'
|
||||||
|
r = requests.get(api_url, headers={'Accept': 'application/vnd.github+json'})
|
||||||
|
assets = r.json().get('assets', [])
|
||||||
|
zip_asset = next((a for a in assets if 'essentials_build.zip' in a['name']), None)
|
||||||
|
if not zip_asset: return
|
||||||
|
zip_url = zip_asset['browser_download_url']
|
||||||
|
zip_name = zip_asset['name']
|
||||||
|
with requests.get(zip_url, stream=True) as resp:
|
||||||
|
total = int(resp.headers.get('Content-Length', 0))
|
||||||
|
with open(zip_name, 'wb') as f, tqdm(total=total, unit='B', unit_scale=True) as pbar:
|
||||||
|
for chunk in resp.iter_content(chunk_size=8192):
|
||||||
|
f.write(chunk)
|
||||||
|
pbar.update(len(chunk))
|
||||||
|
with zipfile.ZipFile(zip_name) as z:
|
||||||
|
for f in z.namelist():
|
||||||
|
if f.endswith(tuple(exes)) and '/bin/' in f:
|
||||||
|
z.extract(f)
|
||||||
|
os.rename(f, os.path.basename(f))
|
||||||
|
os.remove(zip_name)
|
||||||
|
|
||||||
def format_time(seconds):
|
def format_time(seconds):
|
||||||
if seconds < 60:
|
if seconds < 60:
|
||||||
return f"{seconds:.1f}s"
|
return f"{seconds:.1f}s"
|
||||||
@ -755,11 +781,17 @@ def quit_application():
|
|||||||
import signal
|
import signal
|
||||||
os.kill(os.getpid(), signal.SIGINT)
|
os.kill(os.getpid(), signal.SIGINT)
|
||||||
|
|
||||||
def request_quit_confirmation():
|
def start_quit_process():
|
||||||
return gr.update(visible=False), gr.update(visible=True)
|
return 5, gr.update(visible=False), gr.update(visible=True)
|
||||||
|
|
||||||
def cancel_quit_confirmation():
|
def cancel_quit_process():
|
||||||
return gr.update(visible=True), gr.update(visible=False)
|
return -1, gr.update(visible=True), gr.update(visible=False)
|
||||||
|
|
||||||
|
def show_countdown_info_from_state(current_value: int):
|
||||||
|
if current_value > 0:
|
||||||
|
gr.Info(f"Quitting in {current_value}...")
|
||||||
|
return current_value - 1
|
||||||
|
return current_value
|
||||||
|
|
||||||
def autosave_queue():
|
def autosave_queue():
|
||||||
global global_queue_ref
|
global global_queue_ref
|
||||||
@ -1017,7 +1049,6 @@ def create_html_progress_bar(percentage=0.0, text="Idle", is_idle=True):
|
|||||||
"""
|
"""
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
|
||||||
def update_generation_status(html_content):
|
def update_generation_status(html_content):
|
||||||
if(html_content):
|
if(html_content):
|
||||||
return gr.update(value=html_content)
|
return gr.update(value=html_content)
|
||||||
@ -3811,51 +3842,46 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
|
|||||||
clear_queue_btn = gr.Button("Clear Queue", size="sm", variant="stop")
|
clear_queue_btn = gr.Button("Clear Queue", size="sm", variant="stop")
|
||||||
quit_button = gr.Button("Save and Quit", size="sm", variant="secondary")
|
quit_button = gr.Button("Save and Quit", size="sm", variant="secondary")
|
||||||
with gr.Row(visible=False) as quit_confirmation_row:
|
with gr.Row(visible=False) as quit_confirmation_row:
|
||||||
gr.Markdown("Quitting in 5 seconds...", elem_id="quit_timer_label")
|
confirm_quit_button = gr.Button("Confirm", elem_id="comfirm_quit_btn_hidden", size="sm", variant="stop")
|
||||||
confirm_quit_button = gr.Button("Confirm Quit Now", elem_id="comfirm_quit_btn_hidden", size="sm", variant="stop")
|
cancel_quit_button = gr.Button("Cancel", size="sm", variant="secondary")
|
||||||
cancel_quit_button = gr.Button("Cancel Quit", size="sm", variant="secondary")
|
|
||||||
hidden_force_quit_trigger = gr.Button("force_quit", visible=False, elem_id="force_quit_btn_hidden")
|
hidden_force_quit_trigger = gr.Button("force_quit", visible=False, elem_id="force_quit_btn_hidden")
|
||||||
|
hidden_countdown_state = gr.Number(value=-1, visible=False, elem_id="hidden_countdown_state_num")
|
||||||
|
single_hidden_trigger_btn = gr.Button("trigger_countdown", visible=False, elem_id="trigger_info_single_btn")
|
||||||
|
|
||||||
start_quit_timer_js = """
|
start_quit_timer_js = """
|
||||||
() => {
|
() => {
|
||||||
function findAndClickGradioButton(elemId) {
|
function findAndClickGradioButton(elemId) {
|
||||||
const gradioApp = document.querySelector('gradio-app') || document;
|
const gradioApp = document.querySelector('gradio-app') || document;
|
||||||
const button = gradioApp.querySelector(`#${elemId}`);
|
const button = gradioApp.querySelector(`#${elemId}`);
|
||||||
if (button) {
|
if (button) { button.click(); }
|
||||||
button.click();
|
}
|
||||||
|
|
||||||
|
if (window.quitCountdownTimeoutId) clearTimeout(window.quitCountdownTimeoutId);
|
||||||
|
|
||||||
|
let js_click_count = 0;
|
||||||
|
const max_clicks = 5;
|
||||||
|
|
||||||
|
function countdownStep() {
|
||||||
|
if (js_click_count < max_clicks) {
|
||||||
|
findAndClickGradioButton('trigger_info_single_btn');
|
||||||
|
js_click_count++;
|
||||||
|
window.quitCountdownTimeoutId = setTimeout(countdownStep, 1000);
|
||||||
|
} else {
|
||||||
|
findAndClickGradioButton('force_quit_btn_hidden');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window.quitTimerId = setTimeout(() => {
|
|
||||||
}, 5000);
|
countdownStep();
|
||||||
let countdown = 5;
|
|
||||||
const label = document.getElementById('quit_timer_label');
|
|
||||||
if (label) {
|
|
||||||
label.innerText = `M${countdown}...`;
|
|
||||||
window.quitCountdownInterval = setInterval(() => {
|
|
||||||
countdown--;
|
|
||||||
if (countdown > 0) {
|
|
||||||
label.innerText = `${countdown}`;
|
|
||||||
} else {
|
|
||||||
clearInterval(window.quitCountdownInterval);
|
|
||||||
findAndClickGradioButton('comfirm_quit_btn_hidden');
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cancel_quit_timer_js = """
|
cancel_quit_timer_js = """
|
||||||
() => {
|
() => {
|
||||||
if (window.quitTimerId) {
|
if (window.quitCountdownTimeoutId) {
|
||||||
clearTimeout(window.quitTimerId);
|
clearTimeout(window.quitCountdownTimeoutId);
|
||||||
window.quitTimerId = null;
|
window.quitCountdownTimeoutId = null;
|
||||||
|
console.log("Quit countdown cancelled (single trigger).");
|
||||||
}
|
}
|
||||||
if(window.quitCountdownInterval) {
|
|
||||||
clearInterval(window.quitCountdownInterval);
|
|
||||||
window.quitCountdownInterval = null;
|
|
||||||
}
|
|
||||||
const label = document.getElementById('quit_timer_label');
|
|
||||||
if(label) { label.innerText = 'Quit cancelled.'; }
|
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -3891,10 +3917,15 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
|
|||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
single_hidden_trigger_btn.click(
|
||||||
|
fn=show_countdown_info_from_state,
|
||||||
|
inputs=[hidden_countdown_state],
|
||||||
|
outputs=[hidden_countdown_state]
|
||||||
|
)
|
||||||
quit_button.click(
|
quit_button.click(
|
||||||
fn=request_quit_confirmation,
|
fn=start_quit_process,
|
||||||
inputs=[],
|
inputs=[],
|
||||||
outputs=[quit_button, quit_confirmation_row]
|
outputs=[hidden_countdown_state, quit_button, quit_confirmation_row]
|
||||||
).then(
|
).then(
|
||||||
fn=None, inputs=None, outputs=None, js=start_quit_timer_js
|
fn=None, inputs=None, outputs=None, js=start_quit_timer_js
|
||||||
)
|
)
|
||||||
@ -3903,12 +3934,14 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
|
|||||||
fn=quit_application,
|
fn=quit_application,
|
||||||
inputs=[],
|
inputs=[],
|
||||||
outputs=[]
|
outputs=[]
|
||||||
|
).then(
|
||||||
|
fn=None, inputs=None, outputs=None, js=cancel_quit_timer_js
|
||||||
)
|
)
|
||||||
|
|
||||||
cancel_quit_button.click(
|
cancel_quit_button.click(
|
||||||
fn=cancel_quit_confirmation,
|
fn=cancel_quit_process,
|
||||||
inputs=[],
|
inputs=[],
|
||||||
outputs=[quit_button, quit_confirmation_row]
|
outputs=[hidden_countdown_state, quit_button, quit_confirmation_row]
|
||||||
).then(
|
).then(
|
||||||
fn=None, inputs=None, outputs=None, js=cancel_quit_timer_js
|
fn=None, inputs=None, outputs=None, js=cancel_quit_timer_js
|
||||||
)
|
)
|
||||||
@ -4643,6 +4676,7 @@ def create_demo():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
atexit.register(autosave_queue)
|
atexit.register(autosave_queue)
|
||||||
|
download_ffmpeg()
|
||||||
# threading.Thread(target=runner, daemon=True).start()
|
# threading.Thread(target=runner, daemon=True).start()
|
||||||
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
||||||
server_port = int(args.server_port)
|
server_port = int(args.server_port)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user