ReXploreBackend / summarize_paper.py
raannakasturi's picture
Refactor paper_data and summarize_paper functions for improved parameter handling and clarity
adbfd57
raw
history blame
1.06 kB
import json
from gradio_client import Client
def summarize_paper(paper_title, pdf_url,paper_id, paper_citation, access_key):
mindmap = None
summary = None
title = None
citation = None
try:
summarizer_client = Client("raannakasturi/ReXploreAPI")
result = summarizer_client.predict(
url=pdf_url,
title=paper_title,
id=paper_id,
citation=paper_citation,
access_key=access_key,
api_name="/rexplore_summarizer"
)
if result:
data = json.loads(result[0])
if data['title']:
title = data['title']
if data['citation']:
citation = data['citation']
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 title, summary, mindmap, citation