Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 37 additions & 32 deletions demo_gradio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
os.environ['HF_HOME'] = os.path.abspath(os.path.realpath(os.path.join(os.path.dirname(__file__), './hf_download')))

import gradio as gr
from gradio_i18n import Translate
from gradio_i18n import gettext as _
import torch
import traceback
import einops
Expand Down Expand Up @@ -356,49 +358,52 @@ def end_process():

css = make_progress_bar_css()
block = gr.Blocks(css=css).queue()

lang_list = ["en", "ja", "ko", "fr", "de", "es", "it", "pt", "ru", "tr", "pl", "ar", "zh-Hans", "zh-Hant"]
with block:
gr.Markdown('# FramePack')
with gr.Row():
with gr.Column():
input_image = gr.Image(sources='upload', type="numpy", label="Image", height=320)
prompt = gr.Textbox(label="Prompt", value='')
example_quick_prompts = gr.Dataset(samples=quick_prompts, label='Quick List', samples_per_page=1000, components=[prompt])
example_quick_prompts.click(lambda x: x[0], inputs=[example_quick_prompts], outputs=prompt, show_progress=False, queue=False)
with Translate("translations.json", placeholder_langs=lang_list):
gr.Markdown('# FramePack')
with gr.Row():
with gr.Column():
input_image = gr.Image(sources='upload', type="numpy", label=_("Image"), height=320)
prompt = gr.Textbox(label=_("Prompt"), value='')
example_quick_prompts = gr.Dataset(samples=quick_prompts, label=_('Quick List'), samples_per_page=1000, components=[prompt])
example_quick_prompts.click(lambda x: x[0], inputs=[example_quick_prompts], outputs=prompt, show_progress=False, queue=False)

with gr.Row():
start_button = gr.Button(value="Start Generation")
end_button = gr.Button(value="End Generation", interactive=False)
with gr.Row():
start_button = gr.Button(value=_("Start Generation"))
end_button = gr.Button(value=_("End Generation"), interactive=False)

with gr.Group():
use_teacache = gr.Checkbox(label='Use TeaCache', value=True, info='Faster speed, but often makes hands and fingers slightly worse.')
with gr.Group():
use_teacache = gr.Checkbox(label=_('Use TeaCache'), value=True, info=_('Faster speed, but often makes hands and fingers slightly worse.'))

n_prompt = gr.Textbox(label="Negative Prompt", value="", visible=False) # Not used
seed = gr.Number(label="Seed", value=31337, precision=0)
n_prompt = gr.Textbox(label=_("Negative Prompt"), value="", visible=False) # Not used
seed = gr.Number(label=_("Seed"), value=31337, precision=0)

total_second_length = gr.Slider(label="Total Video Length (Seconds)", minimum=1, maximum=120, value=5, step=0.1)
latent_window_size = gr.Slider(label="Latent Window Size", minimum=1, maximum=33, value=9, step=1, visible=False) # Should not change
steps = gr.Slider(label="Steps", minimum=1, maximum=100, value=25, step=1, info='Changing this value is not recommended.')
total_second_length = gr.Slider(label=_("Total Video Length (Seconds)"), minimum=1, maximum=120, value=5, step=0.1)
latent_window_size = gr.Slider(label=_("Latent Window Size"), minimum=1, maximum=33, value=9, step=1, visible=False) # Should not change
steps = gr.Slider(label=_("Steps"), minimum=1, maximum=100, value=25, step=1, info=_('Changing this value is not recommended.'))

cfg = gr.Slider(label="CFG Scale", minimum=1.0, maximum=32.0, value=1.0, step=0.01, visible=False) # Should not change
gs = gr.Slider(label="Distilled CFG Scale", minimum=1.0, maximum=32.0, value=10.0, step=0.01, info='Changing this value is not recommended.')
rs = gr.Slider(label="CFG Re-Scale", minimum=0.0, maximum=1.0, value=0.0, step=0.01, visible=False) # Should not change
cfg = gr.Slider(label=_("CFG Scale"), minimum=1.0, maximum=32.0, value=1.0, step=0.01, visible=False) # Should not change
gs = gr.Slider(label=_("Distilled CFG Scale"), minimum=1.0, maximum=32.0, value=10.0, step=0.01, info=_('Changing this value is not recommended.'))
rs = gr.Slider(label=_("CFG Re-Scale"), minimum=0.0, maximum=1.0, value=0.0, step=0.01, visible=False) # Should not change

gpu_memory_preservation = gr.Slider(label="GPU Inference Preserved Memory (GB) (larger means slower)", minimum=6, maximum=128, value=6, step=0.1, info="Set this number to a larger value if you encounter OOM. Larger value causes slower speed.")
gpu_memory_preservation = gr.Slider(label=_("GPU Inference Preserved Memory (GB) (larger means slower)"), minimum=6, maximum=128, value=6, step=0.1, info=_("Set this number to a larger value if you encounter OOM. Larger value causes slower speed."))

mp4_crf = gr.Slider(label="MP4 Compression", minimum=0, maximum=100, value=16, step=1, info="Lower means better quality. 0 is uncompressed. Change to 16 if you get black outputs. ")
mp4_crf = gr.Slider(label=_("MP4 Compression"), minimum=0, maximum=100, value=16, step=1, info=_("Lower means better quality. 0 is uncompressed. Change to 16 if you get black outputs. "))

with gr.Column():
preview_image = gr.Image(label="Next Latents", height=200, visible=False)
result_video = gr.Video(label="Finished Frames", autoplay=True, show_share_button=False, height=512, loop=True)
gr.Markdown('Note that the ending actions will be generated before the starting actions due to the inverted sampling. If the starting action is not in the video, you just need to wait, and it will be generated later.')
progress_desc = gr.Markdown('', elem_classes='no-generating-animation')
progress_bar = gr.HTML('', elem_classes='no-generating-animation')
with gr.Column():
preview_image = gr.Image(label=_("Next Latents"), height=200, visible=False)
result_video = gr.Video(label=_("Finished Frames"), autoplay=True, show_share_button=False, height=512, loop=True)
gr.Markdown(_('Note that the ending actions will be generated before the starting actions due to the inverted sampling. If the starting action is not in the video, you just need to wait, and it will be generated later.'))
progress_desc = gr.Markdown('', elem_classes='no-generating-animation')
progress_bar = gr.HTML('', elem_classes='no-generating-animation')

gr.HTML('<div style="text-align:center; margin-top:20px;">Share your results and find ideas at the <a href="https://x.com/search?q=framepack&f=live" target="_blank">FramePack Twitter (X) thread</a></div>')
gr.HTML('<div style="text-align:center; margin-top:20px;">Share your results and find ideas at the <a href="https://x.com/search?q=framepack&f=live" target="_blank">FramePack Twitter (X) thread</a></div>')

ips = [input_image, prompt, n_prompt, seed, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, use_teacache, mp4_crf]
start_button.click(fn=process, inputs=ips, outputs=[result_video, preview_image, progress_desc, progress_bar, start_button, end_button])
end_button.click(fn=end_process)
ips = [input_image, prompt, n_prompt, seed, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, use_teacache, mp4_crf]
start_button.click(fn=process, inputs=ips, outputs=[result_video, preview_image, progress_desc, progress_bar, start_button, end_button])
end_button.click(fn=end_process)


block.launch(
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ torchsde==0.2.6
einops
opencv-contrib-python
safetensors
gradio-i18n
Loading