import gradio as gr from gradio_client import Client, handle_file def generate_video(image_path, prompt): if image_path is None: return None try: # ۱. اتصال به کلاینت (این کار خودش Config و API Schema رو می‌خونه) client = Client("ibuildproducts/wan22-i2v-v4-demo") # ۲. ارسال به صف (Join the Queue) # این متد خودش فایل رو آپلود می‌کنه و پارامترها رو می‌فرسته job = client.submit( input_image=handle_file(image_path), prompt=prompt, api_name="/predict" ) # ۳. منتظر ماندن برای نتیجه (Stream results رو مدیریت می‌کنه) result = job.result() # ۴. بازگرداندن مسیر ویدیو return result except Exception as e: print(f"Error: {e}") return None # رابط کاربری Gradio with gr.Blocks() as demo: with gr.Row(): with gr.Column(): img_input = gr.Image(type="filepath") prompt_input = gr.Textbox(label="Prompt", value="cinematic motion, high quality") submit_btn = gr.Button("ساخت ویدیو") with gr.Column(): video_output = gr.Video() submit_btn.click(generate_video, [img_input, prompt_input], video_output) demo.launch()