Spaces:
Running
Running
Refactor summarization and email sending logic; improve error handling and environment variable checks
f50b29d
| import os | |
| import json | |
| from gradio_client import Client | |
| import dotenv | |
| dotenv.load_dotenv() | |
| def summarize_paper(pdf_url: str, paper_id: str, access_key: str): | |
| summary = None | |
| mindmap = None | |
| try: | |
| hf_api_token = os.getenv("HF_API_TOKEN") | |
| if not hf_api_token: | |
| raise ValueError("HF_API_TOKEN not found in environment variables.") | |
| summarizer_client = Client("raannakasturi/ReXploreAPI", hf_token=hf_api_token) | |
| result = summarizer_client.predict( | |
| url=pdf_url, | |
| id=paper_id, | |
| access_key=access_key, | |
| api_name="/rexplore_summarizer" | |
| ) | |
| if result: | |
| data = json.loads(result[0]) | |
| if data.get("mindmap_status") == "success": | |
| mindmap = data.get("mindmap") | |
| if data.get("summary_status") == "success": | |
| summary = data.get("summary") | |
| except Exception as e: | |
| print(f"Error summarizing paper: {e}") | |
| return summary, mindmap | |
| if __name__ == "__main__": | |
| test_pdf_url = "https://example.com/paper.pdf" | |
| test_paper_id = "12345" | |
| test_access_key = "your_access_key_here" | |
| paper_summary, paper_mindmap = summarize_paper(test_pdf_url, test_paper_id, test_access_key) | |
| print("Summary:", paper_summary) | |
| print("Mindmap:", paper_mindmap) | |