Update app.py
Browse files
app.py
CHANGED
|
@@ -91,37 +91,37 @@ user_input = st.text_input(
|
|
| 91 |
if user_input:
|
| 92 |
|
| 93 |
|
| 94 |
-
#
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
|
| 126 |
|
| 127 |
#2. 生成分镜
|
|
@@ -142,9 +142,9 @@ if user_input:
|
|
| 142 |
|
| 143 |
# 生成分镜
|
| 144 |
storyboard = storyboard_pipe(
|
| 145 |
-
f"将以下剧本转换为分镜JSON,严格遵循模板:\n{json_template}\n剧本内容:{
|
| 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 |
# 格式修复流程
|