Spaces:
Running
Running
File size: 1,326 Bytes
98434dd 398744d f50b29d 398744d 6b18f32 f50b29d 398744d f50b29d 398744d f50b29d 398744d f50b29d 398744d f50b29d 398744d f50b29d 98434dd f50b29d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
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)
|