fix the missing code for width low and height low """ ) Shared settings with gr.Row():…
- User
fix the missing code for width low and height low
""" )
code - Assistant
fix the missing code for width low and height low
""" )
# Shared settings
with gr.Row():
resolution_dropdown = gr.Dropdown(
choices=["768p", "384p"],
value="384p",
label="Model Resolution"
)
width_low = float(gr.Textbox(label="Model Width", placeholder="Enter a video width.", lines=1))
height_low = float(gr.Textbox(label="Model Height", placeholder="Enter a video height.", lines=1))
with gr.Tab("Text-to-Video"):
with gr.Row():
with gr.Column():
text_prompt = gr.Textbox(label="Prompt (Less than 128 words)", placeholder="Enter a text prompt for the video", lines=2)
temp_slider = gr.Slider(1, 16, value=16, step=1, label="Duration")
guidance_scale_slider = gr.Slider(1.0, 15.0, value=9.0, step=0.1, label="Guidance Scale")
video_guidance_scale_slider = gr.Slider(1.0, 10.0, value=5.0, step=0.1, label="Video Guidance Scale")
txt_generate = gr.Button("Generate Video")
with gr.Column():
txt_output = gr.Video(label="Generated Video")
gr.Examples(
examples=[
["A movie trailer featuring the adventures of the 30 year old space man wearing a red wool knitted motorcycle helmet, blue sky, salt desert, cinematic style, shot on 35mm film, vivid colors", 16, 7.0, 5.0, "384p"],
["Beautiful, snowy Tokyo city is bustling. The camera moves through the bustling city street, following several people enjoying the beautiful snowy weather and shopping at nearby stalls. Gorgeous sakura petals are flying through the wind along with snowflakes", 16, 7.0, 5.0, "384p"],
# ["Extreme close-up of chicken and green pepper kebabs grilling on a barbeque with flames. Shallow focus and light smoke. vivid colours", 31, 9.0, 5.0, "768p"],
],
inputs=[text_prompt, temp_slider, guidance_scale_slider, video_guidance_scale_slider, resolution_dropdown],
outputs=[txt_output],
fn=generate_text_to_video,
cache_examples='lazy',
)
with gr.Tab("Image-to-Video"):
with gr.Row():
with gr.Column():
image_input = gr.Image(type="pil", label="Input Image")
image_prompt = gr.Textbox(label="Prompt (Less than 128 words)", placeholder="Enter a text prompt for the video", lines=2)
image_temp_slider = gr.Slider(2, 16, value=16, step=1, label="Duration")
image_video_guidance_scale_slider = gr.Slider(1.0, 7.0, value=4.0, step=0.1, label="Video Guidance Scale")
img_generate = gr.Button("Generate Video")
with gr.Column():
img_output = gr.Video(label="Generated Video")
gr.Examples(
examples=[
['assets/the_great_wall.jpg', 'FPV flying over the Great Wall', 16, 4.0, "384p"]
],
inputs=[image_input, image_prompt, image_temp_slider, image_video_guidance_scale_slider, resolution_dropdown],
outputs=[img_output],
fn=generate_image_to_video,
cache_examples='lazy',
)
# Update generate functions to include resolution options
txt_generate.click(
generate_text_to_video,
inputs=[text_prompt, temp_slider, guidance_scale_slider, video_guidance_scale_slider, resolution_dropdown],
outputs=txt_output
)
img_generate.click(
generate_image_to_video,
inputs=[image_input, image_prompt, image_temp_slider, image_video_guidance_scale_slider, resolution_dropdown],
outputs=img_output
)
demo.launch(share=False)
To fix the issue with width_low and height_low, you should ensure that they are properly initialized and used as Gradio components. The gr.Textbox is used for inputs that should take textual values and here you're attempting to assign a float directly, which might not be appropriate in this context without processing their values first from user input. Instead, what you'll want to do is capture these as strings initially via the gr.Textbox and then convert them.
Here's how you might modify your code snippet to correctly initialize width_low and height_low using Gradio components and properly parse them as floats:
import gradio as gr
def generate_text_to_video(prompt, duration, guidance_scale, video_guidance_scale, resolution, width, height):
# Process resolution and width, height parameters here
# Placeholder for the video generation logic
return f"Video generated with resolution {resolution}, width {width}, and height {height}"
def generate_image_to_video(image, prompt, duration, video_guidance_scale, resolution, width, height):
# Process resolution and width, height parameters here
# Placeholder for the video generation logic
return f"Video generated with resolution {resolution}, width {width}, and height {height}"
with gr.Row():
resolution_dropdown = gr.Dropdown(
choices=["768p", "384p"],
value="384p",
label="Model Resolution"
)
width_low = gr.Textbox(label="Model Width", placeholder="Enter a video width.", lines=1)
height_low = gr.Textbox(label="Model Height", placeholder="Enter a video height.", lines=1)
with gr.Tab("Text-to-Video"):
with gr.Row():
with gr.Column():
text_prompt = gr.Textbox(label="Prompt (Less than 128 words)", placeholder="Enter a text prompt for the video", lines=2)
temp_slider = gr.Slider(1, 16, value=16, step=1, label="Duration")
guidance_scale_slider = gr.Slider(1.0, 15.0, value=9.0, step=0.1, label="Guidance Scale")
video_guidance_scale_slider = gr.Slider(1.0, 10.0, value=5.0, step=0.1, label="Video Guidance Scale")
txt_generate = gr.Button("Generate Video")
with gr.Column():
txt_output = gr.Video(label="Generated Video")
gr.Examples(
examples=[
["A movie trailer featuring the adventures of the 30 year old space man wearing a red wool knitted motorcycle helmet, blue sky, salt desert, cinematic style, shot on 35mm film, vivid colors", 16, 7.0, 5.0, "384p"],
["Beautiful, snowy Tokyo city is bustling...", 16, 7.0, 5.0, "384p"],
],
inputs=[text_prompt, temp_slider, guidance_scale_slider, video_guidance_scale_slider, resolution_dropdown, width_low, height_low],
outputs=[txt_output],
fn=generate_text_to_video,
cache_examples='lazy',
)
with gr.Tab("Image-to-Video"):
with gr.Row():
with gr.Column():
image_input = gr.Image(type="pil", label="Input Image")
image_prompt = gr.Textbox(label="Prompt (Less than 128 words)", placeholder="Enter a text prompt for the video", lines=2)
image_temp_slider = gr.Slider(2, 16, value=16, step=1, label="Duration")
image_video_guidance_scale_slider = gr.Slider(1.0, 7.0, value=4.0, step=0.1, label="Video Guidance Scale")
img_generate = gr.Button("Generate Video")
with gr.Column():
img_output = gr.Video(label="Generated Video")
gr.Examples(
examples=[
['assets/the_great_wall.jpg', 'FPV flying over the Great Wall', 16, 4.0, "384p"]
],
inputs=[image_input, image_prompt, image_temp_slider, image_video_guidance_scale_slider, resolution_dropdown, width_low, height_low],
outputs=[img_output],
fn=generate_image_to_video,
cache_examples='lazy',
)
txt_generate.click(
generate_text_to_video,
inputs=[text_prompt, temp_slider, guidance_scale_slider, video_guidance_scale_slider, resolution_dropdown, width_low, height_low],
outputs=txt_output
)
img_generate.click(
generate_image_to_video,
inputs=[image_input, image_prompt, image_temp_slider, image_video_guidance_scale_slider, resolution_dropdown, width_low, height_low],
outputs=img_output
)
demo.launch(share=False)
In this code, the width_low and height_low inputs are kept as text boxes so the user can input desired dimensions, and you'll presumably handle the conversion and application of these dimensions in your generate_text_to_video and generate_image_to_video functions.
Not yet included in a published release.