JessicaChen1854 commited on
Commit
c70c3a9
·
verified ·
1 Parent(s): 331c705

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -30
app.py CHANGED
@@ -91,37 +91,37 @@ user_input = st.text_input(
91
  if user_input:
92
 
93
 
94
- # # 1. 生成剧本
95
- # with st.status("🖋️ 剧本生成中...", expanded=True) as status:
96
- # try:
97
- # # 生成内容
98
- # prompt = build_script_prompt(user_input)
99
- # response = script_pipe(
100
- # prompt,
101
- # max_length=600,
102
- # temperature=0.8,
103
- # num_beams=4,
104
- # no_repeat_ngram_size=3
105
- # )[0]["generated_text"]
106
 
107
- # # 后处理
108
- # def format_script(text):
109
- # # 强制修正场景标题格式(如 "场景1" -> "### 场景1")
110
- # text = re.sub(r"场景(\d+)", r"### 场景\1", text)
111
- # # 删除多余符号
112
- # text = re.sub(r"[<>()]{2,}|\[?\]?", "", text)
113
- # # 确保动作描述包裹在方括号内
114
- # return re.sub(r"(?<=\n)\s*([^\[\n]+?)\s*(?=\n)", r"[\1]", text)
115
 
116
- # # 显示结果
117
- # st.subheader("生成剧本")
118
- # st.markdown(f"```markdown\n{format_script(response)}\n```")
119
- # status.update(label="✅ 生成完成", state="complete")
120
 
121
- # except Exception as e:
122
- # status.update(label="❌ 生成失败", state="error")
123
- # st.error(f"错误详情:{str(e)}")
124
- # st.stop()
125
 
126
 
127
  #2. 生成分镜
@@ -142,9 +142,9 @@ if user_input:
142
 
143
  # 生成分镜
144
  storyboard = storyboard_pipe(
145
- f"将以下剧本转换为分镜JSON,严格遵循模板:\n{json_template}\n剧本内容:{script[:800]}",
146
  max_length=1500,
147
- temperature=0.3 # 降低创造性保证格式
148
  )[0]["generated_text"]
149
 
150
  # 格式修复流程
 
91
  if user_input:
92
 
93
 
94
+ # 1. 生成剧本
95
+ with st.status("🖋️ 剧本生成中...", expanded=True) as status:
96
+ try:
97
+ # 生成内容
98
+ prompt = build_script_prompt(user_input)
99
+ response = script_pipe(
100
+ prompt,
101
+ max_length=600,
102
+ temperature=0.8,
103
+ num_beams=4,
104
+ no_repeat_ngram_size=3
105
+ )[0]["generated_text"]
106
 
107
+ # 后处理
108
+ def format_script(text):
109
+ # 强制修正场景标题格式(如 "场景1" -> "### 场景1")
110
+ text = re.sub(r"场景(\d+)", r"### 场景\1", text)
111
+ # 删除多余符号
112
+ text = re.sub(r"[<>()]{2,}|\[?\]?", "", text)
113
+ # 确保动作描述包裹在方括号内
114
+ return re.sub(r"(?<=\n)\s*([^\[\n]+?)\s*(?=\n)", r"[\1]", text)
115
 
116
+ # 显示结果
117
+ st.subheader("生成剧本")
118
+ st.markdown(f"```markdown\n{format_script(response)}\n```")
119
+ status.update(label="✅ 生成完成", state="complete")
120
 
121
+ except Exception as e:
122
+ status.update(label="❌ 生成失败", state="error")
123
+ st.error(f"错误详情:{str(e)}")
124
+ st.stop()
125
 
126
 
127
  #2. 生成分镜
 
142
 
143
  # 生成分镜
144
  storyboard = storyboard_pipe(
145
+ f"将以下剧本转换为分镜JSON,严格遵循模板:\n{json_template}\n剧本内容:{cleaned[:800]}", # 关键修改点
146
  max_length=1500,
147
+ temperature=0.3
148
  )[0]["generated_text"]
149
 
150
  # 格式修复流程