galikarl commited on
Commit
61483b0
1 Parent(s): 415e096

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +124 -1
app.py CHANGED
@@ -1 +1,124 @@
1
- https://github.com/tfytfty/ez-text2video.git
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # app.py
5
+ #
6
+ # Copyright 2023 KP
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
+ # MA 02110-1301, USA.
22
+ #
23
+ #
24
+
25
+ import argparse
26
+
27
+ import streamlit as st
28
+
29
+ from lib.generate import generate
30
+ from lib.util import convert_to_video, get_device
31
+
32
+
33
+ def main():
34
+ parser = argparse.ArgumentParser()
35
+ parser.add_argument(
36
+ "--device",
37
+ choices=["cuda", "mps", "cpu"],
38
+ help="Override device",
39
+ )
40
+ args = parser.parse_args()
41
+ device = args.device if args.device is not None else get_device()
42
+
43
+ st.set_page_config(
44
+ page_title="ez-text2video",
45
+ page_icon="🎥",
46
+ layout="wide",
47
+ menu_items={
48
+ "Get Help": "https://github.com/kpthedev/ez-text2video",
49
+ "Report a bug": "https://github.com/kpthedev/ez-text2video/issues",
50
+ "About": "# ez-text2video 🎥 \n A Streamlit app to easily run the text-to-video diffusion model.",
51
+ },
52
+ )
53
+ st.write("# ez-text2video 🎥")
54
+ col_left, col_right = st.columns(2)
55
+
56
+ with col_left:
57
+ st.info(
58
+ "The very first time you run this app, it will take some time to download all of the models (~5 mins).",
59
+ icon="ℹ️",
60
+ )
61
+ prompt = st.text_area("Prompt")
62
+
63
+ # Number inputs
64
+ num_sub_col_1, num_sub_col_2, num_sub_col_3, num_sub_col_4 = st.columns(4)
65
+ frames = num_sub_col_1.number_input(
66
+ label="Number of total frames", min_value=1, max_value=999999, value=16
67
+ )
68
+ n_fps = num_sub_col_2.number_input(
69
+ label="Frames per second (fps)", min_value=1, max_value=999999, value=8
70
+ )
71
+ steps = num_sub_col_3.number_input(
72
+ label="Number of inference steps", min_value=1, max_value=999999, value=50
73
+ )
74
+ seed = num_sub_col_4.number_input(
75
+ label="Seed", min_value=1, max_value=999999, value=42
76
+ )
77
+
78
+ # Dim inputs
79
+ dim_sub_col_1, dim_sub_col_2 = st.columns(2)
80
+ height = dim_sub_col_1.slider(
81
+ label="Height", min_value=16, max_value=1024, value=256, step=1
82
+ )
83
+ width = dim_sub_col_2.slider(
84
+ label="Width", min_value=16, max_value=1024, value=256, step=1
85
+ )
86
+
87
+ with st.expander("Optimizations", expanded=True):
88
+ st.markdown(f"**Device:** `{device}`")
89
+ cpu_offload = st.checkbox(
90
+ "Enable CPU offloading",
91
+ value=True if device == "cuda" else False,
92
+ disabled=True if device == "cpu" else False,
93
+ )
94
+ attention_slice = st.checkbox(
95
+ "Enable attention slicing (slow)",
96
+ value=True if device == "mps" else False,
97
+ disabled=True if device == "cpu" else False,
98
+ )
99
+
100
+ if st.button("Generate", use_container_width=True):
101
+ with st.spinner("Generating..."):
102
+ raw_video = generate(
103
+ prompt=prompt,
104
+ num_frames=int(frames),
105
+ num_steps=int(steps),
106
+ seed=int(seed),
107
+ height=height,
108
+ width=width,
109
+ device=device,
110
+ cpu_offload=cpu_offload,
111
+ attention_slice=attention_slice,
112
+ )
113
+ video = convert_to_video(
114
+ video_frames=raw_video,
115
+ fps=int(n_fps),
116
+ filename=f"{prompt.replace(' ', '_').lower()}-{seed}",
117
+ )
118
+
119
+ with col_right:
120
+ st.video(video)
121
+
122
+
123
+ if __name__ == "__main__":
124
+ main()