evaluator42 commited on
Commit
4336d0b
·
verified ·
1 Parent(s): a2b85a2

Upload 14 files

Browse files
app.py CHANGED
@@ -25,7 +25,7 @@ with gr.Blocks(title="Nova Reel — Text → Video (Single-shot)") as demo:
25
  with gr.Column(scale=1):
26
  s3_uri = gr.Textbox(
27
  label="S3 output base URI",
28
- value="s3://bucketvideogenerationwest",
29
  placeholder="s3://your-bucket[/optional/prefix]",
30
  )
31
  region = gr.Textbox(label="AWS Region", value=DEFAULT_REGION)
@@ -70,4 +70,8 @@ with gr.Blocks(title="Nova Reel — Text → Video (Single-shot)") as demo:
70
  )
71
 
72
  if __name__ == "__main__":
73
- demo.queue().launch(share=True, ssr_mode=False)
 
 
 
 
 
25
  with gr.Column(scale=1):
26
  s3_uri = gr.Textbox(
27
  label="S3 output base URI",
28
+ value="s3://r2-video-test",
29
  placeholder="s3://your-bucket[/optional/prefix]",
30
  )
31
  region = gr.Textbox(label="AWS Region", value=DEFAULT_REGION)
 
70
  )
71
 
72
  if __name__ == "__main__":
73
+ auth_user = os.getenv("USER")
74
+ auth_pass = os.getenv("PASS")
75
+ demo.queue().launch(
76
+ auth=(auth_user, auth_pass), share=True, ssr_mode=False
77
+ )
drivers/nova_reel.py CHANGED
@@ -1,7 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import boto3
2
  from config import MODEL_ID, FIXED_FPS, FIXED_WIDTH, FIXED_HEIGHT, FIXED_DURATION
3
  from utils.images import image_path_to_image_source
4
 
 
5
  def bedrock_and_s3(region_name: str):
