ScientryAPI / main.py
raannakasturi's picture
Retrieve access key from environment variables and update citation format in main.py
8184b96
raw
history blame
2.65 kB
from extract_text import extract_text_from_pdf
from math_summarizer import generate_math_summary
from nlp_processes import generate_nlp_summary_and_mindmap
import json
import dotenv
import time
import os
dotenv.load_dotenv()
ACCESS_KEY = os.getenv("ACCESS_KEY")
def generate_summary_mindmap(corpus, title, citation):
response = {}
math_summary = generate_math_summary(corpus)
# print(f'As a text script expert, please help me to write a short text script with the topic \" {math_summary}\".You have three tasks, which are:\\n 1.to summarize the text I provided into a Summary .Please answer within 150-300 characters.\\n 2.to summarize the text I provided, using up to seven Highlight.\\n 3.to summarize the text I provided, using up to seven Key Insights. Each insight should include a brief in-depth analysis. Key Insight should not include timestamps.\\n Your output should use the following template strictly, provide the results for the three tasks:\\n ## Summary\\n ## Highlights\\n - Highlights\\n ## Key Insights\\n - Key Insights .\\n Importantly your output must use language \"English\"')
# exit()
if not math_summary:
print("Error generating Math Summary")
response["summary_status"] = "error"
response["summary"] = None
response["mindmap_status"] = "error"
response["mindmap"] = None
return response
else:
response = generate_nlp_summary_and_mindmap(math_summary, title, citation)
return response
def main(url, title, id, citation, access_key):
if access_key != ACCESS_KEY:
return {"error": "Invalid Access Key", "summary": None, "mindmap": None}
else:
corpus = extract_text_from_pdf(url, id)
start_time = time.time()
response = generate_summary_mindmap(corpus, title, citation)
print(f"Total timetaken: {time.time() - start_time} seconds")
return json.dumps(response, indent=4, ensure_ascii=False)
if __name__ == "__main__":
url = "https://arxiv.org/pdf/2412.21024"
id = "123"
title = "Trading linearity for ellipticity: a nonsmooth approach to Einstein’s theory of gravity and the Lorentzian splitting theorems"
access_key = os.environ.get("ACCESS_KEY")
citation = "Bykov, D., Krivorol, V., & Kuzovchikov, A. (2024). Oscillator Calculus on Coadjoint Orbits and Index Theorems (Version 1). arXiv. https://doi.org/10.48550/ARXIV.2412.21024"
data = main(url, title, id, citation, access_key)
print((data))
with open("output.json", "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=4)