Opera8 commited on
Commit
e0f7bb7
·
verified ·
1 Parent(s): 9204ecc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio_client import Client, handle_file
3
+ import os
4
+
5
+ # آدرس اسپیس مقصد که در عکس فرستادی
6
+ SOURCE_SPACE = "ibuildproducts/wan22-i2v-v4-demo"
7
+
8
+ def generate_video(image_path, prompt):
9
+ try:
10
+ # اتصال به API اسپیس مقصد
11
+ client = Client(SOURCE_SPACE)
12
+
13
+ # ارسال درخواست به متد predict
14
+ # نکته: پارامترها باید دقیقا مطابق با API مقصد باشد
15
+ result = client.predict(
16
+ input_image=handle_file(image_path),
17
+ prompt=prompt,
18
+ api_name="/predict"
19
+ )
20
+
21
+ # result معمولاً مسیر فایل ویدیویی ذخیره شده است
22
+ return result
23
+ except Exception as e:
24
+ return f"Error: {str(e)}"
25
+
26
+ # طراحی رابط کاربری ساده
27
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
28
+ gr.Markdown(f"### AI Video Generator (Bridge to {SOURCE_SPACE})")
29
+
30
+ with gr.Row():
31
+ with gr.Column():
32
+ input_img = gr.Image(type="filepath", label="عکس منظره")
33
+ input_prompt = gr.Textbox(value="A beautiful cinematic landscape, 1 second animation", label="پرامپت")
34
+ btn = gr.Button("ساخت ویدیو (۱ ثانیه)", variant="primary")
35
+
36
+ with gr.Column():
37
+ output_video = gr.Video(label="ویدیو خروجی")
38
+
39
+ btn.click(fn=generate_video, inputs=[input_img, input_prompt], outputs=output_video)
40
+
41
+ if __name__ == "__main__":
42
+ demo.launch(server_name="0.0.0.0", server_port=7860)