6
  return (
7
  boto3.client("bedrock-runtime", region_name=region_name),
 
1
+ """
2
+ Module for interacting with AWS Bedrock and S3 to generate videos from text prompts.
3
+
4
+ Functions:
5
+ bedrock_and_s3(region_name: str) -> tuple:
6
+ Creates and returns AWS Bedrock Runtime and S3 clients for the specified region.
7
+
8
+ build_single_shot_input(prompt: str, seed: int | None, reference_image_path: str | None) -> dict:
9
+ Builds the input payload for a single-shot text-to-video generation request.
10
+ Optionally includes a seed for reproducibility and a reference image.
11
+
12
+ start_async_single_shot(bedrock_client, prompt: str, seed: int | None,
13
+ reference_image_path: str | None, s3_output_uri: str) -> str:
14
+ Initiates an asynchronous text-to-video generation request using Bedrock.
15
+ Returns the invocation ARN for tracking the request.
16
+
17
+ get_async(bedrock_client, invocation_arn: str) -> dict:
18
+ Retrieves the status and result of an asynchronous Bedrock invocation using the provided ARN.
19
+ """
20
  import boto3
21
  from config import MODEL_ID, FIXED_FPS, FIXED_WIDTH, FIXED_HEIGHT, FIXED_DURATION
22
  from utils.images import image_path_to_image_source
23
 
24
+
25
  def bedrock_and_s3(region_name: str):
26
  return (
27
  boto3.client("bedrock-runtime", region_name=region_name),
drivers/polling.py CHANGED
@@ -1,8 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import time
2
  from botocore.exceptions import BotoCoreError, ClientError
3
  from config import POLL_INTERVAL_SECS
4
  from VideoBR.utils.s3_io import download_output_mp4
5
 
 
6
  def poll_and_fetch(bedrock_runtime, s3_client, invocation_arn: str):
7
  last_status = None
8
  while True:
 
1
+ """
2
+ Polls the status of an asynchronous Bedrock job and fetches the output video upon completion.
3
+
4
+ Args:
5
+ bedrock_runtime: The Bedrock runtime client used to poll the job status.
6
+ s3_client: The S3 client used to download the output video.
7
+ invocation_arn (str): The ARN of the asynchronous Bedrock job to poll.
8
+
9
+ Yields:
10
+ tuple:
11
+ - local_mp4 (str or None): Path to the downloaded MP4 file if the job is completed successfully, otherwise None.
12
+ - message (str): Status or error message describing the current state or any issues encountered.
13
+
14
+ Behavior:
15
+ - Continuously polls the job status at intervals defined by POLL_INTERVAL_SECS.
16
+ - Yields status updates when the job status changes.
17
+ - On completion, attempts to download the output MP4 from S3 and yields the local file path.
18
+ - Handles and yields error messages for polling failures, download failures, or job failures.
19
+ """
20
+
21
  import time
22
  from botocore.exceptions import BotoCoreError, ClientError
23
  from config import POLL_INTERVAL_SECS
24
  from VideoBR.utils.s3_io import download_output_mp4
25
 
26
+
27
  def poll_and_fetch(bedrock_runtime, s3_client, invocation_arn: str):
28
  last_status = None
29
  while True:
handlers/video_generation_type.py CHANGED
@@ -1,3 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import time
2
  from datetime import datetime
3
  from botocore.exceptions import BotoCoreError, ClientError
 
1
+
2
+ """
3
+ Module for handling video generation using Bedrock and S3.
4
+
5
+ Functions:
6
+ generate_single_shot(prompt: str, output_s3_uri: str, seed_in: str, region_name: str,
7
+ reference_image_path: str | None, custom_name: str)
8
+ Asynchronously generates a single-shot video based on the provided prompt and optional reference image.
9
+ The video is saved to the specified S3 URI, and the function yields status updates and results.
10
+ Handles job submission, polling for status, renaming the output file, and generating a presigned URL for playback.
11
+
12
+ Args:
13
+ prompt (str): The text prompt for video generation.
14
+ output_s3_uri (str): The S3 URI where the output video will be stored.
15
+ seed_in (str): Seed value for deterministic generation.
16
+ region_name (str): AWS region name for Bedrock and S3 clients.
17
+ reference_image_path (str | None): Optional path to a reference image.
18
+ custom_name (str): Custom name for the output video file.
19
+
20
+ Yields:
21
+ tuple: (vid_path, status_msg, rows) where
22
+ vid_path (str | None): Presigned URL for the generated video (if available).
23
+ status_msg (str): Status or error message.
24
+ rows (list): List of video metadata rows from S3.
25
+
26
+ refresh_listing(output_s3_uri: str, region_name: str)
27
+ Retrieves and returns a list of video metadata rows from the specified S3 URI.
28
+
29
+ Args:
30
+ output_s3_uri (str): The S3 URI to list videos from.
31
+ region_name (str): AWS region name for S3 client.
32
+
33
+ Returns:
34
+ list: List of video metadata rows from S3, or an empty list on error.
35
+ """
36
  import time
37
  from datetime import datetime
38
  from botocore.exceptions import BotoCoreError, ClientError
utils/.DS_Store ADDED
Binary file (6.15 kB). View file
 
utils/images.py CHANGED
@@ -1,3 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import base64
2
  from pathlib import Path
3
 
 
1
+ """
2
+ Converts an image file path to a dictionary containing the image format and a base64-encoded source.
3
+
4
+ Args:
5
+ image_path (str | None): The file path to the image. Can be None.
6
+
7
+ Returns:
8
+ dict | None: A dictionary with keys 'format' (either 'jpeg' or 'png') and 'source' (containing base64-encoded image bytes),
9
+ or None if image_path is None.
10
+
11
+ Raises:
12
+ ValueError: If the image file is not a PNG or JPEG.
13
+ """
14
  import base64
15
  from pathlib import Path
16