Opera8 commited on
Commit
51fac29
·
verified ·
1 Parent(s): 21c0365

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -12
app.py CHANGED
@@ -2,33 +2,40 @@ import gradio as gr
2
  from gradio_client import Client, handle_file
3
 
4
  def generate_video(image_path, prompt):
 
 
 
5
  try:
6
- # اتصال به اسپیس مقصد
7
  client = Client("ibuildproducts/wan22-i2v-v4-demo")
8
 
9
- # در آپدیت جدید، بهتر است از اسم پیش‌فرض استفاده نکنی
10
- # و اجازه دهی خود کلاینت جابجایی فایل را مدیریت کند
11
- result = client.predict(
12
  input_image=handle_file(image_path),
13
  prompt=prompt,
14
- api_name="/predict"
15
  )
16
 
17
- # نتیجه در ZeroGPU معمولاً یک مسیر فایل محلی است
 
 
 
18
  return result
19
  except Exception as e:
 
20
  return None
21
 
 
22
  with gr.Blocks() as demo:
23
- gr.Markdown("### Wan 2.1 Video Generator")
24
  with gr.Row():
25
  with gr.Column():
26
- img = gr.Image(type="filepath")
27
- txt = gr.Textbox(value="moving cinematic eyes, 1 second", label="Prompt")
28
- btn = gr.Button("ساخت ویدیو")
29
  with gr.Column():
30
- out = gr.Video()
31
 
32
- btn.click(generate_video, [img, txt], out)
33
 
34
  demo.launch()
 
2
  from gradio_client import Client, handle_file
3
 
4
  def generate_video(image_path, prompt):
5
+ if image_path is None:
6
+ return None
7
+
8
  try:
9
+ # ۱. اتصال به کلاینت (این کار خودش Config و API Schema رو می‌خونه)
10
  client = Client("ibuildproducts/wan22-i2v-v4-demo")
11
 
12
+ # ۲. ارسال به صف (Join the Queue)
13
+ # این متد خودش فایل رو آپلود می‌کنه و پارامترها رو می‌فرسته
14
+ job = client.submit(
15
  input_image=handle_file(image_path),
16
  prompt=prompt,
17
+ api_name="/predict"
18
  )
19
 
20
+ # ۳. منتظر ماندن برای نتیجه (Stream results رو مدیریت می‌کنه)
21
+ result = job.result()
22
+
23
+ # ۴. بازگرداندن مسیر ویدیو
24
  return result
25
  except Exception as e:
26
+ print(f"Error: {e}")
27
  return None
28
 
29
+ # رابط کاربری Gradio
30
  with gr.Blocks() as demo:
 
31
  with gr.Row():
32
  with gr.Column():
33
+ img_input = gr.Image(type="filepath")
34
+ prompt_input = gr.Textbox(label="Prompt", value="cinematic motion, high quality")
35
+ submit_btn = gr.Button("ساخت ویدیو")
36
  with gr.Column():
37
+ video_output = gr.Video()
38
 
39
+ submit_btn.click(generate_video, [img_input, prompt_input], video_output)
40
 
41
  demo.launch()