Ronaldo1111 commited on
Commit
4e09e43
·
verified ·
1 Parent(s): d73016e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -69
app.py CHANGED
@@ -211,73 +211,72 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
211
  msg = gr.Textbox(label="想对豌豆说啥?", placeholder="比如:你在干嘛?", lines=2)
212
  btn = gr.Button("投喂")
213
 
214
- # 页面美化注入 HTML + JS + CSS
215
- html_content = f"""
216
- <style>
217
- body {{
218
- margin: 0;
219
- animation: backgroundCycle 60s infinite;
220
- background-size: cover;
221
- background-position: center;
222
- transition: background-image 1s ease-in-out;
223
- }}
224
- @keyframes backgroundCycle {{
225
- {background_css}
226
- }}
227
- .gr-chatbot {{
228
- background: rgba(255, 255, 255, 0.5);
229
- border-radius: 16px;
230
- padding: 10px;
231
- }}
232
- .gr-textbox textarea {{
233
- font-family: monospace;
234
- font-size: 1.1em;
235
- animation: typewriter 1s steps(40, end);
236
- }}
237
- @keyframes typewriter {{
238
- from {{ width: 0 }}
239
- to {{ width: 100% }}
240
- }}
241
- #sophia-avatar {{
242
- position: fixed;
243
- top: 40px;
244
- left: 30px;
245
- width: 80px;
246
- height: 80px;
247
- border-radius: 50%;
248
- z-index: 9999;
249
- cursor: grab;
250
- animation: spinBounce 4s infinite;
251
- }}
252
- @keyframes spinBounce {{
253
- 0% {{ transform: rotate(0deg) translateY(0px); }}
254
- 50% {{ transform: rotate(180deg) translateY(-10px); }}
255
- 100% {{ transform: rotate(360deg) translateY(0px); }}
256
- }}
257
- #birthday-cake {{
258
- position: fixed;
259
- bottom: 20px;
260
- right: 20px;
261
- width: 80px;
262
- animation: bounce 1.5s infinite;
263
- z-index: 9999;
264
- }}
265
- @keyframes bounce {{
266
- 0% {{ transform: translateY(0); }}
267
- 50% {{ transform: translateY(-15px); }}
268
- 100% {{ transform: translateY(0); }}
269
- }}
270
- </style>
271
-
272
- <!-- 动态头像 + 生日蛋糕 -->
273
- <img id="sophia-avatar" src="{avatar_url}" />
274
- <img id="birthday-cake" src="{cake_url}" />
275
- <audio id="bg-music" autoplay loop>
276
- <source src="{music1}" type="audio/mpeg" />
277
- <source src="{music2}" type="audio/mpeg" />
278
- </audio>
279
- <audio id="bark" src="{bark_sound}"></audio>
280
- <canvas id="fireworks" style="position:fixed;top:0;left:0;width:100vw;height:100vh;pointer-events:none;z-index:0;"></canvas>
281
 
282
  <script>
283
  const tracks = ["{music1}", "{music2}"];
@@ -320,7 +319,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
320
  setTimeout(() => {{
321
  ctx.beginPath();
322
  ctx.arc(x, y, Math.random() * 3 + 2, 0, Math.PI * 2);
323
- ctx.fillStyle = `hsl(${Math.random() * 360}, 100%, 60%)`;
324
  ctx.fill();
325
  }}, i * 20);
326
  }}
@@ -328,7 +327,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
328
 
329
  setInterval(firework, 1800);
330
  </script>
331
- """
 
332
  # 替换掉HTML模板中的变量部分
333
  html_content = html_content.replace("{background_css}", background_css)
334
  html_content = html_content.replace("{avatar_url}", avatar_url)
 
211
  msg = gr.Textbox(label="想对豌豆说啥?", placeholder="比如:你在干嘛?", lines=2)
212
  btn = gr.Button("投喂")
213
 
214
+ html_content = f"""
215
+ <style>
216
+ body {{
217
+ margin: 0;
218
+ animation: backgroundCycle 60s infinite;
219
+ background-size: cover;
220
+ background-position: center;
221
+ transition: background-image 1s ease-in-out;
222
+ }}
223
+ @keyframes backgroundCycle {{
224
+ {background_css}
225
+ }}
226
+ .gr-chatbot {{
227
+ background: rgba(255, 255, 255, 0.5);
228
+ border-radius: 16px;
229
+ padding: 10px;
230
+ }}
231
+ .gr-textbox textarea {{
232
+ font-family: monospace;
233
+ font-size: 1.1em;
234
+ animation: typewriter 1s steps(40, end);
235
+ }}
236
+ @keyframes typewriter {{
237
+ from {{ width: 0 }}
238
+ to {{ width: 100% }}
239
+ }}
240
+ #sophia-avatar {{
241
+ position: fixed;
242
+ top: 40px;
243
+ left: 30px;
244
+ width: 80px;
245
+ height: 80px;
246
+ border-radius: 50%;
247
+ z-index: 9999;
248
+ cursor: grab;
249
+ animation: spinBounce 4s infinite;
250
+ }}
251
+ @keyframes spinBounce {{
252
+ 0% {{ transform: rotate(0deg) translateY(0px); }}
253
+ 50% {{ transform: rotate(180deg) translateY(-10px); }}
254
+ 100% {{ transform: rotate(360deg) translateY(0px); }}
255
+ }}
256
+ #birthday-cake {{
257
+ position: fixed;
258
+ bottom: 20px;
259
+ right: 20px;
260
+ width: 80px;
261
+ animation: bounce 1.5s infinite;
262
+ z-index: 9999;
263
+ }}
264
+ @keyframes bounce {{
265
+ 0% {{ transform: translateY(0); }}
266
+ 50% {{ transform: translateY(-15px); }}
267
+ 100% {{ transform: translateY(0); }}
268
+ }}
269
+ </style>
270
+
271
+ <!-- 动态头像 + 生日蛋糕 -->
272
+ <img id="sophia-avatar" src="{avatar_url}" />
273
+ <img id="birthday-cake" src="{cake_url}" />
274
+ <audio id="bg-music" autoplay loop>
275
+ <source src="{music1}" type="audio/mpeg" />
276
+ <source src="{music2}" type="audio/mpeg" />
277
+ </audio>
278
+ <audio id="bark" src="{bark_sound}"></audio>
279
+ <canvas id="fireworks" style="position:fixed;top:0;left:0;width:100vw;height:100vh;pointer-events:none;z-index:0;"></canvas>
 
280
 
281
  <script>
282
  const tracks = ["{music1}", "{music2}"];
 
319
  setTimeout(() => {{
320
  ctx.beginPath();
321
  ctx.arc(x, y, Math.random() * 3 + 2, 0, Math.PI * 2);
322
+ ctx.fillStyle = 'hsl(' + (Math.random() * 360) + ', 100%, 60%)';
323
  ctx.fill();
324
  }}, i * 20);
325
  }}
 
327
 
328
  setInterval(firework, 1800);
329
  </script>
330
+ """
331
+
332
  # 替换掉HTML模板中的变量部分
333
  html_content = html_content.replace("{background_css}", background_css)
334
  html_content = html_content.replace("{avatar_url}", avatar_url)