Update app.py
Browse files33 unmodified lines3435363738394059 unmodified lines10010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514638 unmodified lines185186187188189190191192193194405 unmodified lines60060160260360460560660760860961061161261361461561661761861962062162262362462533 unmodified linesMIN_DURATION = round(MIN_FRAMES_MODEL/FIXED_FPS, 1)MAX_DURATION = round(MAX_FRAMES_MODEL/FIXED_FPS, 1)# --- Translation Functions ---@spaces.GPUdef translate_albanian_to_english(text):"""Translate from Albanian to English using the sepioo-facebook-translation API."""59 unmodified linesaoti.aoti_blocks_load(pipe.transformer, 'zerogpu-aoti/Wan2', variant='fp8da')aoti.aoti_blocks_load(pipe.transformer_2, 'zerogpu-aoti/Wan2', variant='fp8da')default_prompt_i2v = "make this image come alive, cinematic motion, smooth animation"default_negative_prompt = "色调艳丽, 过曝, 静态, 细节模糊不清, 字幕, 风格, 作品, 画作, 画面, 静止, 整体发灰, 最差质量, 低质量, JPEG压缩残留, 丑陋的, 残缺的, 多余的手指, 画得不好的手部, 画得不好的脸部, 畸形的, 毁容的, 形态畸形的肢体, 手指融合, 静止不动的画面, 杂乱的背景, 三条腿, 背景人很多, 倒着走"def resize_image(image: Image.Image) -> Image.Image:width, height = image.sizeif width == height:return image.resize((SQUARE_DIM, SQUARE_DIM), Image.LANCZOS)aspect_ratio = width / heightMAX_ASPECT_RATIO = MAX_DIM / MIN_DIMMIN_ASPECT_RATIO = MIN_DIM / MAX_DIMimage_to_resize = imageif aspect_ratio > MAX_ASPECT_RATIO:target_w, target_h = MAX_DIM, MIN_DIMcrop_width = int(round(height * MAX_ASPECT_RATIO))left = (width - crop_width) // 2image_to_resize = image.crop((left, 0, left + crop_width, height))elif aspect_ratio < MIN_ASPECT_RATIO:target_w, target_h = MIN_DIM, MAX_DIMcrop_height = int(round(width / MIN_ASPECT_RATIO))top = (height - crop_height) // 2image_to_resize = image.crop((0, top, width, top + crop_height))else:if width > height:target_w = MAX_DIMtarget_h = int(round(target_w / aspect_ratio))else:target_h = MAX_DIMtarget_w = int(round(target_h * aspect_ratio))final_w = round(target_w / MULTIPLE_OF) * MULTIPLE_OFfinal_h = round(target_h / MULTIPLE_OF) * MULTIPLE_OFfinal_w = max(MIN_DIM, min(MAX_DIM, final_w))final_h = max(MIN_DIM, min(MAX_DIM, final_h))return image_to_resize.resize((final_w, final_h), Image.LANCZOS)def get_num_frames(duration_seconds: float):return 1 + int(np.clip(int(round(duration_seconds * FIXED_FPS)),MIN_FRAMES_MODEL,MAX_FRAMES_MODEL,))def get_duration(input_image, prompt, steps, negative_prompt, duration_seconds, guidance_scale, guidance_scale_2, seed, randomize_seed, progress):BASE_FRAMES_HEIGHT_WIDTH = 81 * 832 * 624BASE_STEP_DURATION = 1538 unmodified linesexport_to_video(output_frames_list, video_path, fps=FIXED_FPS)return video_path, current_seeddef create_demo():with gr.Blocks(css="", title="Fast Image to Video") as demo:gr.HTML("""<style>@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;600;700&display=swap');@keyframes glow {0% { box-shadow: 0 0 14px rgba(0, 255, 128, 0.5); }405 unmodified linesif isSpanish:# ✅ 100% SPANISH - TITLE + DESCRIPTION + EVERYTHING!gr.Markdown("# Vídeo de Imagen Rápido")gr.Markdown("Genera videos desde una imagen de entrada y un prompt usando **Wan 2.2** con **Lightning LoRA**.", elem_id="subtitle")prompt_value = "haz que esta imagen cobre vida, movimiento cinematográfico, animación suave"input_image_label = "Imagen de Entrada"prompt_label = "Prompt"prompt_placeholder = "Describe la animación o movimiento deseado"generate_button_text = "Generar Vídeo"output_video_label = "Vídeo Generado"demo.title = "Vídeo de Imagen Rápido"else:# ✅ 100% ENGLISHgr.Markdown("# Fast Image to Video")gr.Markdown("Generate videos from an input image and prompt using **Wan 2.2** with **Lightning LoRA**.", elem_id="subtitle")prompt_value = default_prompt_i2vinput_image_label = "Input Image"prompt_label = "Prompt"prompt_placeholder = "Describe the desired animation or motion"generate_button_text = "Generate Video"output_video_label = "Generated Video"demo.title = "Fast Image to Video"with gr.Column(elem_id="input_column"):input_image = gr.Image(33 unmodified lines343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888959 unmodified lines14915015115215315438 unmodified lines193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233405 unmodified lines63964064164264364464564664764864965065165265365465565665765865966066166266366433 unmodified linesMIN_DURATION = round(MIN_FRAMES_MODEL/FIXED_FPS, 1)MAX_DURATION = round(MAX_FRAMES_MODEL/FIXED_FPS, 1)default_prompt_i2v = "make this image come alive, cinematic motion, smooth animation"default_negative_prompt = "色调艳丽, 过曝, 静态, 细节模糊不清, 字幕, 风格, 作品, 画作, 画面, 静止, 整体发灰, 最差质量, 低质量, JPEG压缩残留, 丑陋的, 残缺的, 多余的手指, 画得不好的手部, 画得不好的脸部, 畸形的, 毁容的, 形态畸形的肢体, 手指融合, 静止不动的画面, 杂乱的背景, 三条腿, 背景人很多, 倒着走"def resize_image(image: Image.Image) -> Image.Image:width, height = image.sizeif width == height:return image.resize((SQUARE_DIM, SQUARE_DIM), Image.LANCZOS)aspect_ratio = width / heightMAX_ASPECT_RATIO = MAX_DIM / MIN_DIMMIN_ASPECT_RATIO = MIN_DIM / MAX_DIMimage_to_resize = imageif aspect_ratio > MAX_ASPECT_RATIO:target_w, target_h = MAX_DIM, MIN_DIMcrop_width = int(round(height * MAX_ASPECT_RATIO))left = (width - crop_width) // 2image_to_resize = image.crop((left, 0, left + crop_width, height))elif aspect_ratio < MIN_ASPECT_RATIO:target_w, target_h = MIN_DIM, MAX_DIMcrop_height = int(round(width / MIN_ASPECT_RATIO))top = (height - crop_height) // 2image_to_resize = image.crop((0, top, width, top + crop_height))else:if width > height:target_w = MAX_DIMtarget_h = int(round(target_w / aspect_ratio))else:target_h = MAX_DIMtarget_w = int(round(target_h * aspect_ratio))final_w = round(target_w / MULTIPLE_OF) * MULTIPLE_OFfinal_h = round(target_h / MULTIPLE_OF) * MULTIPLE_OFfinal_w = max(MIN_DIM, min(MAX_DIM, final_w))final_h = max(MIN_DIM, min(MAX_DIM, final_h))return image_to_resize.resize((final_w, final_h), Image.LANCZOS)def get_num_frames(duration_seconds: float):return 1 + int(np.clip(int(round(duration_seconds * FIXED_FPS)),MIN_FRAMES_MODEL,MAX_FRAMES_MODEL,))def get_duration(input_image, prompt, steps, negative_prompt, duration_seconds, guidance_scale, guidance_scale_2, seed, randomize_seed, progress):BASE_FRAMES_HEIGHT_WIDTH = 81 * 832 * 624BASE_STEP_DURATION = 15width, height = resize_image(input_image).sizeframes = get_num_frames(duration_seconds)factor = frames * width * height / BASE_FRAMES_HEIGHT_WIDTHstep_duration = BASE_STEP_DURATION * factor ** 1.5return 10 + int(steps) * step_duration@spaces.GPUdef translate_albanian_to_english(text):"""Translate from Albanian to English using the sepioo-facebook-translation API."""59 unmodified linesaoti.aoti_blocks_load(pipe.transformer, 'zerogpu-aoti/Wan2', variant='fp8da')aoti.aoti_blocks_load(pipe.transformer_2, 'zerogpu-aoti/Wan2', variant='fp8da')def get_duration(input_image, prompt, steps, negative_prompt, duration_seconds, guidance_scale, guidance_scale_2, seed, randomize_seed, progress):BASE_FRAMES_HEIGHT_WIDTH = 81 * 832 * 624BASE_STEP_DURATION = 1538 unmodified linesexport_to_video(output_frames_list, video_path, fps=FIXED_FPS)return video_path, current_seed# ----------------------------------------------------------------------# UI language dictionaries (only UI text – no functional changes)# ----------------------------------------------------------------------EN_UI = {"title": "Fast Image to Video","subtitle": "Generate videos from an input image and prompt using **Wan 2.2** with **Lightning LoRA**.","input_image_label": "Input Image","prompt_label": "Prompt","prompt_placeholder": "Describe the desired animation or motion","generate_button": "Generate Video","output_video_label": "Generated Video",}ES_UI = {"title": "Vídeo de Imagen Rápido","subtitle": "Genera videos a partir de una imagen y un prompt usando **Wan 2.2** con **Lightning LoRA**.","input_image_label": "Imagen de Entrada","prompt_label": "Prompt","prompt_placeholder": "Describe la animación o movimiento deseado","generate_button": "Generar Vídeo","output_video_label": "Vídeo Generado",}def create_demo():# Detect language from URL path (same logic you already used)path = gr.Request().url.path if hasattr(gr.Request, "url") else "/"is_spanish = "spanish" in path.lower()UI = ES_UI if is_spanish else EN_UIwith gr.Blocks(css="", title=UI["title"]) as demo:gr.HTML("""<style>/* -----------------------------------------------------------------YOUR ORIGINAL CSS – ALL OF IT IS LEFT UNCHANGED----------------------------------------------------------------- */@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;600;700&display=swap');@keyframes glow {0% { box-shadow: 0 0 14px rgba(0, 255, 128, 0.5); }405 unmodified linesif isSpanish:# ✅ 100% SPANISH - TITLE + DESCRIPTION + EVERYTHING!gr.Markdown(f"# {UI['title']}")gr.Markdown(UI["subtitle"], elem_id="subtitle")prompt_value = "haz que esta imagen cobre vida, movimiento cinematográfico, animación suave"input_image_label = UI["input_image_label"]prompt_label = UI["prompt_label"]prompt_placeholder = UI["prompt_placeholder"]generate_button_text = UI["generate_button"]output_video_label = UI["output_video_label"]demo.title = UI["title"]else:# ✅ 100% ENGLISHgr.Markdown(f"# {UI['title']}")gr.Markdown(UI["subtitle"], elem_id="subtitle")prompt_value = default_prompt_i2vinput_image_label = UI["input_image_label"]prompt_label = UI["prompt_label"]prompt_placeholder = UI["prompt_placeholder"]generate_button_text = UI["generate_button"]output_video_label = UI["output_video_label"]demo.title = UI["title"]with gr.Column(elem_id="input_column"):input_image = gr.Image(
app.py+98-59