jbilcke-hf HF staff commited on
Commit
f58ac54
·
1 Parent(s): 3744cdd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -57,8 +57,18 @@ def sample(
57
  frames = pipe(image, decode_chunk_size=decoding_t, generator=generator, motion_bucket_id=motion_bucket_id, noise_aug_strength=0.1, num_frames=25).frames[0]
58
  export_to_video(frames, video_path, fps=fps_id)
59
  torch.manual_seed(seed)
 
 
 
 
 
 
 
60
 
61
- return video_path, seed
 
 
 
62
 
63
  def resize_image(image, output_size=(1024, 576)):
64
  # Calculate aspect ratios
@@ -104,13 +114,14 @@ with gr.Blocks() as demo:
104
  with gr.Column():
105
  image = gr.Image(label="Upload your image", type="pil")
106
  generate_btn = gr.Button("Generate")
107
- video = gr.Video()
 
108
  with gr.Accordion("Advanced options", open=False):
109
  seed = gr.Slider(label="Seed", value=42, randomize=False, minimum=0, maximum=max_64_bit_int, step=1)
110
  motion_bucket_id = gr.Slider(label="Motion bucket id", info="Controls how much motion to add/remove from the image", value=127, minimum=1, maximum=255)
111
  fps_id = gr.Slider(label="Frames per second", info="The length of your video in seconds will be 25/fps", value=6, minimum=5, maximum=30)
112
 
113
- generate_btn.click(fn=sample, inputs=[image, seed, motion_bucket_id, fps_id, secret_token], outputs=video, api_name="video")
114
 
115
  if __name__ == "__main__":
116
  demo.queue(max_size=20).launch()
 
57
  frames = pipe(image, decode_chunk_size=decoding_t, generator=generator, motion_bucket_id=motion_bucket_id, noise_aug_strength=0.1, num_frames=25).frames[0]
58
  export_to_video(frames, video_path, fps=fps_id)
59
  torch.manual_seed(seed)
60
+
61
+ # Read the content of the video file and encode it to base64
62
+ with open(video_path, "rb") as video_file:
63
+ video_base64 = base64.b64encode(video_file.read()).decode('utf-8')
64
+
65
+ # Prepend the appropriate data URI header with MIME type
66
+ video_data_uri = 'data:video/mp4;base64,' + video_base64
67
 
68
+ # Clean up the video file to avoid filling up storage
69
+ # os.remove(video_path)
70
+
71
+ return video_data_uri
72
 
73
  def resize_image(image, output_size=(1024, 576)):
74
  # Calculate aspect ratios
 
114
  with gr.Column():
115
  image = gr.Image(label="Upload your image", type="pil")
116
  generate_btn = gr.Button("Generate")
117
+ base64_out = gr.Textbox(label="Base64 Video")
118
+
119
  with gr.Accordion("Advanced options", open=False):
120
  seed = gr.Slider(label="Seed", value=42, randomize=False, minimum=0, maximum=max_64_bit_int, step=1)
121
  motion_bucket_id = gr.Slider(label="Motion bucket id", info="Controls how much motion to add/remove from the image", value=127, minimum=1, maximum=255)
122
  fps_id = gr.Slider(label="Frames per second", info="The length of your video in seconds will be 25/fps", value=6, minimum=5, maximum=30)
123
 
124
+ generate_btn.click(fn=sample, inputs=[image, seed, motion_bucket_id, fps_id, secret_token], outputs=[base64_out], api_name="video")
125
 
126
  if __name__ == "__main__":
127
  demo.queue(max_size=20).launch()