NihalGazi commited on
Commit
f584bfb
1 Parent(s): ee0797c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -42
app.py CHANGED
@@ -4,51 +4,53 @@ from gradio_client import Client, handle_file
4
  def generate_video(input_image, prompt, negative_prompt, diffusion_step, height, width, scfg_scale, use_dctinit, dct_coefficients, noise_level, motion_bucket_id, seed):
5
  client = Client("maxin-cn/Cinemo")
6
 
7
- try:
8
- result = client.predict(
9
- input_image=handle_file(input_image),
10
- prompt=prompt,
11
- negative_prompt=negative_prompt,
12
- diffusion_step=diffusion_step,
13
- height=height,
14
- width=width,
15
- scfg_scale=scfg_scale,
16
- use_dctinit=use_dctinit,
17
- dct_coefficients=dct_coefficients,
18
- noise_level=noise_level,
19
- motion_bucket_id=motion_bucket_id,
20
- seed=seed,
21
- api_name="/gen_video"
22
- )
23
-
24
- print("API Response:", result)
25
- return result
26
- except Exception as e:
27
- return f"Error: {str(e)}"
 
 
28
 
29
- # Define the Gradio interface
30
  with gr.Blocks() as demo:
31
  with gr.Row():
32
  input_image = gr.Image(label="Input Image", type="filepath")
33
- with gr.Column():
34
- prompt = gr.Textbox(label="Prompt", placeholder="Enter prompt here...")
35
- negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="Enter negative prompt here...")
36
-
37
- diffusion_step = gr.Slider(minimum=1, maximum=100, value=50, label="Diffusion Steps")
38
- height = gr.Slider(minimum=128, maximum=1024, value=320, label="Height")
39
- width = gr.Slider(minimum=128, maximum=1024, value=512, label="Width")
40
- scfg_scale = gr.Slider(minimum=1.0, maximum=20.0, value=7.5, label="CFG Scale")
41
- use_dctinit = gr.Checkbox(value=True, label="Enable DCTInit")
42
- dct_coefficients = gr.Slider(minimum=0.0, maximum=1.0, value=0.23, label="DCT Coefficients")
43
- noise_level = gr.Slider(minimum=0, maximum=1000, value=985, label="Noise Level")
44
- motion_bucket_id = gr.Slider(minimum=1, maximum=100, value=10, label="Motion Intensity")
45
- seed = gr.Slider(minimum=1, maximum=10000, value=100, label="Seed")
46
-
47
- generate_btn = gr.Button("Generate Video")
48
-
49
- output_video = gr.Video(label="Generated Video")
50
 
51
- generate_btn.click(generate_video, inputs=[input_image, prompt, negative_prompt, diffusion_step, height, width, scfg_scale, use_dctinit, dct_coefficients, noise_level, motion_bucket_id, seed], outputs=output_video)
 
 
 
 
52
 
53
- # Launch the app with verbose error reporting
54
- demo.launch(show_error=True)
 
4
  def generate_video(input_image, prompt, negative_prompt, diffusion_step, height, width, scfg_scale, use_dctinit, dct_coefficients, noise_level, motion_bucket_id, seed):
5
  client = Client("maxin-cn/Cinemo")
6
 
7
+ result = client.predict(
8
+ input_image=handle_file(input_image),
9
+ prompt=prompt,
10
+ negative_prompt=negative_prompt,
11
+ diffusion_step=diffusion_step,
12
+ height=height,
13
+ width=width,
14
+ scfg_scale=scfg_scale,
15
+ use_dctinit=use_dctinit,
16
+ dct_coefficients=dct_coefficients,
17
+ noise_level=noise_level,
18
+ motion_bucket_id=motion_bucket_id,
19
+ seed=seed,
20
+ api_name="/gen_video"
21
+ )
22
+ print("API response" , result)
23
+
24
+ video_path = result.get('video') # Extract the video file path from the API response
25
+
26
+ if video_path is None:
27
+ return "The API did not return a valid video. Please try again."
28
+
29
+ return video_path # Return the path to the video file
30
 
31
+ # Gradio Interface
32
  with gr.Blocks() as demo:
33
  with gr.Row():
34
  input_image = gr.Image(label="Input Image", type="filepath")
35
+ with gr.Row():
36
+ prompt = gr.Textbox(label="Prompt")
37
+ negative_prompt = gr.Textbox(label="Negative Prompt")
38
+ with gr.Row():
39
+ diffusion_step = gr.Slider(label="Sampling steps", minimum=1, maximum=100, value=50)
40
+ height = gr.Slider(label="Height", minimum=64, maximum=1024, value=320)
41
+ width = gr.Slider(label="Width", minimum=64, maximum=1024, value=512)
42
+ scfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7.5)
43
+ with gr.Row():
44
+ use_dctinit = gr.Checkbox(label="Enable DCTInit", value=True)
45
+ dct_coefficients = gr.Slider(label="DCT Coefficients", minimum=0.0, maximum=1.0, value=0.23)
46
+ noise_level = gr.Slider(label="Noise Level", minimum=0, maximum=1000, value=985)
47
+ motion_bucket_id = gr.Slider(label="Motion Intensity", minimum=0, maximum=20, value=10)
48
+ seed = gr.Number(label="Seed", value=100)
 
 
 
49
 
50
+ video_output = gr.Video(label="Generated Video")
51
+
52
+ generate_button = gr.Button("Generate Video")
53
+
54
+ generate_button.click(generate_video, inputs=[input_image, prompt, negative_prompt, diffusion_step, height, width, scfg_scale, use_dctinit, dct_coefficients, noise_level, motion_bucket_id, seed], outputs=video_output)
55
 
56
+ demo.launch()