File size: 1,433 Bytes
e0f7bb7
 
 
 
51fac29
 
 
e0f7bb7
51fac29
21c0365
e0f7bb7
51fac29
 
 
e0f7bb7
 
51fac29
e0f7bb7
 
51fac29
 
 
 
e0f7bb7
 
51fac29
21c0365
e0f7bb7
51fac29
21c0365
e0f7bb7
 
51fac29
 
 
e0f7bb7
51fac29
e0f7bb7
51fac29
e0f7bb7
21c0365
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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()