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
|
||||
return logger
|
||||
|
||||
|
||||
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.*)?$",\
|
||||
torch.__version__)[0][:3])] >= [1, 12, 0]
|
||||
match = re.match(r"^([0-9]+)\.([0-9]+)\.([0-9]+)", torch.__version__)
|
||||
if match:
|
||||
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():
|
||||
if IS_HIGH_VERSION:
|
||||
|
||||
112
wgp.py
112
wgp.py
@ -34,6 +34,8 @@ import atexit
|
||||
import shutil
|
||||
import glob
|
||||
|
||||
from tqdm import tqdm
|
||||
import requests
|
||||
global_queue_ref = []
|
||||
AUTOSAVE_FILENAME = "queue.zip"
|
||||
PROMPT_VARS_MAX = 10
|
||||
@ -50,6 +52,30 @@ task_id = 0
|
||||
# progress_tracker = {}
|
||||
# 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):
|
||||
if seconds < 60:
|
||||
return f"{seconds:.1f}s"
|
||||
@ -755,11 +781,17 @@ def quit_application():
|
||||
import signal
|
||||
os.kill(os.getpid(), signal.SIGINT)
|
||||
|
||||
def request_quit_confirmation():
|
||||
return gr.update(visible=False), gr.update(visible=True)
|
||||
def start_quit_process():
|
||||
return 5, gr.update(visible=False), gr.update(visible=True)
|
||||
|
||||
def cancel_quit_confirmation():
|
||||
return gr.update(visible=True), gr.update(visible=False)
|
||||
def cancel_quit_process():
|
||||
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():
|
||||
global global_queue_ref
|
||||
@ -1017,7 +1049,6 @@ def create_html_progress_bar(percentage=0.0, text="Idle", is_idle=True):
|
||||
"""
|
||||
return html
|
||||
|
||||
|
||||
def update_generation_status(html_content):
|
||||
if(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")
|
||||
quit_button = gr.Button("Save and Quit", size="sm", variant="secondary")
|
||||
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 Quit Now", elem_id="comfirm_quit_btn_hidden", size="sm", variant="stop")
|
||||
cancel_quit_button = gr.Button("Cancel Quit", size="sm", variant="secondary")
|
||||
confirm_quit_button = gr.Button("Confirm", elem_id="comfirm_quit_btn_hidden", size="sm", variant="stop")
|
||||
cancel_quit_button = gr.Button("Cancel", size="sm", variant="secondary")
|
||||
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 = """
|
||||
() => {
|
||||
function findAndClickGradioButton(elemId) {
|
||||
const gradioApp = document.querySelector('gradio-app') || document;
|
||||
const button = gradioApp.querySelector(`#${elemId}`);
|
||||
if (button) {
|
||||
button.click();
|
||||
if (button) { 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);
|
||||
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);
|
||||
}
|
||||
|
||||
countdownStep();
|
||||
}
|
||||
"""
|
||||
|
||||
cancel_quit_timer_js = """
|
||||
() => {
|
||||
if (window.quitTimerId) {
|
||||
clearTimeout(window.quitTimerId);
|
||||
window.quitTimerId = null;
|
||||
if (window.quitCountdownTimeoutId) {
|
||||
clearTimeout(window.quitCountdownTimeoutId);
|
||||
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(
|
||||
fn=request_quit_confirmation,
|
||||
fn=start_quit_process,
|
||||
inputs=[],
|
||||
outputs=[quit_button, quit_confirmation_row]
|
||||
outputs=[hidden_countdown_state, quit_button, quit_confirmation_row]
|
||||
).then(
|
||||
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,
|
||||
inputs=[],
|
||||
outputs=[]
|
||||
).then(
|
||||
fn=None, inputs=None, outputs=None, js=cancel_quit_timer_js
|
||||
)
|
||||
|
||||
cancel_quit_button.click(
|
||||
fn=cancel_quit_confirmation,
|
||||
fn=cancel_quit_process,
|
||||
inputs=[],
|
||||
outputs=[quit_button, quit_confirmation_row]
|
||||
outputs=[hidden_countdown_state, quit_button, quit_confirmation_row]
|
||||
).then(
|
||||
fn=None, inputs=None, outputs=None, js=cancel_quit_timer_js
|
||||
)
|
||||
@ -4643,6 +4676,7 @@ def create_demo():
|
||||
|
||||
if __name__ == "__main__":
|
||||
atexit.register(autosave_queue)
|
||||
download_ffmpeg()
|
||||
# threading.Thread(target=runner, daemon=True).start()
|
||||
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
||||
server_port = int(args.server_port)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user