Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,7 +23,7 @@ import pandas as pd
|
|
| 23 |
import numpy as np
|
| 24 |
import threading
|
| 25 |
from concurrent.futures import ThreadPoolExecutor
|
| 26 |
-
from streamlit.runtime.scriptrunner import add_script_run_ctx
|
| 27 |
|
| 28 |
from config import APP_CONFIG, AMJ_PROMPTS, GENERIC_PROMPTS
|
| 29 |
from utils.file_parser import extract_text_from_files, extract_data_from_files
|
|
@@ -315,7 +315,6 @@ if st.session_state.start_pipeline or st.session_state.resume_pipeline:
|
|
| 315 |
agent = SSciPipelineAgent(global_ds_key, global_s2_key)
|
| 316 |
SAFE_CHUNK_WORDS = agent.chunk_words_cyrillic if target_lang in ["Russian (Русский)", "Kazakh (Қазақша)"] else agent.chunk_words_default
|
| 317 |
|
| 318 |
-
# 【修复 2】将 clone_arch 的实例化提升到全局级别,确保断点续传时它始终存在
|
| 319 |
clone_arch = get_clone_architect(agent)
|
| 320 |
|
| 321 |
try:
|
|
@@ -351,7 +350,6 @@ if st.session_state.start_pipeline or st.session_state.resume_pipeline:
|
|
| 351 |
APP_CONFIG.update(state.get("prompt_config", GENERIC_PROMPTS))
|
| 352 |
st.success(f"✅ 断点加载成功!将从节点 {len(completed_sections)}/{len(adaptive_structure)} 安全恢复。")
|
| 353 |
|
| 354 |
-
# 【修复 1】强制在加载完毕后立刻渲染算力监控面板,展示已找回的 API 调用次数
|
| 355 |
render_monitor(agent, "断点恢复 (Resuming)", "状态校验", "✅ 成功找回历史算力消耗数据")
|
| 356 |
|
| 357 |
else:
|
|
@@ -729,8 +727,17 @@ if st.session_state.start_pipeline or st.session_state.resume_pipeline:
|
|
| 729 |
pb.progress(min(15 + int((current_step / total_steps) * 80), 95), text=f"🇬🇧 {display_name} 英文完成,翻译任务已挂载后台...")
|
| 730 |
|
| 731 |
trans_ph.info("⏳ 英文已完成,正在后台异步翻译...")
|
| 732 |
-
|
| 733 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 734 |
async_translation_tasks.append({"name": display_name, "future": future})
|
| 735 |
|
| 736 |
except Exception as e:
|
|
|
|
| 23 |
import numpy as np
|
| 24 |
import threading
|
| 25 |
from concurrent.futures import ThreadPoolExecutor
|
| 26 |
+
from streamlit.runtime.scriptrunner import add_script_run_ctx, get_script_run_ctx
|
| 27 |
|
| 28 |
from config import APP_CONFIG, AMJ_PROMPTS, GENERIC_PROMPTS
|
| 29 |
from utils.file_parser import extract_text_from_files, extract_data_from_files
|
|
|
|
| 315 |
agent = SSciPipelineAgent(global_ds_key, global_s2_key)
|
| 316 |
SAFE_CHUNK_WORDS = agent.chunk_words_cyrillic if target_lang in ["Russian (Русский)", "Kazakh (Қазақша)"] else agent.chunk_words_default
|
| 317 |
|
|
|
|
| 318 |
clone_arch = get_clone_architect(agent)
|
| 319 |
|
| 320 |
try:
|
|
|
|
| 350 |
APP_CONFIG.update(state.get("prompt_config", GENERIC_PROMPTS))
|
| 351 |
st.success(f"✅ 断点加载成功!将从节点 {len(completed_sections)}/{len(adaptive_structure)} 安全恢复。")
|
| 352 |
|
|
|
|
| 353 |
render_monitor(agent, "断点恢复 (Resuming)", "状态校验", "✅ 成功找回历史算力消耗数据")
|
| 354 |
|
| 355 |
else:
|
|
|
|
| 727 |
pb.progress(min(15 + int((current_step / total_steps) * 80), 95), text=f"🇬🇧 {display_name} 英文完成,翻译任务已挂载后台...")
|
| 728 |
|
| 729 |
trans_ph.info("⏳ 英文已完成,正在后台异步翻译...")
|
| 730 |
+
|
| 731 |
+
# 获取当前主线程的 Streamlit 上下文
|
| 732 |
+
ctx = get_script_run_ctx()
|
| 733 |
+
|
| 734 |
+
# 定义包装器,在子线程内强制绑定上下文
|
| 735 |
+
def thread_wrapper(agent_obj, text, ph, lang, q_flag):
|
| 736 |
+
add_script_run_ctx(threading.current_thread(), ctx)
|
| 737 |
+
return async_translate_task(agent_obj, text, ph, lang, q_flag)
|
| 738 |
+
|
| 739 |
+
# 提交带上下文的包装器函数到线程池
|
| 740 |
+
future = translation_executor.submit(thread_wrapper, agent, en_draft_clean, trans_ph, target_lang, is_quarantined)
|
| 741 |
async_translation_tasks.append({"name": display_name, "future": future})
|
| 742 |
|
| 743 |
except Exception as e:
|