add wan animate
Browse filesFiles changed (2)
- app.py+382-7
- requirements.txt+2-1
37 unmodified lines3839404142433635 unmodified lines367936803681368236833684646 unmodified lines433143324333433443354336433723 unmodified lines436143624363436443654366436743681147 unmodified lines5516551755185519552055215522270 unmodified lines57935794579557965797579868 unmodified lines58675868586958705871587226 unmodified lines589959005901590259035904435 unmodified lines63406341634263436344634529 unmodified lines6375637663776378637963801293 unmodified lines76747675767676777678767939 unmodified lines771977207721772277237724546 unmodified lines827182728273827482758276827790 unmodified lines83688369837083718372837373 unmodified lines84478448844984508451845267 unmodified lines85208521852285238524852524 unmodified lines8550855185528553855485553 unmodified lines855985608561856285638564856525 unmodified lines85918592859385948595859685971 unmodified line85998600860186028603860422 unmodified lines8627862886298630863186321 unmodified line863486358636863786388639864019 unmodified lines86608661866286638664866537 unmodified linesimport asynciofrom datetime import datetime, timedeltafrom typing import Optional# Gradio supported languages for syntax highlightingGRADIO_SUPPORTED_LANGUAGES = [3635 unmodified linesexcept Exception as e:return f"Error generating music: {str(e)}"def extract_image_prompts_from_text(text: str, num_images_needed: int = 1) -> list:"""Extract image generation prompts from the full text based on number of images needed"""# Use the entire text as the base prompt for image generation646 unmodified linesprint("[Video2Video] No <body> tag; appending video via replacement block")return f"{SEARCH_START}\n\n{DIVIDER}\n{video_html}\n{REPLACE_END}"def apply_generated_media_to_html(html_content: str, user_prompt: str, enable_text_to_image: bool, enable_image_to_image: bool, input_image_data, image_to_image_prompt: str | None = None, text_to_image_prompt: str | None = None, enable_image_to_video: bool = False, image_to_video_prompt: str | None = None, session_id: Optional[str] = None, enable_text_to_video: bool = False, text_to_video_prompt: Optional[str] = None, enable_video_to_video: bool = False, video_to_video_prompt: Optional[str] = None, input_video_data = None, enable_text_to_music: bool = False, text_to_music_prompt: Optional[str] = None, token: gr.OAuthToken | None = None) -> str:"""Apply text/image/video/music replacements to HTML content.- Works with single-document HTML strings23 unmodified linestry:print(f"[MediaApply] enable_i2v={enable_image_to_video}, enable_i2i={enable_image_to_image}, "f"enable_t2i={enable_text_to_image}, enable_t2v={enable_text_to_video}, enable_v2v={enable_video_to_video}, enable_t2m={enable_text_to_music}, has_image={input_image_data is not None}, has_video={input_video_data is not None}")# If image-to-video is enabled, replace the first image with a generated video and return.if enable_image_to_video and input_image_data is not None and (result.strip().startswith('<!DOCTYPE html>') or result.strip().startswith('<html')):i2v_prompt = (image_to_video_prompt or user_prompt or "").strip()1147 unmodified linesstop_generation = Falsedef generation_code(query: Optional[str], vlm_image: Optional[gr.Image], gen_image: Optional[gr.Image], file: Optional[str], website_url: Optional[str], _setting: Dict[str, str], _history: Optional[History], _current_model: Dict, enable_search: bool = False, language: str = "html", provider: str = "auto", enable_image_generation: bool = False, enable_image_to_image: bool = False, image_to_image_prompt: Optional[str] = None, text_to_image_prompt: Optional[str] = None, enable_image_to_video: bool = False, image_to_video_prompt: Optional[str] = None, enable_text_to_video: bool = False, text_to_video_prompt: Optional[str] = None, enable_video_to_video: bool = False, video_to_video_prompt: Optional[str] = None, input_video_data = None, enable_text_to_music: bool = False, text_to_music_prompt: Optional[str] = None):if query is None:query = ''if _history is None:270 unmodified linesinput_video_data=input_video_data,enable_text_to_music=enable_text_to_music,text_to_music_prompt=text_to_music_prompt,)_history.append([query, final_content])68 unmodified linesinput_video_data=input_video_data,enable_text_to_music=enable_text_to_music,text_to_music_prompt=text_to_music_prompt,token=None,)26 unmodified linesinput_video_data=input_video_data,enable_text_to_music=enable_text_to_music,text_to_music_prompt=text_to_music_prompt,token=None,)else:435 unmodified linesinput_video_data=input_video_data,enable_text_to_music=enable_text_to_music,text_to_music_prompt=text_to_music_prompt,token=None,)29 unmodified linesinput_video_data=input_video_data,enable_text_to_music=enable_text_to_music,text_to_music_prompt=text_to_music_prompt,)_history.append([query, final_content])1293 unmodified linesvisible=False)# LLM-guided media placement is now always on (no toggle in UI)def on_image_to_image_toggle(toggled, beta_enabled):39 unmodified linesinputs=[text_to_music_toggle, beta_toggle],outputs=[text_to_music_prompt])model_dropdown = gr.Dropdown(choices=[model['name'] for model in AVAILABLE_MODELS],value=DEFAULT_MODEL_NAME,546 unmodified linesshow_progress="hidden",).then(generation_code,inputs=[input, image_input, generation_image_input, file_input, website_url_input, setting, history, current_model, search_toggle, language_dropdown, provider_state, image_generation_toggle, image_to_image_toggle, image_to_image_prompt, text_to_image_prompt, image_to_video_toggle, image_to_video_prompt, text_to_video_toggle, text_to_video_prompt, video_to_video_toggle, video_to_video_prompt, video_input, text_to_music_toggle, text_to_music_prompt],outputs=[code_output, history, sandbox, history_output]).then(end_generation_ui,90 unmodified linesupd_current_model = gr.skip()upd_t2m_toggle = gr.skip()upd_t2m_prompt = gr.skip()# Split by comma to separate main prompt and directivessegments = [seg.strip() for seg in (text or "").split(",") if seg.strip()]73 unmodified linesif p:upd_t2m_prompt = gr.update(value=p)# URL (website redesign)url = _extract_url(seg)if url:67 unmodified linesupd_current_model,upd_t2m_toggle,upd_t2m_prompt,)# Wire chat submit -> apply settings -> run generation24 unmodified linescurrent_model,text_to_music_toggle,text_to_music_prompt,],queue=False,).then(3 unmodified linesshow_progress="hidden",).then(generation_code,inputs=[input, image_input, generation_image_input, file_input, website_url_input, setting, history, current_model, search_toggle, language_dropdown, provider_state, image_generation_toggle, image_to_image_toggle, image_to_image_prompt, text_to_image_prompt, image_to_video_toggle, image_to_video_prompt, text_to_video_toggle, text_to_video_prompt, video_to_video_toggle, video_to_video_prompt, video_input, text_to_music_toggle, text_to_music_prompt],outputs=[code_output, history, sandbox, history_output]).then(end_generation_ui,25 unmodified lines)# Toggle between classic controls and beta chat UIdef toggle_beta(checked: bool, t2i: bool, i2i: bool, i2v: bool, t2v: bool, v2v: bool, t2m: bool):# Prompts only visible in classic mode and when their toggles are ont2i_vis = (not checked) and bool(t2i)i2i_vis = (not checked) and bool(i2i)1 unmodified linet2v_vis = (not checked) and bool(t2v)v2v_vis = (not checked) and bool(v2v)t2m_vis = (not checked) and bool(t2m)return (# Chat UI group22 unmodified linesgr.update(visible=v2v_vis), # video_inputgr.update(visible=not checked), # text_to_music_togglegr.update(visible=t2m_vis), # text_to_music_promptgr.update(visible=not checked), # model_dropdowngr.update(visible=not checked), # quick_start_mdgr.update(visible=not checked), # quick_examples_col1 unmodified linebeta_toggle.change(toggle_beta,inputs=[beta_toggle, image_generation_toggle, image_to_image_toggle, image_to_video_toggle, text_to_video_toggle, video_to_video_toggle, text_to_music_toggle],outputs=[sidebar_chatbot,sidebar_msg,19 unmodified linesvideo_input,text_to_music_toggle,text_to_music_prompt,model_dropdown,quick_start_md,quick_examples_col,37 unmodified lines38394041424344453635 unmodified lines3681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906646 unmodified lines455345544555455645574558455923 unmodified lines4583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846391147 unmodified lines5787578857895790579157925793270 unmodified lines6064606560666067606860696070607160726073607468 unmodified lines614361446145614661476148614961506151615226 unmodified lines6179618061816182618361846185618661876188435 unmodified lines662466256626662766286629663066316632663329 unmodified lines666366646665666666676668666966706671667266731293 unmodified lines7967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800439 unmodified lines804480458046804780488049805080518052805380548055805680578058805980608061806280638064546 unmodified lines861186128613861486158616861790 unmodified lines870887098710871187128713871487158716871773 unmodified lines8791879287938794879587968797879887998800880188028803880488058806880788088809881067 unmodified lines887888798880888188828883888488858886888724 unmodified lines89128913891489158916891789188919892089213 unmodified lines892589268927892889298930893125 unmodified lines89578958895989608961896289631 unmodified line896589668967896889698970897122 unmodified lines89948995899689978998899990009001900290031 unmodified line900590069007900890099010901119 unmodified lines903190329033903490359036903790389039904037 unmodified linesimport asynciofrom datetime import datetime, timedeltafrom typing import Optionalimport dashscopefrom dashscope.utils.oss_utils import check_and_upload_local# Gradio supported languages for syntax highlightingGRADIO_SUPPORTED_LANGUAGES = [3635 unmodified linesexcept Exception as e:return f"Error generating music: {str(e)}"class WanAnimateApp:"""Wan2.2-Animate integration for character animation and video replacement using DashScope API"""def __init__(self):self.api_key = os.getenv("DASHSCOPE_API_KEY")if self.api_key:dashscope.api_key = self.api_keyself.url = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis/"self.get_url = "https://dashscope.aliyuncs.com/api/v1/tasks/"def predict(self, ref_img, video, model_id, model):"""Generate animated video using Wan2.2-AnimateArgs:ref_img: Reference image file pathvideo: Template video file pathmodel_id: Animation mode ("wan2.2-animate-move" or "wan2.2-animate-mix")model: Inference quality ("wan-pro" or "wan-std")Returns:Tuple of (video_url, status_message)"""if not self.api_key:return None, "Error: DASHSCOPE_API_KEY environment variable is not set"try:# Upload files to OSS if needed and get URLs_, image_url = check_and_upload_local(model_id, ref_img, self.api_key)_, video_url = check_and_upload_local(model_id, video, self.api_key)# Prepare the request payloadpayload = {"model": model_id,"input": {"image_url": image_url,"video_url": video_url},"parameters": {"check_image": True,"mode": model,}}# Set up headersheaders = {"X-DashScope-Async": "enable","X-DashScope-OssResourceResolve": "enable","Authorization": f"Bearer {self.api_key}","Content-Type": "application/json"}# Make the initial API requestresponse = requests.post(self.url, json=payload, headers=headers)# Check if request was successfulif response.status_code != 200:error_msg = f"Initial request failed with status code {response.status_code}: {response.text}"print(f"[WanAnimate] {error_msg}")return None, error_msg# Get the task ID from responseresult = response.json()task_id = result.get("output", {}).get("task_id")if not task_id:error_msg = "Failed to get task ID from response"print(f"[WanAnimate] {error_msg}")return None, error_msg# Poll for resultsget_url = f"{self.get_url}/{task_id}"headers = {"Authorization": f"Bearer {self.api_key}","Content-Type": "application/json"}max_attempts = 60 # 5 minutes max wait timeattempt = 0while attempt < max_attempts:response = requests.get(get_url, headers=headers)if response.status_code != 200:error_msg = f"Failed to get task status: {response.status_code}: {response.text}"print(f"[WanAnimate] {error_msg}")return None, error_msgresult = response.json()print(f"[WanAnimate] Task status check {attempt + 1}: {result}")task_status = result.get("output", {}).get("task_status")if task_status == "SUCCEEDED":# Task completed successfully, return video URLvideo_url = result["output"]["results"]["video_url"]print(f"[WanAnimate] Animation completed successfully: {video_url}")return video_url, "SUCCEEDED"elif task_status == "FAILED":# Task failed, return error messageerror_msg = result.get("output", {}).get("message", "Unknown error")code_msg = result.get("output", {}).get("code", "Unknown code")full_error = f"Task failed: {error_msg} Code: {code_msg} TaskId: {task_id}"print(f"[WanAnimate] {full_error}")return None, full_errorelse:# Task is still running, wait and retrytime.sleep(5) # Wait 5 seconds before polling againattempt += 1# Timeout reachedtimeout_msg = f"Animation generation timed out after {max_attempts * 5} seconds. TaskId: {task_id}"print(f"[WanAnimate] {timeout_msg}")return None, timeout_msgexcept Exception as e:error_msg = f"Exception during animation generation: {str(e)}"print(f"[WanAnimate] {error_msg}")return None, error_msgdef generate_animation_from_image_video(input_image_data, input_video_data, prompt: str, model_id: str = "wan2.2-animate-move", model: str = "wan-pro", session_id: Optional[str] = None, token: gr.OAuthToken | None = None) -> str:"""Generate animated video from reference image and template video using Wan2.2-Animate.Returns an HTML <video> tag whose source points to a temporary file URL."""try:print(f"[ImageVideo2Animation] Starting animation generation with model={model_id}, quality={model}")if not os.getenv("DASHSCOPE_API_KEY"):print("[ImageVideo2Animation] Missing DASHSCOPE_API_KEY")return "Error: DASHSCOPE_API_KEY environment variable is not set. Please configure your DashScope API key."# Normalize inputs to file pathsdef _save_to_temp_file(data, suffix):if isinstance(data, str) and os.path.exists(data):return dataelif hasattr(data, 'name') and os.path.exists(data.name):return data.nameelse:# Save to temporary filetemp_file = tempfile.NamedTemporaryFile(delete=False, suffix=suffix)if hasattr(data, 'read'):temp_file.write(data.read())elif isinstance(data, (bytes, bytearray)):temp_file.write(data)elif isinstance(data, np.ndarray):# Handle numpy array (likely image data)if suffix.lower() in ['.jpg', '.jpeg', '.png']:# Convert numpy array to imagefrom PIL import Imageif data.dtype != np.uint8:data = (data * 255).astype(np.uint8)if len(data.shape) == 3 and data.shape[2] == 3:# RGB imageimg = Image.fromarray(data, 'RGB')elif len(data.shape) == 3 and data.shape[2] == 4:# RGBA imageimg = Image.fromarray(data, 'RGBA')elif len(data.shape) == 2:# Grayscale imageimg = Image.fromarray(data, 'L')else:raise ValueError(f"Unsupported numpy array shape for image: {data.shape}")img.save(temp_file.name, format='JPEG' if suffix.lower() in ['.jpg', '.jpeg'] else 'PNG')else:raise ValueError(f"Cannot save numpy array as {suffix} format")else:raise ValueError(f"Unsupported data type: {type(data)}")temp_file.close()return temp_file.nameref_img_path = _save_to_temp_file(input_image_data, '.jpg')video_path = _save_to_temp_file(input_video_data, '.mp4')print(f"[ImageVideo2Animation] Input files prepared: image={ref_img_path}, video={video_path}")# Initialize WanAnimateApp and generate animationwan_app = WanAnimateApp()video_url, status = wan_app.predict(ref_img_path, video_path, model_id, model)if video_url and status == "SUCCEEDED":print(f"[ImageVideo2Animation] Animation generated successfully: {video_url}")# Download the video and create temporary URLtry:response = requests.get(video_url, timeout=60)response.raise_for_status()video_bytes = response.contentfilename = "wan_animate_result.mp4"temp_url = upload_media_to_hf(video_bytes, filename, "video", token, use_temp=True)if temp_url.startswith("Error"):print(f"[ImageVideo2Animation] Failed to upload video: {temp_url}")return temp_url# Create video HTML tagvideo_html = (f'<video controls autoplay muted loop playsinline 'f'style="max-width:100%; height:auto; border-radius:8px; box-shadow:0 4px 8px rgba(0,0,0,0.1)" 'f'onerror="this.style.display=\'none\'; console.error(\'Animation video failed to load\')">'f'<source src="{temp_url}" type="video/mp4" />'f'<p style="text-align: center; color: #666;">Your browser does not support the video tag.</p>'f'</video>')print(f"[ImageVideo2Animation] Successfully created animation HTML with temporary URL: {temp_url}")return video_htmlexcept Exception as e:error_msg = f"Failed to download generated animation: {str(e)}"print(f"[ImageVideo2Animation] {error_msg}")return f"Error: {error_msg}"else:error_msg = f"Animation generation failed: {status}"print(f"[ImageVideo2Animation] {error_msg}")return f"Error: {error_msg}"except Exception as e:print(f"[ImageVideo2Animation] Exception during generation:")print(f"Animation generation error: {str(e)}")return f"Error generating animation: {str(e)}"def extract_image_prompts_from_text(text: str, num_images_needed: int = 1) -> list:"""Extract image generation prompts from the full text based on number of images needed"""# Use the entire text as the base prompt for image generation646 unmodified linesprint("[Video2Video] No <body> tag; appending video via replacement block")return f"{SEARCH_START}\n\n{DIVIDER}\n{video_html}\n{REPLACE_END}"def apply_generated_media_to_html(html_content: str, user_prompt: str, enable_text_to_image: bool, enable_image_to_image: bool, input_image_data, image_to_image_prompt: str | None = None, text_to_image_prompt: str | None = None, enable_image_to_video: bool = False, image_to_video_prompt: str | None = None, session_id: Optional[str] = None, enable_text_to_video: bool = False, text_to_video_prompt: Optional[str] = None, enable_video_to_video: bool = False, video_to_video_prompt: Optional[str] = None, input_video_data = None, enable_text_to_music: bool = False, text_to_music_prompt: Optional[str] = None, enable_image_video_to_animation: bool = False, animation_mode: str = "wan2.2-animate-move", animation_quality: str = "wan-pro", animation_video_data = None, token: gr.OAuthToken | None = None) -> str:"""Apply text/image/video/music replacements to HTML content.- Works with single-document HTML strings23 unmodified linestry:print(f"[MediaApply] enable_i2v={enable_image_to_video}, enable_i2i={enable_image_to_image}, "f"enable_t2i={enable_text_to_image}, enable_t2v={enable_text_to_video}, enable_v2v={enable_video_to_video}, enable_t2m={enable_text_to_music}, enable_iv2a={enable_image_video_to_animation}, has_image={input_image_data is not None}, has_video={input_video_data is not None}, has_anim_video={animation_video_data is not None}")# If image+video-to-animation is enabled, generate animated video and return.if enable_image_video_to_animation and input_image_data is not None and animation_video_data is not None and (result.strip().startswith('<!DOCTYPE html>') or result.strip().startswith('<html')):print(f"[MediaApply] Running image+video-to-animation with mode={animation_mode}, quality={animation_quality}")try:animation_html_tag = generate_animation_from_image_video(input_image_data,animation_video_data,user_prompt or "",model_id=animation_mode,model=animation_quality,session_id=session_id,token=token)if not (animation_html_tag or "").startswith("Error"):# Validate animation video HTML before attempting placementif validate_video_html(animation_html_tag):blocks_anim = llm_place_media(result, animation_html_tag, media_kind="video")else:print("[MediaApply] Generated animation HTML failed validation, skipping LLM placement")blocks_anim = ""else:print(f"[MediaApply] Animation generation failed: {animation_html_tag}")blocks_anim = ""except Exception as e:print(f"[MediaApply] Exception during animation generation: {str(e)}")blocks_anim = ""# If LLM placement failed, use fallback placementif not blocks_anim:# Create simple replacement block for animation videoblocks_anim = f"""{SEARCH_START}</head>{DIVIDER}</head><div class="animation-container" style="margin: 20px 0; text-align: center;">{animation_html_tag}</div>{REPLACE_END}"""if blocks_anim:print("[MediaApply] Applying animation replacement blocks")result = apply_search_replace_changes(result, blocks_anim)if is_multipage and entry_html_path:multipage_files[entry_html_path] = resultreturn format_multipage_output(multipage_files)return result# If image-to-video is enabled, replace the first image with a generated video and return.if enable_image_to_video and input_image_data is not None and (result.strip().startswith('<!DOCTYPE html>') or result.strip().startswith('<html')):i2v_prompt = (image_to_video_prompt or user_prompt or "").strip()1147 unmodified linesstop_generation = Falsedef generation_code(query: Optional[str], vlm_image: Optional[gr.Image], gen_image: Optional[gr.Image], file: Optional[str], website_url: Optional[str], _setting: Dict[str, str], _history: Optional[History], _current_model: Dict, enable_search: bool = False, language: str = "html", provider: str = "auto", enable_image_generation: bool = False, enable_image_to_image: bool = False, image_to_image_prompt: Optional[str] = None, text_to_image_prompt: Optional[str] = None, enable_image_to_video: bool = False, image_to_video_prompt: Optional[str] = None, enable_text_to_video: bool = False, text_to_video_prompt: Optional[str] = None, enable_video_to_video: bool = False, video_to_video_prompt: Optional[str] = None, input_video_data = None, enable_text_to_music: bool = False, text_to_music_prompt: Optional[str] = None, enable_image_video_to_animation: bool = False, animation_mode: str = "wan2.2-animate-move", animation_quality: str = "wan-pro", animation_video_data = None):if query is None:query = ''if _history is None:270 unmodified linesinput_video_data=input_video_data,enable_text_to_music=enable_text_to_music,text_to_music_prompt=text_to_music_prompt,enable_image_video_to_animation=enable_image_video_to_animation,animation_mode=animation_mode,animation_quality=animation_quality,animation_video_data=animation_video_data,token=None,)_history.append([query, final_content])68 unmodified linesinput_video_data=input_video_data,enable_text_to_music=enable_text_to_music,text_to_music_prompt=text_to_music_prompt,enable_image_video_to_animation=enable_image_video_to_animation,animation_mode=animation_mode,animation_quality=animation_quality,animation_video_data=animation_video_data,token=None,)26 unmodified linesinput_video_data=input_video_data,enable_text_to_music=enable_text_to_music,text_to_music_prompt=text_to_music_prompt,enable_image_video_to_animation=enable_image_video_to_animation,animation_mode=animation_mode,animation_quality=animation_quality,animation_video_data=animation_video_data,token=None,)else:435 unmodified linesinput_video_data=input_video_data,enable_text_to_music=enable_text_to_music,text_to_music_prompt=text_to_music_prompt,enable_image_video_to_animation=enable_image_video_to_animation,animation_mode=animation_mode,animation_quality=animation_quality,animation_video_data=animation_video_data,token=None,)29 unmodified linesinput_video_data=input_video_data,enable_text_to_music=enable_text_to_music,text_to_music_prompt=text_to_music_prompt,enable_image_video_to_animation=enable_image_video_to_animation,animation_mode=animation_mode,animation_quality=animation_quality,animation_video_data=animation_video_data,token=None,)_history.append([query, final_content])1293 unmodified linesvisible=False)# Image+Video to Animationimage_video_to_animation_toggle = gr.Checkbox(label="🎭 Character Animation (uses input image + video)",value=False,visible=True,info="Animate characters using Wan2.2-Animate with reference image and template video")animation_mode_dropdown = gr.Dropdown(label="Animation Mode",choices=[("Move Mode (animate character with video motion)", "wan2.2-animate-move"),("Mix Mode (replace character in video)", "wan2.2-animate-mix")],value="wan2.2-animate-move",visible=False,info="Move: animate image character with video motion. Mix: replace video character with image character")animation_quality_dropdown = gr.Dropdown(label="Animation Quality",choices=[("Professional (25fps, 720p)", "wan-pro"),("Standard (15fps, 720p)", "wan-std")],value="wan-pro",visible=False,info="Higher quality takes more time to generate")animation_video_input = gr.Video(label="Template video for animation (upload a video to use as motion template or character replacement source)",visible=False)# LLM-guided media placement is now always on (no toggle in UI)def on_image_to_image_toggle(toggled, beta_enabled):39 unmodified linesinputs=[text_to_music_toggle, beta_toggle],outputs=[text_to_music_prompt])def on_image_video_to_animation_toggle(toggled, beta_enabled):vis = bool(toggled) and not bool(beta_enabled)return (gr.update(visible=vis), # generation_image_inputgr.update(visible=vis), # animation_mode_dropdowngr.update(visible=vis), # animation_quality_dropdowngr.update(visible=vis), # animation_video_input)image_video_to_animation_toggle.change(on_image_video_to_animation_toggle,inputs=[image_video_to_animation_toggle, beta_toggle],outputs=[generation_image_input, animation_mode_dropdown, animation_quality_dropdown, animation_video_input])model_dropdown = gr.Dropdown(choices=[model['name'] for model in AVAILABLE_MODELS],value=DEFAULT_MODEL_NAME,546 unmodified linesshow_progress="hidden",).then(generation_code,inputs=[input, image_input, generation_image_input, file_input, website_url_input, setting, history, current_model, search_toggle, language_dropdown, provider_state, image_generation_toggle, image_to_image_toggle, image_to_image_prompt, text_to_image_prompt, image_to_video_toggle, image_to_video_prompt, text_to_video_toggle, text_to_video_prompt, video_to_video_toggle, video_to_video_prompt, video_input, text_to_music_toggle, text_to_music_prompt, image_video_to_animation_toggle, animation_mode_dropdown, animation_quality_dropdown, animation_video_input],outputs=[code_output, history, sandbox, history_output]).then(end_generation_ui,90 unmodified linesupd_current_model = gr.skip()upd_t2m_toggle = gr.skip()upd_t2m_prompt = gr.skip()upd_iv2a_toggle = gr.skip()upd_anim_mode = gr.skip()upd_anim_quality = gr.skip()upd_anim_video = gr.skip()# Split by comma to separate main prompt and directivessegments = [seg.strip() for seg in (text or "").split(",") if seg.strip()]73 unmodified linesif p:upd_t2m_prompt = gr.update(value=p)# Image+Video-to-Animationif ("animate" in seg_norm) or ("character animation" in seg_norm) or ("wan animate" in seg_norm):upd_iv2a_toggle = gr.update(value=True)# Check for mode specificationif "move mode" in seg_norm:upd_anim_mode = gr.update(value="wan2.2-animate-move")elif "mix mode" in seg_norm:upd_anim_mode = gr.update(value="wan2.2-animate-mix")# Check for quality specificationif "standard quality" in seg_norm or "std quality" in seg_norm:upd_anim_quality = gr.update(value="wan-std")elif "professional quality" in seg_norm or "pro quality" in seg_norm:upd_anim_quality = gr.update(value="wan-pro")# URL (website redesign)url = _extract_url(seg)if url:67 unmodified linesupd_current_model,upd_t2m_toggle,upd_t2m_prompt,upd_iv2a_toggle,upd_anim_mode,upd_anim_quality,upd_anim_video,)# Wire chat submit -> apply settings -> run generation24 unmodified linescurrent_model,text_to_music_toggle,text_to_music_prompt,image_video_to_animation_toggle,animation_mode_dropdown,animation_quality_dropdown,animation_video_input,],queue=False,).then(3 unmodified linesshow_progress="hidden",).then(generation_code,inputs=[input, image_input, generation_image_input, file_input, website_url_input, setting, history, current_model, search_toggle, language_dropdown, provider_state, image_generation_toggle, image_to_image_toggle, image_to_image_prompt, text_to_image_prompt, image_to_video_toggle, image_to_video_prompt, text_to_video_toggle, text_to_video_prompt, video_to_video_toggle, video_to_video_prompt, video_input, text_to_music_toggle, text_to_music_prompt, image_video_to_animation_toggle, animation_mode_dropdown, animation_quality_dropdown, animation_video_input],outputs=[code_output, history, sandbox, history_output]).then(end_generation_ui,25 unmodified lines)# Toggle between classic controls and beta chat UIdef toggle_beta(checked: bool, t2i: bool, i2i: bool, i2v: bool, t2v: bool, v2v: bool, t2m: bool, iv2a: bool):# Prompts only visible in classic mode and when their toggles are ont2i_vis = (not checked) and bool(t2i)i2i_vis = (not checked) and bool(i2i)1 unmodified linet2v_vis = (not checked) and bool(t2v)v2v_vis = (not checked) and bool(v2v)t2m_vis = (not checked) and bool(t2m)iv2a_vis = (not checked) and bool(iv2a)return (# Chat UI group22 unmodified linesgr.update(visible=v2v_vis), # video_inputgr.update(visible=not checked), # text_to_music_togglegr.update(visible=t2m_vis), # text_to_music_promptgr.update(visible=not checked), # image_video_to_animation_togglegr.update(visible=iv2a_vis), # animation_mode_dropdowngr.update(visible=iv2a_vis), # animation_quality_dropdowngr.update(visible=iv2a_vis), # animation_video_inputgr.update(visible=not checked), # model_dropdowngr.update(visible=not checked), # quick_start_mdgr.update(visible=not checked), # quick_examples_col1 unmodified linebeta_toggle.change(toggle_beta,inputs=[beta_toggle, image_generation_toggle, image_to_image_toggle, image_to_video_toggle, text_to_video_toggle, video_to_video_toggle, text_to_music_toggle, image_video_to_animation_toggle],outputs=[sidebar_chatbot,sidebar_msg,19 unmodified linesvideo_input,text_to_music_toggle,text_to_music_prompt,image_video_to_animation_toggle,animation_mode_dropdown,animation_quality_dropdown,animation_video_input,model_dropdown,quick_start_md,quick_examples_col,
9 unmodified lines101112139 unmodified linesbeautifulsoup4html2textopenaimistralai9 unmodified lines10111213149 unmodified linesbeautifulsoup4html2textopenaimistralaidashscope
app.py+382-7
requirements.txt+2-1