Update app.py
Browse files
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 |
-
|
| 12 |
input_image=handle_file(image_path),
|
| 13 |
prompt=prompt,
|
| 14 |
-
api_name="/predict"
|
| 15 |
)
|
| 16 |
|
| 17 |
-
# نتیجه
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
with gr.Column():
|
| 30 |
-
|
| 31 |
|
| 32 |
-
|
| 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()
|