File size: 893 Bytes
98434dd
6b18f32
398744d
 
 
6b18f32
 
98434dd
398744d
 
 
98434dd
 
6b18f32
98434dd
398744d
adbfd57
 
 
 
398744d
 
 
6ad097c
398744d
 
 
 
 
 
98434dd
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
import os
import dotenv
import json
from gradio_client import Client

dotenv.load_dotenv()

def summarize_paper(pdf_url, paper_id, access_key):
    mindmap = None
    summary = None
    try:
        summarizer_client = Client(
            "raannakasturi/ReXploreAPI",
            hf_token=os.getenv("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])
            print
            if data["mindmap_status"] == "success":
                mindmap = data["mindmap"]
            if data["summary_status"] == "success":
                summary = data["summary"]
    except Exception as e:
        print(f"Error summarizing paper: {e}")
    return summary, mindmap