File size: 2,825 Bytes
2d37733
9093067
 
 
2d37733
 
 
68d53f7
2d37733
68d53f7
2d37733
68d53f7
2d37733
 
 
 
 
 
 
 
 
 
 
 
 
 
9093067
 
 
 
 
 
 
 
 
 
2d37733
 
 
 
 
 
 
 
 
 
 
 
 
9093067
 
 
 
 
 
 
2d37733
9093067
 
2d37733
 
9093067
2d37733
 
 
 
 
 
 
 
 
9093067
2d37733
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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()