multimodalart HF Staff commited on
Commit
862521e
·
verified ·
1 Parent(s): eff53ff

feat: Add docstrings and enable MCP

Browse files

Hello! This is an automated PR from a bot.

This PR introduces two improvements:
1. Adds docstrings to the functions in the app file that are directly connected to the Gradio UI, improving code readability.
2. Enables the Model-Compute-Platform by adding `mcp_server=True` to the `.launch()` call.

No other logic has been changed. Please review and merge if it looks good!

Files changed (1) hide show
  1. app.py +31 -1
app.py CHANGED
@@ -40,6 +40,26 @@ def sample(
40
  output_folder: str = "outputs",
41
  progress=gr.Progress(track_tqdm=True)
42
  ):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  if image.mode == "RGBA":
44
  image = image.convert("RGB")
45
 
@@ -58,6 +78,16 @@ def sample(
58
  return video_path, seed
59
 
60
  def resize_image(image, output_size=(1024, 576)):
 
 
 
 
 
 
 
 
 
 
61
  # Calculate aspect ratios
62
  target_aspect = output_size[0] / output_size[1] # Aspect ratio of the desired size
63
  image_aspect = image.width / image.height # Aspect ratio of the original image
@@ -125,4 +155,4 @@ with gr.Blocks() as demo:
125
 
126
  if __name__ == "__main__":
127
  #demo.queue(max_size=20, api_open=False)
128
- demo.launch(share=True, show_api=False)
 
40
  output_folder: str = "outputs",
41
  progress=gr.Progress(track_tqdm=True)
42
  ):
43
+ """
44
+ Generate a video from a single image using Stable Video Diffusion.
45
+
46
+ Args:
47
+ image: Input PIL Image to generate video from
48
+ seed: Random seed for generation reproducibility
49
+ randomize_seed: Whether to randomize the seed
50
+ motion_bucket_id: Controls the amount of motion in the generated video (1-255)
51
+ fps_id: Frames per second for the output video
52
+ version: Model version to use
53
+ cond_aug: Conditioning augmentation strength
54
+ decoding_t: Number of frames decoded at a time (affects VRAM usage)
55
+ device: Device to run the model on
56
+ output_folder: Directory to save the output video
57
+ progress: Gradio progress tracker
58
+
59
+ Returns:
60
+ Tuple of (video_path, seed) where video_path is the path to the generated video file
61
+ and seed is the seed used for generation
62
+ """
63
  if image.mode == "RGBA":
64
  image = image.convert("RGB")
65
 
 
78
  return video_path, seed
79
 
80
  def resize_image(image, output_size=(1024, 576)):
81
+ """
82
+ Resize and crop an image to the specified output size while maintaining aspect ratio.
83
+
84
+ Args:
85
+ image: PIL Image to resize
86
+ output_size: Tuple of (width, height) for the target size
87
+
88
+ Returns:
89
+ PIL Image resized and cropped to the target dimensions
90
+ """
91
  # Calculate aspect ratios
92
  target_aspect = output_size[0] / output_size[1] # Aspect ratio of the desired size
93
  image_aspect = image.width / image.height # Aspect ratio of the original image
 
155
 
156
  if __name__ == "__main__":
157
  #demo.queue(max_size=20, api_open=False)
158
+ demo.launch(share=True, show_api=False, mcp_server=True)