Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -10,9 +10,98 @@ from huggingface_hub import hf_hub_download
|
|
10 |
from safetensors.torch import load_file
|
11 |
from PIL import Image
|
12 |
|
13 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
USERS = {
|
15 |
-
"vip": "vip888",
|
16 |
}
|
17 |
|
18 |
# Constants
|
@@ -80,32 +169,41 @@ def generate_image(prompt, base="写实风格", motion="", step=8, progress=gr.P
|
|
80 |
return path
|
81 |
|
82 |
# Gradio Interface
|
83 |
-
with gr.Blocks(css=
|
84 |
# 创建两个界面容器
|
85 |
with gr.Group(visible=True) as login_container:
|
86 |
-
gr.HTML("
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
# 主界面
|
93 |
with gr.Group(visible=False) as main_container:
|
94 |
-
gr.HTML(
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
102 |
with gr.Row():
|
103 |
prompt = gr.Textbox(
|
104 |
-
label='
|
|
|
|
|
105 |
)
|
106 |
with gr.Row():
|
107 |
select_base = gr.Dropdown(
|
108 |
-
label='
|
109 |
choices=[
|
110 |
"卡通风格",
|
111 |
"写实风格",
|
@@ -113,64 +211,72 @@ with gr.Blocks(css="style.css") as demo:
|
|
113 |
"动漫风格",
|
114 |
],
|
115 |
value=base_loaded,
|
116 |
-
interactive=True
|
|
|
117 |
)
|
118 |
select_motion = gr.Dropdown(
|
119 |
-
label='
|
120 |
choices=[
|
121 |
-
("
|
122 |
-
("
|
123 |
-
("
|
124 |
("向上倾斜", "guoyww/animatediff-motion-lora-tilt-up"),
|
125 |
("向下倾斜", "guoyww/animatediff-motion-lora-tilt-down"),
|
126 |
("向左平移", "guoyww/animatediff-motion-lora-pan-left"),
|
127 |
("向右平移", "guoyww/animatediff-motion-lora-pan-right"),
|
128 |
-
("
|
129 |
-
("
|
130 |
],
|
131 |
value="guoyww/animatediff-motion-lora-zoom-in",
|
132 |
-
interactive=True
|
|
|
133 |
)
|
134 |
select_step = gr.Dropdown(
|
135 |
-
label='
|
136 |
choices=[
|
137 |
-
('1步', 1),
|
138 |
-
('2步', 2),
|
139 |
-
('4步', 4),
|
140 |
-
('8步', 8),
|
141 |
],
|
142 |
value=4,
|
143 |
-
interactive=True
|
144 |
-
|
145 |
-
submit = gr.Button(
|
146 |
-
value="生成",
|
147 |
-
scale=1,
|
148 |
-
variant='primary'
|
149 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
video = gr.Video(
|
151 |
-
label='
|
152 |
autoplay=True,
|
153 |
height=512,
|
154 |
width=512,
|
155 |
-
elem_id="video_output"
|
|
|
156 |
)
|
157 |
|
158 |
-
gr.
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
|
|
|
|
174 |
|
175 |
# 生成按钮事件
|
176 |
submit.click(
|
|
|
10 |
from safetensors.torch import load_file
|
11 |
from PIL import Image
|
12 |
|
13 |
+
# 自定义CSS样式
|
14 |
+
custom_css = """
|
15 |
+
.container {
|
16 |
+
max-width: 1000px;
|
17 |
+
margin: auto;
|
18 |
+
padding: 20px;
|
19 |
+
}
|
20 |
+
|
21 |
+
.title {
|
22 |
+
background: linear-gradient(90deg, #00ff87 0%, #60efff 100%);
|
23 |
+
-webkit-background-clip: text;
|
24 |
+
-webkit-text-fill-color: transparent;
|
25 |
+
font-size: 2.5em;
|
26 |
+
text-align: center;
|
27 |
+
margin-bottom: 1em;
|
28 |
+
font-weight: bold;
|
29 |
+
text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
|
30 |
+
}
|
31 |
+
|
32 |
+
.subtitle {
|
33 |
+
color: #666;
|
34 |
+
text-align: center;
|
35 |
+
margin-bottom: 2em;
|
36 |
+
font-size: 1.2em;
|
37 |
+
}
|
38 |
+
|
39 |
+
.warning {
|
40 |
+
color: #ff4b4b;
|
41 |
+
font-weight: bold;
|
42 |
+
text-align: center;
|
43 |
+
padding: 10px;
|
44 |
+
margin: 10px 0;
|
45 |
+
border-radius: 5px;
|
46 |
+
background: rgba(255,75,75,0.1);
|
47 |
+
}
|
48 |
+
|
49 |
+
.info {
|
50 |
+
color: #4b8bff;
|
51 |
+
text-align: center;
|
52 |
+
padding: 10px;
|
53 |
+
margin: 10px 0;
|
54 |
+
border-radius: 5px;
|
55 |
+
background: rgba(75,139,255,0.1);
|
56 |
+
}
|
57 |
+
|
58 |
+
.gradio-container {
|
59 |
+
background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%);
|
60 |
+
}
|
61 |
+
|
62 |
+
.gr-button {
|
63 |
+
background: linear-gradient(90deg, #00ff87 0%, #60efff 100%);
|
64 |
+
border: none;
|
65 |
+
color: black;
|
66 |
+
font-weight: bold;
|
67 |
+
}
|
68 |
+
|
69 |
+
.gr-button:hover {
|
70 |
+
background: linear-gradient(90deg, #60efff 0%, #00ff87 100%);
|
71 |
+
transform: translateY(-2px);
|
72 |
+
box-shadow: 0 5px 15px rgba(0,255,135,0.3);
|
73 |
+
transition: all 0.3s ease;
|
74 |
+
}
|
75 |
+
|
76 |
+
.gr-input, .gr-dropdown {
|
77 |
+
border: 2px solid rgba(96,239,255,0.2);
|
78 |
+
border-radius: 8px;
|
79 |
+
background: rgba(26,26,26,0.9);
|
80 |
+
color: white;
|
81 |
+
}
|
82 |
+
|
83 |
+
.gr-input:focus, .gr-dropdown:focus {
|
84 |
+
border-color: #00ff87;
|
85 |
+
box-shadow: 0 0 10px rgba(0,255,135,0.3);
|
86 |
+
}
|
87 |
+
|
88 |
+
.gr-form {
|
89 |
+
background: rgba(42,42,42,0.8);
|
90 |
+
border-radius: 15px;
|
91 |
+
padding: 20px;
|
92 |
+
box-shadow: 0 8px 32px rgba(0,0,0,0.3);
|
93 |
+
}
|
94 |
+
|
95 |
+
.example-container {
|
96 |
+
background: rgba(255,255,255,0.05);
|
97 |
+
border-radius: 10px;
|
98 |
+
padding: 15px;
|
99 |
+
margin: 10px 0;
|
100 |
+
}
|
101 |
+
"""
|
102 |
+
|
103 |
USERS = {
|
104 |
+
"vip": "vip888",
|
105 |
}
|
106 |
|
107 |
# Constants
|
|
|
169 |
return path
|
170 |
|
171 |
# Gradio Interface
|
172 |
+
with gr.Blocks(css=custom_css) as demo:
|
173 |
# 创建两个界面容器
|
174 |
with gr.Group(visible=True) as login_container:
|
175 |
+
gr.HTML("""
|
176 |
+
<div class="container">
|
177 |
+
<h1 class="title">🌟 OfficeChatAI 视频生成系统</h1>
|
178 |
+
<p class="subtitle">欢迎使用AI视频生成系统,让创意转化为现实</p>
|
179 |
+
</div>
|
180 |
+
""")
|
181 |
+
with gr.Group(elem_classes="gr-form"):
|
182 |
+
username = gr.Textbox(label="用户名", placeholder="请输入VIP用户名")
|
183 |
+
password = gr.Textbox(label="密码", type="password", placeholder="请输入密码")
|
184 |
+
login_button = gr.Button("登 录", variant="primary")
|
185 |
+
login_msg = gr.Textbox(label="登录状态", interactive=False)
|
186 |
|
187 |
# 主界面
|
188 |
with gr.Group(visible=False) as main_container:
|
189 |
+
gr.HTML("""
|
190 |
+
<div class="container">
|
191 |
+
<h1 class="title">🎬 OfficeChatAI 视频生成工作室</h1>
|
192 |
+
<p class="subtitle">专业的AI视频生成平台 | VIP尊享服务</p>
|
193 |
+
<div class="warning">提示:首次生成视频需要较长时间,后续生成速度会显著提升</div>
|
194 |
+
<div class="info">为获得最佳效果,建议使用英文提示词,参考示例格式</div>
|
195 |
+
</div>
|
196 |
+
""")
|
197 |
+
with gr.Group(elem_classes="gr-form"):
|
198 |
with gr.Row():
|
199 |
prompt = gr.Textbox(
|
200 |
+
label='创作提示词',
|
201 |
+
placeholder='请输入您想要生成的视频场景描述...',
|
202 |
+
elem_classes="gr-input"
|
203 |
)
|
204 |
with gr.Row():
|
205 |
select_base = gr.Dropdown(
|
206 |
+
label='选择基础模型',
|
207 |
choices=[
|
208 |
"卡通风格",
|
209 |
"写实风格",
|
|
|
211 |
"动漫风格",
|
212 |
],
|
213 |
value=base_loaded,
|
214 |
+
interactive=True,
|
215 |
+
elem_classes="gr-dropdown"
|
216 |
)
|
217 |
select_motion = gr.Dropdown(
|
218 |
+
label='动作特效',
|
219 |
choices=[
|
220 |
+
("默认效果", ""),
|
221 |
+
("镜头拉近", "guoyww/animatediff-motion-lora-zoom-in"),
|
222 |
+
("镜头拉远", "guoyww/animatediff-motion-lora-zoom-out"),
|
223 |
("向上倾斜", "guoyww/animatediff-motion-lora-tilt-up"),
|
224 |
("向下倾斜", "guoyww/animatediff-motion-lora-tilt-down"),
|
225 |
("向左平移", "guoyww/animatediff-motion-lora-pan-left"),
|
226 |
("向右平移", "guoyww/animatediff-motion-lora-pan-right"),
|
227 |
+
("逆时针旋转", "guoyww/animatediff-motion-lora-rolling-anticlockwise"),
|
228 |
+
("顺时针旋转", "guoyww/animatediff-motion-lora-rolling-clockwise"),
|
229 |
],
|
230 |
value="guoyww/animatediff-motion-lora-zoom-in",
|
231 |
+
interactive=True,
|
232 |
+
elem_classes="gr-dropdown"
|
233 |
)
|
234 |
select_step = gr.Dropdown(
|
235 |
+
label='生成质量',
|
236 |
choices=[
|
237 |
+
('快速模式(1步)', 1),
|
238 |
+
('平衡模式(2步)', 2),
|
239 |
+
('高质量(4步)', 4),
|
240 |
+
('超高清(8步)', 8),
|
241 |
],
|
242 |
value=4,
|
243 |
+
interactive=True,
|
244 |
+
elem_classes="gr-dropdown"
|
|
|
|
|
|
|
|
|
245 |
)
|
246 |
+
submit = gr.Button(
|
247 |
+
value="✨ 开始生成",
|
248 |
+
scale=1,
|
249 |
+
variant="primary",
|
250 |
+
elem_classes=["gr-button"]
|
251 |
+
)
|
252 |
+
|
253 |
video = gr.Video(
|
254 |
+
label='创作结果',
|
255 |
autoplay=True,
|
256 |
height=512,
|
257 |
width=512,
|
258 |
+
elem_id="video_output",
|
259 |
+
elem_classes="output-video"
|
260 |
)
|
261 |
|
262 |
+
with gr.Group(elem_classes="example-container"):
|
263 |
+
gr.HTML("<h3 class='subtitle'>🎯 创作灵感</h3>")
|
264 |
+
gr.Examples(
|
265 |
+
examples=[
|
266 |
+
["A majestic Eiffel Tower with moving clouds in the background"],
|
267 |
+
["A lion running through a dense forest"],
|
268 |
+
["An astronaut floating in space with stars twinkling"],
|
269 |
+
["A flock of birds flying in formation against a blue sky"],
|
270 |
+
["Statue of Liberty viewed from a approaching drone"],
|
271 |
+
["A cute panda drinking tea in a bamboo forest"],
|
272 |
+
["Children playing in the snow"],
|
273 |
+
["Cars driving on a rainy city street"]
|
274 |
+
],
|
275 |
+
fn=generate_image,
|
276 |
+
inputs=[prompt],
|
277 |
+
outputs=[video],
|
278 |
+
cache_examples="lazy",
|
279 |
+
)
|
280 |
|
281 |
# 生成按钮事件
|
282 |
submit.click(
|