GuXiaopeng commited on
Commit
d49318f
·
verified ·
1 Parent(s): cf04eb8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -26
app.py CHANGED
@@ -37,6 +37,10 @@ WORKSPACE_DIR = APP_CONFIG.get("workspace_dir", ".workspace")
37
  os.makedirs(WORKSPACE_DIR, exist_ok=True)
38
  CHECKPOINT_FILE = os.path.join(WORKSPACE_DIR, "snapshot.json")
39
 
 
 
 
 
40
  META_SECTIONS_BLACKLIST = set(APP_CONFIG["blacklists"]["meta_sections"])
41
 
42
  def clean_trailing_references(text, keywords=("reference", "references", "reference list", "参考文献")):
@@ -196,19 +200,11 @@ ui, target_lang = APP_CONFIG["ui_labels"][lang_choice], APP_CONFIG["target_lang_
196
  st.markdown(f"<div class='main-title'><h2>{ui['title']}</h2></div>", unsafe_allow_html=True)
197
 
198
  if os.path.exists(CHECKPOINT_FILE) and not (st.session_state.is_running or st.session_state.resume_pipeline or st.session_state.start_pipeline):
199
- st.warning("⚠️ 系统检测到上次因网络或意外中断的未完成论文任务。")
200
- colA, colB = st.columns([1, 1])
201
- if colA.button("🔄 恢复断点续传 (Resume Progress)", key="resume_task"):
202
- st.session_state.resume_pipeline = True
203
- st.session_state.start_pipeline = False
204
- st.rerun()
205
- if colB.button("🗑️ 清除临时数据 (Clear Garbage)", key="clear_task"):
206
- try:
207
- os.remove(CHECKPOINT_FILE)
208
- except OSError:
209
- pass
210
- st.rerun()
211
- st.markdown("---")
212
 
213
  topic = st.text_input(ui["topic_label"], value="Generative Artificial Intelligence in Ubiquitous Learning: Evaluating a Chatbot-based Recommendation Engine for Personalized and Context-aware Education", disabled=st.session_state.is_running)
214
  keywords = st.text_input(ui["keywords_label"], value="Ubiquitous computing; Context awareness; Deep learning; Personalized educational; Educational technologies; HCI; Recommendation system; LLMs; Generative AI; ChatGPT; Prompting engineering; Few-shot prompting", disabled=st.session_state.is_running)
@@ -291,17 +287,6 @@ if st.session_state.start_pipeline or st.session_state.resume_pipeline:
291
  st.error("❌ DEEPSEEK_API_KEY missing. 请配置API KEY。")
292
  st.stop()
293
 
294
- if st.session_state.get("is_running", False):
295
- if global_lock.locked():
296
- try: global_lock.release()
297
- except: pass
298
- # 【修改点:无感自动恢复,移除按钮拦截,直接重置状态并重跑】
299
- st.toast("🔄 检测到页面刷新或网络抖动,系统正在自动恢复进度...", icon="⚡")
300
- st.session_state.is_running = False
301
- st.session_state.start_pipeline = False
302
- st.session_state.resume_pipeline = True
303
- st.rerun()
304
-
305
  if not global_lock.acquire(blocking=False):
306
  st.warning("⏳ 有小伙伴正在创作,您在15-20 分钟后就能正常使用啦")
307
  st.session_state.start_pipeline = False
@@ -599,7 +584,7 @@ if st.session_state.start_pipeline or st.session_state.resume_pipeline:
599
  if trans_text:
600
  full_draft_translated += trans_text + "\n\n"
601
  except Exception as e:
602
- logging.error(f"翻译任务失败: {e}")
603
 
604
  full_draft_en += previous_task["en_text"] + "\n\n"
605
  state["completed_sections"].append(previous_task["name"])
@@ -779,7 +764,7 @@ if st.session_state.start_pipeline or st.session_state.resume_pipeline:
779
  if trans_text:
780
  full_draft_translated += trans_text + "\n\n"
781
  except Exception as e:
782
- logging.error(f"翻译任务失败: {e}")
783
 
784
  full_draft_en += previous_task["en_text"] + "\n\n"
785
  state["completed_sections"].append(previous_task["name"])
@@ -844,6 +829,14 @@ if st.session_state.start_pipeline or st.session_state.resume_pipeline:
844
  st.session_state.zip_buffer = zip_buffer.getvalue()
845
  st.session_state.zip_filename = f"Draft_{bj_time}.zip"
846
 
 
 
 
 
 
 
 
 
847
  try:
848
  os.remove(CHECKPOINT_FILE)
849
  except OSError:
 
37
  os.makedirs(WORKSPACE_DIR, exist_ok=True)
38
  CHECKPOINT_FILE = os.path.join(WORKSPACE_DIR, "snapshot.json")
39
 
40
+ # [新增修改 1] 定义本地输出文件夹,用于存放最终生成的 ZIP 备份
41
+ OUTPUT_DIR = "outputs"
42
+ os.makedirs(OUTPUT_DIR, exist_ok=True)
43
+
44
  META_SECTIONS_BLACKLIST = set(APP_CONFIG["blacklists"]["meta_sections"])
45
 
46
  def clean_trailing_references(text, keywords=("reference", "references", "reference list", "参考文献")):
 
200
  st.markdown(f"<div class='main-title'><h2>{ui['title']}</h2></div>", unsafe_allow_html=True)
201
 
202
  if os.path.exists(CHECKPOINT_FILE) and not (st.session_state.is_running or st.session_state.resume_pipeline or st.session_state.start_pipeline):
203
+ st.toast("🔄 检测到页面刷新或网络抖动,系统正在自动恢复进度...", icon="⚡")
204
+ st.session_state.is_running = False
205
+ st.session_state.start_pipeline = False
206
+ st.session_state.resume_pipeline = True
207
+ st.rerun()
 
 
 
 
 
 
 
 
208
 
209
  topic = st.text_input(ui["topic_label"], value="Generative Artificial Intelligence in Ubiquitous Learning: Evaluating a Chatbot-based Recommendation Engine for Personalized and Context-aware Education", disabled=st.session_state.is_running)
210
  keywords = st.text_input(ui["keywords_label"], value="Ubiquitous computing; Context awareness; Deep learning; Personalized educational; Educational technologies; HCI; Recommendation system; LLMs; Generative AI; ChatGPT; Prompting engineering; Few-shot prompting", disabled=st.session_state.is_running)
 
287
  st.error("❌ DEEPSEEK_API_KEY missing. 请配置API KEY。")
288
  st.stop()
289
 
 
 
 
 
 
 
 
 
 
 
 
290
  if not global_lock.acquire(blocking=False):
291
  st.warning("⏳ 有小伙伴正在创作,您在15-20 分钟后就能正常使用啦")
292
  st.session_state.start_pipeline = False
 
584
  if trans_text:
585
  full_draft_translated += trans_text + "\n\n"
586
  except Exception as e:
587
+ pass
588
 
589
  full_draft_en += previous_task["en_text"] + "\n\n"
590
  state["completed_sections"].append(previous_task["name"])
 
764
  if trans_text:
765
  full_draft_translated += trans_text + "\n\n"
766
  except Exception as e:
767
+ pass
768
 
769
  full_draft_en += previous_task["en_text"] + "\n\n"
770
  state["completed_sections"].append(previous_task["name"])
 
829
  st.session_state.zip_buffer = zip_buffer.getvalue()
830
  st.session_state.zip_filename = f"Draft_{bj_time}.zip"
831
 
832
+ # [新增修改 2] 落地即保存机制:写入本地硬盘备份
833
+ try:
834
+ disk_save_path = os.path.join(OUTPUT_DIR, st.session_state.zip_filename)
835
+ with open(disk_save_path, "wb") as f_out:
836
+ f_out.write(st.session_state.zip_buffer)
837
+ except Exception as e:
838
+ pass
839
+
840
  try:
841
  os.remove(CHECKPOINT_FILE)
842
  except OSError: