Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -160,7 +160,6 @@ def save_pdf(file, session_id):
|
|
| 160 |
|
| 161 |
file_path = os.path.join(papers_dir, os.path.basename(file.name))
|
| 162 |
shutil.copy(file.name, file_path)
|
| 163 |
-
# 上传成功后显示进度条以反馈状态
|
| 164 |
return gr.update(value=create_progress_html(100, f"✅ PDF Uploaded: {os.path.basename(file.name)}", "success"), visible=True), get_debug_info(session_id), True
|
| 165 |
except Exception as e:
|
| 166 |
return gr.update(value=create_progress_html(0, f"❌ Error: {str(e)}", "error"), visible=True), get_debug_info(session_id), False
|
|
@@ -172,7 +171,6 @@ def clear_pdf(session_id):
|
|
| 172 |
shutil.rmtree(user_base)
|
| 173 |
|
| 174 |
disable_btn = gr.update(interactive=False)
|
| 175 |
-
# 清除时隐藏全部进度条
|
| 176 |
return gr.update(visible=False), gr.update(visible=False), get_debug_info(session_id), False, disable_btn, disable_btn, disable_btn, disable_btn
|
| 177 |
except Exception as e:
|
| 178 |
return gr.update(value=create_progress_html(0, f"❌ Clear Error: {str(e)}", "error"), visible=True), gr.update(), get_debug_info(session_id), False, gr.update(), gr.update(), gr.update(), gr.update()
|
|
@@ -216,6 +214,10 @@ def run_mineru_parsing_and_dag_gen(session_id, api_key, api_base_url, progress=g
|
|
| 216 |
progress(0.3, desc="Mineru 正在解析 PDF...")
|
| 217 |
for line in iter(process_mineru.stdout.readline, ''):
|
| 218 |
full_log += line
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
yield gr.update(value=create_progress_html(30, "⏳ Mineru parsing PDF...", "active"), visible=True), get_debug_info(session_id), full_log, no_change, no_change, no_change, no_change
|
| 220 |
process_mineru.stdout.close()
|
| 221 |
returncode_mineru = process_mineru.wait()
|
|
@@ -240,6 +242,10 @@ def run_mineru_parsing_and_dag_gen(session_id, api_key, api_base_url, progress=g
|
|
| 240 |
progress(0.8, desc="构建图结构中...")
|
| 241 |
for line in iter(process_dag.stdout.readline, ''):
|
| 242 |
full_log += line
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
yield gr.update(value=create_progress_html(80, "⏳ Building DAG...", "active"), visible=True), get_debug_info(session_id), full_log, no_change, no_change, no_change, no_change
|
| 244 |
process_dag.stdout.close()
|
| 245 |
returncode_dag = process_dag.wait()
|
|
@@ -255,6 +261,7 @@ def run_mineru_parsing_and_dag_gen(session_id, api_key, api_base_url, progress=g
|
|
| 255 |
except Exception as e:
|
| 256 |
progress(1.0, desc="发生异常")
|
| 257 |
error_log = full_log + f"\n[Global Exception]:\n{str(e)}"
|
|
|
|
| 258 |
yield gr.update(value=create_progress_html(0, "❌ Execution Exception", "error"), visible=True), get_debug_info(session_id), error_log, disable_btn, disable_btn, disable_btn, disable_btn
|
| 259 |
|
| 260 |
def run_final_generation(task_type, session_id, api_key, api_base_url, progress=gr.Progress()):
|
|
@@ -271,6 +278,8 @@ def run_final_generation(task_type, session_id, api_key, api_base_url, progress=
|
|
| 271 |
elif task_type == "all": scripts_to_run = ["gen_ppt.py", "gen_poster.py", "gen_pr.py"]
|
| 272 |
|
| 273 |
full_log = f"🚀 Starting {len(scripts_to_run)} tasks for session {session_id[:8]}...\n"
|
|
|
|
|
|
|
| 274 |
progress(0.1, desc=f"启动 {task_type.upper()} 生成任务...")
|
| 275 |
yield gr.update(value=create_progress_html(10, f"⏳ Starting {task_type.upper()}...", "active"), visible=True), get_debug_info(session_id), full_log, gr.update(visible=False)
|
| 276 |
|
|
@@ -300,6 +309,10 @@ def run_final_generation(task_type, session_id, api_key, api_base_url, progress=
|
|
| 300 |
try:
|
| 301 |
script_name, line = q.get(timeout=0.1)
|
| 302 |
full_log += f"[{script_name}] {line}"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
yield gr.update(value=create_progress_html(50, f"⏳ Generating {task_type.upper()}...", "active"), visible=True), get_debug_info(session_id), full_log, gr.update(visible=False)
|
| 304 |
except queue.Empty:
|
| 305 |
active_processes = sum(1 for _, p in processes if p.poll() is None)
|
|
@@ -325,6 +338,7 @@ def run_final_generation(task_type, session_id, api_key, api_base_url, progress=
|
|
| 325 |
except Exception as e:
|
| 326 |
progress(1.0, desc="发生全局异常")
|
| 327 |
error_log = full_log + f"\n[Global Exception]:\n{str(e)}"
|
|
|
|
| 328 |
yield gr.update(value=create_progress_html(0, "❌ Global exception", "error"), visible=True), get_debug_info(session_id), error_log, gr.update(visible=False)
|
| 329 |
|
| 330 |
# ==========================================
|
|
@@ -667,4 +681,5 @@ with gr.Blocks(theme=purple_theme, css=custom_css) as demo:
|
|
| 667 |
)
|
| 668 |
|
| 669 |
if __name__ == "__main__":
|
|
|
|
| 670 |
demo.queue(default_concurrency_limit=20).launch()
|
|
|
|
| 160 |
|
| 161 |
file_path = os.path.join(papers_dir, os.path.basename(file.name))
|
| 162 |
shutil.copy(file.name, file_path)
|
|
|
|
| 163 |
return gr.update(value=create_progress_html(100, f"✅ PDF Uploaded: {os.path.basename(file.name)}", "success"), visible=True), get_debug_info(session_id), True
|
| 164 |
except Exception as e:
|
| 165 |
return gr.update(value=create_progress_html(0, f"❌ Error: {str(e)}", "error"), visible=True), get_debug_info(session_id), False
|
|
|
|
| 171 |
shutil.rmtree(user_base)
|
| 172 |
|
| 173 |
disable_btn = gr.update(interactive=False)
|
|
|
|
| 174 |
return gr.update(visible=False), gr.update(visible=False), get_debug_info(session_id), False, disable_btn, disable_btn, disable_btn, disable_btn
|
| 175 |
except Exception as e:
|
| 176 |
return gr.update(value=create_progress_html(0, f"❌ Clear Error: {str(e)}", "error"), visible=True), gr.update(), get_debug_info(session_id), False, gr.update(), gr.update(), gr.update(), gr.update()
|
|
|
|
| 214 |
progress(0.3, desc="Mineru 正在解析 PDF...")
|
| 215 |
for line in iter(process_mineru.stdout.readline, ''):
|
| 216 |
full_log += line
|
| 217 |
+
# ==========================================
|
| 218 |
+
# 🔔 双端输出 1:Mineru 阶段
|
| 219 |
+
# ==========================================
|
| 220 |
+
print(f"[Mineru | {session_id[:6]}] {line}", end="", flush=True)
|
| 221 |
yield gr.update(value=create_progress_html(30, "⏳ Mineru parsing PDF...", "active"), visible=True), get_debug_info(session_id), full_log, no_change, no_change, no_change, no_change
|
| 222 |
process_mineru.stdout.close()
|
| 223 |
returncode_mineru = process_mineru.wait()
|
|
|
|
| 242 |
progress(0.8, desc="构建图结构中...")
|
| 243 |
for line in iter(process_dag.stdout.readline, ''):
|
| 244 |
full_log += line
|
| 245 |
+
# ==========================================
|
| 246 |
+
# 🔔 双端输出 2:DAG 生成阶段
|
| 247 |
+
# ==========================================
|
| 248 |
+
print(f"[DAG | {session_id[:6]}] {line}", end="", flush=True)
|
| 249 |
yield gr.update(value=create_progress_html(80, "⏳ Building DAG...", "active"), visible=True), get_debug_info(session_id), full_log, no_change, no_change, no_change, no_change
|
| 250 |
process_dag.stdout.close()
|
| 251 |
returncode_dag = process_dag.wait()
|
|
|
|
| 261 |
except Exception as e:
|
| 262 |
progress(1.0, desc="发生异常")
|
| 263 |
error_log = full_log + f"\n[Global Exception]:\n{str(e)}"
|
| 264 |
+
print(f"[Exception | {session_id[:6]}] {str(e)}", flush=True)
|
| 265 |
yield gr.update(value=create_progress_html(0, "❌ Execution Exception", "error"), visible=True), get_debug_info(session_id), error_log, disable_btn, disable_btn, disable_btn, disable_btn
|
| 266 |
|
| 267 |
def run_final_generation(task_type, session_id, api_key, api_base_url, progress=gr.Progress()):
|
|
|
|
| 278 |
elif task_type == "all": scripts_to_run = ["gen_ppt.py", "gen_poster.py", "gen_pr.py"]
|
| 279 |
|
| 280 |
full_log = f"🚀 Starting {len(scripts_to_run)} tasks for session {session_id[:8]}...\n"
|
| 281 |
+
print(f"[GEN Start | {session_id[:6]}] Starting {task_type.upper()}", flush=True)
|
| 282 |
+
|
| 283 |
progress(0.1, desc=f"启动 {task_type.upper()} 生成任务...")
|
| 284 |
yield gr.update(value=create_progress_html(10, f"⏳ Starting {task_type.upper()}...", "active"), visible=True), get_debug_info(session_id), full_log, gr.update(visible=False)
|
| 285 |
|
|
|
|
| 309 |
try:
|
| 310 |
script_name, line = q.get(timeout=0.1)
|
| 311 |
full_log += f"[{script_name}] {line}"
|
| 312 |
+
# ==========================================
|
| 313 |
+
# 🔔 双端输出 3:生成阶段
|
| 314 |
+
# ==========================================
|
| 315 |
+
print(f"[{script_name.upper()} | {session_id[:6]}] {line}", end="", flush=True)
|
| 316 |
yield gr.update(value=create_progress_html(50, f"⏳ Generating {task_type.upper()}...", "active"), visible=True), get_debug_info(session_id), full_log, gr.update(visible=False)
|
| 317 |
except queue.Empty:
|
| 318 |
active_processes = sum(1 for _, p in processes if p.poll() is None)
|
|
|
|
| 338 |
except Exception as e:
|
| 339 |
progress(1.0, desc="发生全局异常")
|
| 340 |
error_log = full_log + f"\n[Global Exception]:\n{str(e)}"
|
| 341 |
+
print(f"[Exception | {session_id[:6]}] {str(e)}", flush=True)
|
| 342 |
yield gr.update(value=create_progress_html(0, "❌ Global exception", "error"), visible=True), get_debug_info(session_id), error_log, gr.update(visible=False)
|
| 343 |
|
| 344 |
# ==========================================
|
|
|
|
| 681 |
)
|
| 682 |
|
| 683 |
if __name__ == "__main__":
|
| 684 |
+
# 并发放宽至 20
|
| 685 |
demo.queue(default_concurrency_limit=20).launch()
|