Jessiesj commited on
Commit
922bd17
·
verified ·
1 Parent(s): 06df4c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -7
app.py CHANGED
@@ -26,12 +26,12 @@ def load_pipelines():
26
  device=0 if torch.cuda.is_available() else -1
27
  )
28
 
29
- # # 3. Soundtrack generation (MusicGen)
30
- # # music_pipe = pipeline(
31
- # # "text-to-audio",
32
- # # model="facebook/musicgen-small",
33
- # # device_map="auto"
34
- # # )
35
 
36
  # 4. Storyboard image generation (Stable Diffusion)
37
  image_pipe = StableDiffusionPipeline.from_pretrained(
@@ -236,4 +236,44 @@ if user_input and style_or_opening:
236
  # st.error("生成过程中发生错误")
237
  # st.code(f"错误详情:{str(e)}")
238
  # st.button("点击查看技术详情",
239
- # help="将以下信息提供给技术人员:\n" + str(e))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  device=0 if torch.cuda.is_available() else -1
27
  )
28
 
29
+ # 3. Soundtrack generation (MusicGen)
30
+ music_pipe = pipeline(
31
+ "text-to-audio",
32
+ model="facebook/musicgen-small",
33
+ device_map="auto"
34
+ )
35
 
36
  # 4. Storyboard image generation (Stable Diffusion)
37
  image_pipe = StableDiffusionPipeline.from_pretrained(
 
236
  # st.error("生成过程中发生错误")
237
  # st.code(f"错误详情:{str(e)}")
238
  # st.button("点击查看技术详情",
239
+ # help="将以下信息提供给技术人员:\n" + str(e))
240
+ st.subheader("🎧 Background Music")
241
+ for i, scene in enumerate(parsed["scenes"]):
242
+ action = scene["action"]
243
+ with st.spinner(f"🎵 Generating soundtrack for scene {i + 1}..."):
244
+ try:
245
+ audio = music_pipe(
246
+ action,
247
+ max_new_tokens=256
248
+ )
249
+ audio_buffer = BytesIO()
250
+ audio["audio"].export(audio_buffer, format="wav")
251
+ st.audio(audio_buffer, format="audio/wav", caption=f"Soundtrack for scene {i + 1}")
252
+ except Exception as e:
253
+ st.error(f"Failed to generate soundtrack for scene {i + 1}: {str(e)}")
254
+
255
+ st.subheader("🎨 Storyboard Images")
256
+ for i, scene in enumerate(parsed["scenes"]):
257
+ location = scene["location"]
258
+ if st.toggle(f"Generate preview for scene {i + 1} (takes 2 - 3 minutes)"):
259
+ with st.spinner(f"🖼️ Rendering image for scene {i + 1}..."):
260
+ try:
261
+ # 精细化图片提示词
262
+ image_prompt = f"""Movie still, {location},
263
+ Ultra - high - definition 8K resolution,
264
+ Movie - level lighting, shallow depth - of - field effect,
265
+ Unreal Engine 5 rendering,
266
+ Movie film graininess"""
267
+
268
+ # 优化生成参数
269
+ image = image_pipe(
270
+ image_prompt,
271
+ num_inference_steps=50,
272
+ guidance_scale=9.5,
273
+ width=1024,
274
+ height=576 # 16:9 movie ratio
275
+ ).images[0]
276
+
277
+ st.image(image, caption=f"Preview for scene {i + 1}")
278
+ except Exception as e:
279
+ st.error(f"Failed to generate image for scene {i + 1}: {str(e)}")