MCPcopy Create free account
hub / github.com/HKUDS/Paper2Slides / get_result

Function get_result

api/server.py:647–726  ·  view source on GitHub ↗

Get the final result for a completed session

(session_id: str)

Source from the content-addressed store, hash-verified

645
646@app.get("/api/result/{session_id}")
647async def get_result(session_id: str):
648 """Get the final result for a completed session"""
649 try:
650 # Check if result is in cache
651 if hasattr(app.state, 'results') and session_id in app.state.results:
652 result = app.state.results[session_id]
653
654 if "error" in result:
655 raise HTTPException(status_code=500, detail=result["error"])
656
657 # Prepare response with output files
658 output_files = result.get("output_files", [])
659
660 # Find PDF file in output
661 pdf_file = next((f for f in output_files if f['filename'].endswith('.pdf')), None)
662 # Find image files
663 image_files = [f for f in output_files if f['filename'].endswith(('.png', '.jpg', '.jpeg', '.webp'))]
664
665 # Get output_type from state
666 session_dir = UPLOAD_DIR / session_id
667 pdf_files = list(session_dir.glob("*.pdf"))
668 if len(pdf_files) > 1:
669 project_name = f"session_{session_id[:8]}"
670 else:
671 project_name = get_project_name(str(pdf_files[0]))
672
673 # Try to get output type from state
674 from paper2slides.core.paths import get_base_dir
675 import json
676
677 output_type = "slides" # default
678 for content_type in ["paper", "general"]:
679 base_dir = Path(get_base_dir(str(OUTPUT_DIR), project_name, content_type))
680 if base_dir.exists():
681 for state_file_path in base_dir.rglob("state.json"):
682 if state_file_path.is_file():
683 try:
684 with open(state_file_path, 'r') as f:
685 state_data = json.load(f)
686 output_type = state_data.get("config", {}).get("output_type", "slides")
687 break
688 except:
689 pass
690 if output_type != "slides":
691 break
692
693 response_data = {
694 "session_id": session_id,
695 "slides": [
696 {
697 "title": f"Slide {i+1}",
698 "image_url": f"/outputs/{img['relative_path']}"
699 }
700 for i, img in enumerate(image_files)
701 ],
702 }
703
704 # Add download links

Callers

nothing calls this directly

Calls 2

get_project_nameFunction · 0.90
get_base_dirFunction · 0.90

Tested by

no test coverage detected