besarismaili commited on
Commit
0e349b1
1 Parent(s): 9589487
Files changed (1) hide show
  1. app.py +7 -24
app.py CHANGED
@@ -2,7 +2,9 @@ import os
2
  import cv2
3
  import numpy as np
4
  import gradio as gr
 
5
  from stability_sdk.api import Context
 
6
  from stability_sdk.animation import AnimationArgs, Animator
7
 
8
  STABILITY_HOST = "grpc.stability.ai:443"
@@ -103,32 +105,13 @@ def anim(f_promt, s_promt, stability_key, cadence_interp, width ,height ,sampler
103
  api_context=context,
104
  animation_prompts=animation_prompts,
105
  negative_prompt=negative_prompt,
106
- args=args
 
107
  )
 
 
108
 
109
- # Define output folder path
110
- image_path = "/tmp/frames/"
111
- output_dir = os.path.join(image_path, "output")
112
-
113
- if not os.path.exists(output_dir):
114
- os.makedirs(output_dir)
115
-
116
- # Define the codec using VideoWriter_fourcc and create a VideoWriter object
117
- # We specify output file name as output.avi, codec as MJPG, fps as 25.0, and frame size as (width, height)
118
- fourcc = cv2.VideoWriter_fourcc(*'mp4v')
119
- video = cv2.VideoWriter('output.mp4', fourcc, 25.0, (width, height))
120
-
121
- for idx, frame in enumerate(animator.render()):
122
- # Convert the image from BGR to RGB format
123
- frame = cv2.cvtColor(np.array(frame), cv2.COLOR_RGB2BGR)
124
- # Write the RGB image to file
125
- video.write(frame)
126
- print(f"Added frame {idx} to video.")
127
-
128
- # Release the VideoWriter
129
- video.release()
130
- print("Video created successfully!")
131
-
132
 
133
 
134
  with gr.Blocks() as demo:
 
2
  import cv2
3
  import numpy as np
4
  import gradio as gr
5
+ from tqdm import tqdm
6
  from stability_sdk.api import Context
7
+ from stability_sdk.utils import create_video_from_frames
8
  from stability_sdk.animation import AnimationArgs, Animator
9
 
10
  STABILITY_HOST = "grpc.stability.ai:443"
 
105
  api_context=context,
106
  animation_prompts=animation_prompts,
107
  negative_prompt=negative_prompt,
108
+ args=args,
109
+ out_dir="video_01"
110
  )
111
+ for _ in tqdm(animator.render(), total=args.max_frames):
112
+ pass
113
 
114
+ return create_video_from_frames(animator.out_dir, "video.mp4", fps=24)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
 
117
  with gr.Blocks() as demo: