multimodalart HF Staff commited on
Commit
2d37733
·
verified ·
1 Parent(s): 2787486

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+
4
+ loras = [
5
+ {
6
+ "image": "https://huggingface.co/Remade-AI/Squish/resolve/main/example_videos/tank_squish.mp4",
7
+ "id": "squish",
8
+ "title": "Squish"
9
+ },
10
+ {
11
+ "image": "https://huggingface.co/Remade-AI/Rotate/resolve/main/example_videos/man_rotate.mp4",
12
+ "id": "rotate",
13
+ "title": "Rotate"
14
+ },
15
+
16
+ ]
17
+
18
+ ### Inside this function you can add a call to your backend passing the arguments, then you can return the path to a downloaded video
19
+ ### 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.
20
+ ### os.getenv('BACKEND_URL')
21
+ ### os.getenv('API_KEY')
22
+ def generate_video(input_image, prompt, duration, selected_index):
23
+ pass
24
+
25
+ def update_selection(evt: gr.SelectData):
26
+ selected_lora = loras[evt.index]
27
+ sentence = f"Selected LoRA: {selected_lora['title']}"
28
+ return selected_lora['id'], sentence
29
+
30
+ with gr.Blocks() as demo:
31
+ selected_index = gr.State(None)
32
+ gr.Markdown("# Remade AI - Wan 2.1 I2V effects LoRAs ")
33
+ selected_info = gr.HTML("")
34
+ with gr.Row():
35
+ with gr.Column():
36
+ gallery = gr.Gallery(
37
+ [(item["image"], item["title"]) for item in loras],
38
+ label="Select LoRA",
39
+ allow_preview=False,
40
+ columns=4,
41
+ elem_id="gallery",
42
+ show_share_button=False,
43
+ height=350
44
+ )
45
+ input_image = gr.Image()
46
+ prompt = gr.Textbox(label="Describe your object", placeholder="Cat toy")
47
+ duration = gr.Radio(["Short (3s)", "Long (5s)"], label="Duration")
48
+
49
+ button = gr.Button("Generate")
50
+ with gr.Column():
51
+ output = gr.Video(interactive=False, label="Output video")
52
+
53
+ gallery.select(
54
+ update_selection,
55
+ outputs=[selected_index, selected_info]
56
+ )
57
+ button.click(
58
+ generate_video,
59
+ inputs=[input_image, prompt, duration, selected_index],
60
+ outputs=[output]
61
+ )
62
+
63
+ if __name__ == "__main__":
64
+ demo.launch()