XD-MU commited on
Commit
1ff707e
·
1 Parent(s): 42316e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -16
app.py CHANGED
@@ -85,7 +85,7 @@ DEMO_DATA = [
85
  {
86
  "file": "demo1.mp4",
87
  "title": "案例 1",
88
- "script": "【对话】:1. [0秒-9] (运镜:Handheld+远景-中近景-远景) 林间空地,苏洛焦躁踱步,主角静立;手持推进中近景,苏洛抓发踢石:“真不该答应秦飞,这么短哪找齐三个时光盒!”跺脚,切回远景。2. [9-18] (浅景深+远景-中景-远景) 主角走近,过肩中景虚焦问:“时光盒是什么?”苏洛回头,专业比划:“云丝控制组倒计时机关盒。”远景二人对站。3. [18-26] (Tilt+远景-近景-远景) 远景续讲,切近景苏洛学者状:“指定时间才能开,所以叫时光盒。”镜头下扫手势再回脸,远景收。4. [26-36] (Arc+远景-中近景-远景) 远景苏洛夸张,环绕中近景:“秦飞埋三盒说找不到,我当场拍胸口:风物家苏洛一小时全搞定!”下巴扬拍胸,远景仍骄傲。5. [36-44] (Shaky+远景-中景-远景) 主角中景揶揄:“看你这么急,没完成吧?”背景苏洛瞬间泄气肩耷,微晃暗示心虚,远景低头。6. [44-53] (Pan+远景-近景-远景) 远景垂头,近景苏洛搓衣角小声:“谁料他耍诈盒子远……帮我吗?”抬头平移恳求对视,远景视线交汇。7. [53-62] (Crash Zoom+远景-中景-远景) 远景主角点头微笑,急推中景特写苏洛惊喜:“太好了!那两个方向拜托你,余下我搞定!”捶胸指远,远景振作出发。【人设】苏洛:中等轻盈,大眼亚麻棕乱马尾,短夹克工具腰带上阵,情绪秒切藏不住。主角:中高挺拔,柔和深短发深衣简约,内敛冷静微点头。【场景】午后斑驳林间空地,碎石落叶静树,焦躁转轻松合作。【站位】1.苏洛空地中心来回,主角边缘远距。2.主角走近两三步面对面。3-5.保持近距离,苏洛对主角/侧身垂头。6.再对视。7.苏洛侧指远方。"
89
  },
90
  {
91
  "file": "demo2.mp4",
@@ -95,7 +95,7 @@ DEMO_DATA = [
95
  {
96
  "file": "demo3.mp4",
97
  "title": "案例 3",
98
- "script": "【对话】:1. [0-9](Handheld Camera Effect+全景镜头、中近景镜头)远景镜头展现激战后的荒凉场景,主角与蒙犽站在画面右侧,身姿警惕;画面左侧,袁雪和赵东旭靠着一根燃烧的木桩虚弱地喘息。镜头向前推进并聚焦于袁雪,她瑟瑟发抖,满脸恐惧地看向主角,声音颤抖:“太感谢了!幸好有你们及时赶到!否则现在我们已经变成烤肉大餐了……”她说完还倒吸一口冷气。镜头移动到主角脸上,他眉头微蹙,目光从袁雪身上移开,转向赵东旭,带着关切与专业性评估的神情问道:“伤得怎么样,还站得起来吗?”最后1秒回到远景镜头,确认四人站位。2. [9-17](Shallow Depth of Field+全景镜头、中景镜头)远景镜头中,赵东旭维持着蹲姿。镜头切至以赵东旭为主体的中景,背景中的主角和远处的火光被虚化。赵东旭因痛苦而苍白的脸上,滚动着泪珠,他不敢直视主角,而是低头看着自己毫无知觉的双腿,结结巴巴地回答:“腿一点知觉都没有……”他的声音充满了绝望与无助。最后1秒回到远景镜头,赵东旭的绝望与主角的严肃形成对比。3. [17-25](Panning Shot+全景镜头、中景镜头)远景镜头中,蒙犽从主角身后上前一步。镜头给到蒙犽的中景,他双手抱胸,表情严肃,用不容置喙的口吻对赵东旭和袁雪说:“实力不够就别逞强接甲级委托啊!跟我们走,回营地找百草家治疗。”说完,他侧身用下巴朝主角的方向示意,镜头随之平移,扫过同样保持警惕的主角,蒙犽继续说:“你怎么了,发什么呆呢?”最后1秒回到远景镜头,蒙犽已站在通往主角的路径中央。4. [25-34](Arc Shot+全景镜头、特写镜头)远景镜头中,主角并未理会蒙犽,而是凝视着前方。镜头围绕主角进行缓慢的弧线运动,并推向他的面部特写,他的眼神锐利而专注,紧锁眉头,逐一点头审视周围的环境:“这一带不太对劲。”他先是感受着空气的温度,然后望向地面刚熄灭的火焰痕迹,“气温依然炎热,地面的火焰也没有消退……难道还有漏网之鱼?”最后1秒回到远景镜头,主角独自一人站在队伍前方,形成一道身影。5. [34-41](Crash Zoom+全景镜头、极端特写镜头)远景镜头中,主角的目光猛地转向斜前方。故事情节:一只小型飞行器的身影突然掠过残骸。镜头猛地推向主角的极端特写,捕捉到他瞳孔的剧烈收缩,他倒吸一口气,恍然大悟:“而且……我担心前面还有被困的学生。”他的眼神由惊愕转为决绝。最后1秒回到远景镜头,主角已完全转向前面的道路,毫不犹豫地向前迈出一步。6. [41-49](Deep Depth of Field+全景镜头、中远景镜头)远景镜头中,主角向前走,蒙犽停下脚步。镜头切换为中远景,景深拉大,前景是蒙犽转身离去的背影,他对着主角的背影果断地挥了挥手,大声说道:“知道了。那分头行动吧,我先护送伤员去营地,回头再来找你。”他走动的背影在景深中依然清晰,显示出他会照办的决心。最后1秒回到远景镜头,蒙犽已走出一段距离。7. [49-57](Whip Pan+全景镜头、中远景镜头)远景镜头中,蒙犽走了几步后停下。镜头从远处蒙犽的侧后方开始,他刚要转身,却用眼神示意身前的主角,再次回头,语气带上一丝关切:“哎,你可别跑太远啊!待会大眼枭联系!”话音未落,镜头猛地一甩,从他的脸上摇向他身后数步之遥、静立不动的主角。最后1秒回到远景镜头,两个身影一前一后,保持着准备联系的通讯距离,构成画面。【人物形象】:袁雪:身高约165cm/体态瘦小/面部特征是苍白、多汗且恐惧/深色长发凌乱地披散/穿着朴素的浅色衣物,已被汗水浸透/气质胆怯无助,肢体语言是瑟瑟发抖、不敢直视他人。主角:身高约180cm/体态匀称矫健/面部轮廓分明,眉宇间常紧锁眉头/深色短发,干净利落/身着深色系的战术服,耐磨且便于活动/气质沉稳、敏锐且专业,习惯性地保持警惕,观察环境的习惯性动作是点头审视。蒙犽:身高约182cm/体态结实,站姿充满自信/面部线条硬朗,表情严肃,眼神锐利/刺猬般的黑色短发/身穿带有编号的重甲战斗服,显得经验丰富/气质是年轻的指挥官,行动果断,言语直接,习惯用抱胸、下巴示意等动作表达态度。【场景描述】:午后晴空下的荒凉战场残骸,空气燥热,地面有刚熄灭的火焰痕迹,散落的燃烧木桩发出末日般的微光。【站位】:1:主角与蒙���在画面右侧,袁雪和赵东旭在左侧靠后,靠着燃烧的木桩。2:赵东旭在左侧保持蹲姿,主角与蒙犽在其身后,保持警惕。3:蒙犽从主角身后上前一步,站到主角与赵东旭之间,侧身朝主角。4:主角独自站在队伍最前方,面向前方;蒙犽、袁雪与赵东旭在其身后。5:主角从面向前方,猛地转身朝向斜前方。6:主角向前走,蒙犽停在原地,转身背对主角,朝相反方向走去。7:蒙犽在前,主角在后,保持数步之遥,形成一前一后的站位。"
99
  },
100
  {
101
  "file": "demo4.mp4",
@@ -378,7 +378,7 @@ def parse_script_nodes(script_text: str) -> List[str]:
378
 
379
 
380
  def extract_last_frame(video_path: str, output_path: str) -> Optional[str]:
381
- """提取视频最后一帧作为参考图"""
382
  if cv2 is None:
383
  return None
384
 
@@ -594,9 +594,10 @@ def get_demo_path(filename):
594
  with gr.Blocks(title="AI 剧本视频工厂") as demo:
595
  gr.Markdown("# 🎬 ScriptAgent & Sora/Veo 视频生成工坊 ")
596
 
597
- with gr.Tabs():
 
598
  # --- TAB 1: 剧本创作 ---
599
- with gr.Tab("📝 第一步:剧本创作"):
600
  with gr.Row():
601
  with gr.Column():
602
  llm_input = gr.Textbox(
@@ -628,7 +629,7 @@ with gr.Blocks(title="AI 剧本视频工厂") as demo:
628
  with gr.Accordion("💻 本地部署完整代码(点击展开查看)", open=False):
629
  gr.Markdown("""
630
  ### 📦 完整部署步骤
631
- 以下代码可在本地完整运行,获得最佳性能和输出质量:
632
  """)
633
 
634
  deployment_code = '''import os
@@ -682,15 +683,10 @@ print(response.choices[0].message.content)'''
682
  - 显存: 16GB+ (推荐 24GB)
683
  - 内存: 32GB+
684
  ```
685
-
686
- ### ⚡ 本地部署优势
687
- - ✅ 完整精度模型,无量化损失
688
- - ✅ 更快的推理速度
689
- - ✅ 无网络限制,支持离线运行
690
- - ✅ 可自定义参数(temperature, max_tokens等)
691
  """)
 
692
  # --- TAB 2: 视频生成 ---
693
- with gr.Tab("🎥 第二步:视频生成"):
694
  with gr.Row():
695
  # 左侧配置区
696
  with gr.Column(scale=1):
@@ -772,18 +768,19 @@ print(response.choices[0].message.content)'''
772
  lines=6,
773
  max_lines=6,
774
  interactive=False
775
-
776
  )
 
777
  # 🔥 页面底部警告提示(标红显示)
778
  gr.HTML('<p style="color: red; font-weight: bold; text-align: center; margin-top: 20px; font-size: 16px;">⚠️ 注意:仅供简单测试,由于成本问题在线平台内存只有18G,我们量化了模型,性能效果并不能保证,如果需要最准确的输出请自行部署即可</p>')
779
 
780
  # --- 逻辑绑定 ---
781
  llm_btn.click(chat_with_scriptagent, llm_input, llm_output)
782
 
 
783
  to_video_btn.click(
784
- lambda x: (x, gr.Tabs(selected="🎥 第二步:视频生成")),
785
  inputs=llm_output,
786
- outputs=[video_script_input, demo]
787
  )
788
 
789
  model_sel.change(
 
85
  {
86
  "file": "demo1.mp4",
87
  "title": "案例 1",
88
+ "script": "[Dialogue]: 1. [0-9 seconds] (Camera movement: Handheld + long shot - medium close-up - long shot) In a forest clearing, Su Luo paces anxiously, the protagonist stands still; a medium close-up shot with a camera in hand, Su Luo scratches his hair and kicks a stone: "I really shouldn't have agreed to Qin Fei, how can I find all three time boxes in such a short time!" He stomps his foot, then cuts back to a long shot. 2. [9-18 seconds] (Shallow depth of field + long shot - medium shot - long shot) The protagonist approaches, a medium shot over the shoulder in out of focus asks: "What is a time box?" Su Luo turns around and professionally gestures: "A cloud silk control group countdown mechanism box." The two stand facing each other in a long shot. 3. [18-26 seconds] (Tilt + long shot - close-up - long shot) The long shot continues, then a close-up shot of Su Luo in a scholarly manner: "It can only be opened at a specified time, so it's called a time box." The camera pans down to the gesture and then back to the face, then the long shot ends. 4. [26-36 seconds] (Arc + long shot - medium close-up - long shot) Su Luo exaggerates in the long shot, surrounded by a medium close-up: "Qin Fei buried three boxes saying he couldn't find them, I patted my chest on the spot: Su Luo, the expert in local customs, will get them all done in an hour!" Chin raised, chest patted, still proud in the long shot. 5. [36-44 seconds] (Shaky + long shot - medium shot - long shot) The protagonist in the medium shot teases: "Seeing how anxious you are, you haven't finished, have you?" Su Luo in the background instantly deflates, shoulders droop, slightly swaying to indicate guilt, long shot lowers head. 6. [44-53 seconds] (Pan + long shot - close-up - long shot) Long shot lowers head, close-up Su Luo rubs the corner of his clothes and whispers: "Who would have thought he would cheat with the boxes... help me?" He looks up and moves to make eye contact, long shot meets eyes. 7. [53-62 seconds] (Crash Zoom + Long Shot - Medium Shot - Long Shot) The protagonist nods and smiles in the long shot, then a quick push to the medium shot closes up. Su Luo exclaims with delight, "Great! I'll leave those two directions to you, I'll handle the rest!" She pounds her chest and points into the distance, the protagonist in the long shot exhaling and setting off. 【Character Design】 Su Luo: Medium height and light build, large eyes, flaxen brown hair, messy ponytail, short jacket, tools, belt, emotions instantly revealed. Protagonist: Medium height and upright, soft dark hair, simple dark-colored clothing, reserved and calm, nodding slightly. 【Scene】Afternoon dappled sunlight in a forest clearing, pebbles, fallen leaves, quiet trees, transitioning from anxiety to relaxed cooperation. 【Positioning】 1. Su Luo walks back and forth in the center of the clearing, the protagonist at the edge, at a distance. 2. The protagonist takes two or three steps closer to face her. 3-5. Maintaining close distance, Su Luo faces the protagonist/turns sideways and lowers her head. 6. They look at each other again. 7. Su Luo points to the distance."
89
  },
90
  {
91
  "file": "demo2.mp4",
 
95
  {
96
  "file": "demo3.mp4",
97
  "title": "案例 3",
98
+ "script": "【Dialogue】: 1. [0-9 seconds] (Handheld Camera Effect + panoramic shot, medium close-up shot) A long shot shows the desolate scene after the fierce battle. The protagonist and Meng Ya stand on the right side of the screen, their postures wary; on the left side of the screen, Yuan Xue and Zhao Dongxu lean against a burning wooden stake, panting weakly. The camera moves forward and focuses on Yuan Xue, who is trembling and looking at the protagonist with fear on her face. Her voice trembles: "Thank you so much! Luckily you arrived in time! Otherwise, we would have become a barbecue feast by now..." She finishes speaking and gasps for breath. The camera moves to the protagonist's face. He frowns slightly, his gaze shifts from Yuan Xue to Zhao Dongxu, and asks with concern and professional assessment: "How badly are you injured? Can you still stand up?" The last second returns to the long shot, confirming the four people's positions. 2. [9-17 seconds] (Shallow Depth of Field + panoramic shot, medium shot) In the long shot, Zhao Dongxu maintains a crouching posture. The camera cuts to a medium shot focusing on Zhao Dongxu, blurring the background of the protagonist and the distant firelight. Tears stream down Zhao Dongxu's pale face, a result of his pain. He avoids looking directly at the protagonist, instead looking down at his numb legs, stammering, "I can't feel my legs at all..." His voice is filled with despair and helplessness. The final second returns to a long shot, contrasting Zhao Dongxu's despair with the protagonist's seriousness. 3. [17-25 seconds] (Panning Shot + wide shot, medium shot) In the long shot, Meng Ya steps forward from behind the protagonist. The camera focuses on Meng Ya in a medium shot. He has his arms crossed, a serious expression on his face, and says to Zhao Dongxu and Yuan Xue in an unquestionable tone, "If you're not strong enough, don't try to take on a top-tier commission! Come with us, back to the camp to get treatment from Bai Cao's family." After saying that, he turns to the side and gestures with his chin towards the protagonist. The camera then pans across the protagonist, who is also on guard. Meng Ya continues, "What's wrong with you? Why are you spacing out?" In the last second, the camera returns to a wide shot, showing Meng Ya standing in the middle of the path leading to the protagonist. 4. [25-34 seconds] (Arc Shot + wide shot, close-up shot) In the wide shot, the protagonist ignores Meng Ya and stares ahead. The camera moves slowly in an arc around the protagonist, then zooms in on his face for a close-up. His eyes are sharp and focused, his brow furrowed as he nods and examines his surroundings: “Something’s not right here.” He first senses the temperature of the air, then looks at the remnants of the extinguished flames on the ground. “The temperature is still high, and the flames haven’t died down… Could there be any survivors?” The final second returns to a wide shot, showing the protagonist standing alone at the front of the group, forming a silhouette. 5. [34-41 seconds] (Crash Zoom + wide shot, extreme close-up) In a wide shot, the protagonist’s gaze abruptly shifts to a diagonal angle ahead. Plot: The silhouette of a small aircraft suddenly sweeps past the wreckage. The camera zooms in on the protagonist for an extreme close-up, capturing the violent contraction of his pupils. He gasps, realizing: “And… I’m worried there are still students trapped ahead.” His eyes change from shock to determination. The final second returns to a wide shot, showing the protagonist now fully turned towards the road ahead, taking a step forward without hesitation. 6. [41-49 seconds] (Deep Depth of Field + panoramic shot, medium-long shot) In the long shot, the protagonist walks forward, and Meng Ya stops. The shot switches to a medium-long shot, the depth of field widens, and the foreground shows Meng Ya's back as he turns away. He decisively waves to the protagonist's back and says loudly, "Understood. Let's split up then. I'll escort the wounded to the camp first, and I'll come back to find you later." His walking figure is still clear in the depth of field, showing his determination to do as he says. In the last second, the shot returns to a long shot, and Meng Ya has already walked some distance. 7. [49-57 seconds] (Whip Pan + panoramic shot, medium-long shot) In the long shot, Meng Ya stops after taking a few steps. The camera begins from a distance, slightly behind Meng Ya. He's about to turn around, but gestures with his eyes to the protagonist in front of him. Turning back again, his voice tinged with concern, he says, "Hey, don't go too far! Big Eye Owl will contact you later!" Before he finishes speaking, the camera abruptly pans from his face to the protagonist standing motionless a few steps behind him. The final second returns to a wide shot, showing the two figures, one in front of the other, maintaining a distance suitable for communication, forming the frame. [Character Description]: Yuan Xue: Approximately 165cm tall/slender build/pale, sweaty, and fearful facial features/long, dark hair disheveled/wearing simple, light-colored clothing soaked in sweat/a timid and helpless demeanor, her body language showing trembling and an inability to look directly at others. Main Character: Approximately 180cm tall / Well-proportioned and agile / Distinct facial features, often with a furrowed brow / Short, dark hair, clean and neat / Wears dark tactical uniform, durable and easy to move in / Calm, sharp, and professional demeanor, habitually vigilant, his habitual action of nodding in scrutiny when observing his environment. Meng Ya: Approximately 182cm tall / Sturdy build, confident stance / Strong facial features, serious expression, sharp eyes / Short, spiky black hair / Wears heavily armored combat uniform with numbers, appearing experienced / Demeanor of a young commander, decisive in action, direct in speech, habitually using gestures such as crossing his arms and gesturing with his chin to express his attitude. [Scene Description]: A desolate battlefield wreckage under a clear afternoon sky, the air hot and dry, traces of recently extinguished flames on the ground, scattered burning logs emitting an apocalyptic glow. [Positioning]: 1: The main character and Meng Ya are on the right side of the screen, Yuan Xue and Zhao Dongxu are on the left, slightly behind, leaning against the burning logs. 2. Zhao Dongxu remains crouched on the left, with the protagonist and Meng Ya behind him, remaining alert.3. Meng Ya steps forward from behind the protagonist, standing between the protagonist and Zhao Dongxu, turning sideways towards the protagonist.4. The protagonist stands alone at the front of the group, facing forward; Meng Ya, Yuan Xue, and Zhao Dongxu are behind him.5. The protagonist, who was facing forward, suddenly turns to face diagonally forward.6. The protagonist walks forward, while Meng Ya stops, turns his back to the protagonist, and walks in the opposite direction.7. Meng Ya is in front, and the protagonist is behind, maintaining a distance of several steps, forming a front-and-back formation."
99
  },
100
  {
101
  "file": "demo4.mp4",
 
378
 
379
 
380
  def extract_last_frame(video_path: str, output_path: str) -> Optional[str]:
381
+ """提取视频最后一帧作为参考图"""
382
  if cv2 is None:
383
  return None
384
 
 
594
  with gr.Blocks(title="AI 剧本视频工厂") as demo:
595
  gr.Markdown("# 🎬 ScriptAgent & Sora/Veo 视频生成工坊 ")
596
 
597
+ # 🔥 关键修改:给 Tabs 组件添加变量引用
598
+ with gr.Tabs() as tabs:
599
  # --- TAB 1: 剧本创作 ---
600
+ with gr.Tab("📝 第一步:剧本创作", id=0):
601
  with gr.Row():
602
  with gr.Column():
603
  llm_input = gr.Textbox(
 
629
  with gr.Accordion("💻 本地部署完整代码(点击展开查看)", open=False):
630
  gr.Markdown("""
631
  ### 📦 完整部署步骤
632
+ 以下代码可在本地完整运行,获得最佳性能和输出质量:
633
  """)
634
 
635
  deployment_code = '''import os
 
683
  - 显存: 16GB+ (推荐 24GB)
684
  - 内存: 32GB+
685
  ```
 
 
 
 
 
 
686
  """)
687
+
688
  # --- TAB 2: 视频生成 ---
689
+ with gr.Tab("🎥 第二步:视频生成", id=1):
690
  with gr.Row():
691
  # 左侧配置区
692
  with gr.Column(scale=1):
 
768
  lines=6,
769
  max_lines=6,
770
  interactive=False
 
771
  )
772
+
773
  # 🔥 页面底部警告提示(标红显示)
774
  gr.HTML('<p style="color: red; font-weight: bold; text-align: center; margin-top: 20px; font-size: 16px;">⚠️ 注意:仅供简单测试,由于成本问题在线平台内存只有18G,我们量化了模型,性能效果并不能保证,如果需要最准确的输出请自行部署即可</p>')
775
 
776
  # --- 逻辑绑定 ---
777
  llm_btn.click(chat_with_scriptagent, llm_input, llm_output)
778
 
779
+ # 🔥 关键修改:返回 (剧本内容, 标签页索引)
780
  to_video_btn.click(
781
+ lambda x: (x, 1), # 1 表示切换到第二个标签页(索引从0开始)
782
  inputs=llm_output,
783
+ outputs=[video_script_input, tabs] # 输出到文本框和标签页切换器
784
  )
785
 
786
  model_sel.change(