Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -105,9 +105,9 @@ is_active_session = st.session_state.get("is_running", False) or \
|
|
| 105 |
st.session_state.get("resume_pipeline", False)
|
| 106 |
|
| 107 |
if not is_active_session and global_lock.locked():
|
| 108 |
-
st.markdown("<h3 style='text-align: center; color: #e6a23c;'>⏳ 系统忙碌
|
| 109 |
-
st.warning("🚨
|
| 110 |
-
st.info("💡 预计
|
| 111 |
st.stop()
|
| 112 |
# =====================================================================
|
| 113 |
|
|
@@ -723,8 +723,12 @@ if st.session_state.start_pipeline or st.session_state.resume_pipeline:
|
|
| 723 |
theory_injection = "\n\n".join(extra_directives)
|
| 724 |
sys_prompt_m3 = APP_CONFIG["sys_academic_writer"] + "\n" + APP_CONFIG["deep_refinement_directive"]
|
| 725 |
wiz_data_injection = f"\n<USER_ACTUAL_DATA>\n{user_data_md}\n</USER_ACTUAL_DATA>\n" if user_data_md and sec["is_method_or_result"] else ""
|
| 726 |
-
|
|
|
|
| 727 |
|
|
|
|
|
|
|
|
|
|
| 728 |
if agent._count_tokens(sys_prompt_m3) + agent._count_tokens(base_user) > 60000:
|
| 729 |
base_user = agent._truncate_context(base_user, 60000 - agent._count_tokens(sys_prompt_m3))
|
| 730 |
|
|
@@ -745,8 +749,15 @@ if st.session_state.start_pipeline or st.session_state.resume_pipeline:
|
|
| 745 |
|
| 746 |
status.update(label=f"✅ 【{display_name}】撰写完毕!", state="complete", expanded=False)
|
| 747 |
|
|
|
|
| 748 |
en_draft_clean = re.sub(rf'(?im)^#\s*{re.escape(sec_title)}\s*\n+', '', en_draft_clean).strip()
|
| 749 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 750 |
en_draft_clean = re.sub(r'(?m)^(#{2,3})\s+[\d\.\s一二三四五六七八九十、]+\s*(.*)', r'\1 \2', en_draft_clean)
|
| 751 |
en_draft_clean = re.sub(r'(?m)^####\s+(.*)', r'**\1**', en_draft_clean)
|
| 752 |
|
|
|
|
| 105 |
st.session_state.get("resume_pipeline", False)
|
| 106 |
|
| 107 |
if not is_active_session and global_lock.locked():
|
| 108 |
+
st.markdown("<h3 style='text-align: center; color: #e6a23c;'>⏳ 系统忙碌 / System Busy</h3>", unsafe_allow_html=True)
|
| 109 |
+
st.warning("🚨 有小伙伴正在写作中")
|
| 110 |
+
st.info("💡 预计15-20 分钟后可正常使用")
|
| 111 |
st.stop()
|
| 112 |
# =====================================================================
|
| 113 |
|
|
|
|
| 723 |
theory_injection = "\n\n".join(extra_directives)
|
| 724 |
sys_prompt_m3 = APP_CONFIG["sys_academic_writer"] + "\n" + APP_CONFIG["deep_refinement_directive"]
|
| 725 |
wiz_data_injection = f"\n<USER_ACTUAL_DATA>\n{user_data_md}\n</USER_ACTUAL_DATA>\n" if user_data_md and sec["is_method_or_result"] else ""
|
| 726 |
+
# 判断是否为续写区块,动态调整引导语
|
| 727 |
+
action_verb = f"Generate the main section '{sec_title}'" if sec["is_first"] else f"Continue generating the subsequent paragraphs for the section '{sec_title}' (DO NOT restate the main section title)"
|
| 728 |
|
| 729 |
+
base_user = f"{action_verb}.\n{length_directive}\n{quarantine_rule}\n{heading_instruction}\n{theory_injection}\n{memory_block}\nSynthesis: {synthesis_result}\n{wiz_data_injection}\nPrevious Tail: ...{context_tail}...\nIMPORTANT: Output final text."
|
| 730 |
+
|
| 731 |
+
|
| 732 |
if agent._count_tokens(sys_prompt_m3) + agent._count_tokens(base_user) > 60000:
|
| 733 |
base_user = agent._truncate_context(base_user, 60000 - agent._count_tokens(sys_prompt_m3))
|
| 734 |
|
|
|
|
| 749 |
|
| 750 |
status.update(label=f"✅ 【{display_name}】撰写完毕!", state="complete", expanded=False)
|
| 751 |
|
| 752 |
+
# 提取模型文本后的初步正则清理
|
| 753 |
en_draft_clean = re.sub(rf'(?im)^#\s*{re.escape(sec_title)}\s*\n+', '', en_draft_clean).strip()
|
| 754 |
|
| 755 |
+
# =====================================================================
|
| 756 |
+
# [新增拦截] 暴力擦除模型可能生成的带有 (Part X/Y) 的各级幽灵标题
|
| 757 |
+
# 匹配任意级别的标题(#) + 任意字符 + (Part 数字/数字) + 换行符,将其替换为空
|
| 758 |
+
# =====================================================================
|
| 759 |
+
en_draft_clean = re.sub(r'(?im)^#+\s*.*\(Part\s*\d+/\d+\).*?\n+', '', en_draft_clean)
|
| 760 |
+
|
| 761 |
en_draft_clean = re.sub(r'(?m)^(#{2,3})\s+[\d\.\s一二三四五六七八九十、]+\s*(.*)', r'\1 \2', en_draft_clean)
|
| 762 |
en_draft_clean = re.sub(r'(?m)^####\s+(.*)', r'**\1**', en_draft_clean)
|
| 763 |
|