Spaces:
Running
Running
import os | |
import requests | |
import gradio as gr | |
loras = [ | |
{ | |
#I suggest it to be a gif instead of an mp4! | |
"image": "https://huggingface.co/Remade-AI/Squish/resolve/main/example_videos/tank_squish.mp4", | |
#This is an id you can send to your backend, obviously you can change it | |
"id": "squish", | |
#This is the title that is shown on the front end | |
"title": "Squish" | |
}, | |
{ | |
"image": "https://huggingface.co/Remade-AI/Rotate/resolve/main/example_videos/man_rotate.mp4", | |
"id": "rotate", | |
"title": "Rotate" | |
}, | |
] | |
### Inside this function you can add a call to your backend passing the arguments, then you can return the path to a downloaded video | |
### To not have the code/API public, you can go on "Settings" and add a Secret. The secrets appear here as environemnt variables, e.g. | |
### os.getenv('BACKEND_URL') | |
### os.getenv('API_KEY') | |
def generate_video(input_image, subject, duration, selected_index): | |
if selected_index == "squish": | |
#I suggest not exposing this to the user for simplicity | |
prompt = f"In the video, a miniature {subject} is presented. The {subject} is held in a person's hands. The person then presses on the {subject}, causing a sq41sh squish effect. The person keeps pressing down on the {subject}, further showing the sq41sh squish effect." | |
#do all the things to submit the request | |
#url and heads can come from the env variable | |
response = requests.post(url, data=data, files=files, headers=headers) | |
pass | |
def update_selection(evt: gr.SelectData): | |
selected_lora = loras[evt.index] | |
sentence = f"Selected LoRA: {selected_lora['title']}" | |
return selected_lora['id'], sentence | |
with gr.Blocks() as demo: | |
selected_index = gr.State(None) | |
gr.Markdown("# Remade AI - Wan 2.1 I2V effects LoRAs ") | |
selected_info = gr.HTML("") | |
with gr.Row(): | |
with gr.Column(): | |
gallery = gr.Gallery( | |
[(item["image"], item["title"]) for item in loras], | |
label="Select LoRA", | |
allow_preview=False, | |
columns=4, | |
elem_id="gallery", | |
show_share_button=False, | |
height=350 | |
) | |
input_image = gr.Image(type="filepath") | |
subject = gr.Textbox(label="Describe your subject", placeholder="Cat toy") | |
duration = gr.Radio(["Short (3s)", "Long (5s)"], label="Duration") | |
button = gr.Button("Generate") | |
with gr.Column(): | |
output = gr.Video(interactive=False, label="Output video") | |
gallery.select( | |
update_selection, | |
outputs=[selected_index, selected_info] | |
) | |
button.click( | |
generate_video, | |
inputs=[input_image, subject, duration, selected_index], | |
outputs=[output] | |
) | |
if __name__ == "__main__": | |
demo.launch() | |