Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -1,53 +1,52 @@
|
|
1 |
-
import json
|
2 |
-
import os
|
3 |
-
import dotenv
|
4 |
-
from summarize_paper import summarize_paper
|
5 |
-
from fetch_data import fetch_paper_data_with_category
|
6 |
-
from post_blog import post_blog
|
7 |
-
|
8 |
-
# Load environment variables
|
9 |
-
dotenv.load_dotenv()
|
10 |
-
summarizer_api_key = os.getenv("SUMMARIZER_API_KEY")
|
11 |
-
mail_api = os.getenv("MAIL_API")
|
12 |
-
access_key = os.getenv("ACCESS_KEY")
|
13 |
-
|
14 |
-
def paper_data(paper_data):
|
15 |
-
data = {"status": "success"}
|
16 |
-
data['data'] = {}
|
17 |
-
paper_data = json.loads(paper_data)
|
18 |
-
for category, papers in paper_data.items():
|
19 |
-
print(f"Processing category: {category}")
|
20 |
-
data['data'][category] = {}
|
21 |
-
for paper_id, details in papers.items():
|
22 |
-
doi = details.get("doi")
|
23 |
-
pdf_url = details.get("pdf_url")
|
24 |
-
title = details.get("title")
|
25 |
-
citation = details.get("citation")
|
26 |
-
if not all([paper_id, doi, pdf_url, title, citation]):
|
27 |
-
print(f"Skipping paper with ID: {paper_id} (missing details)")
|
28 |
-
continue
|
29 |
-
summary, mindmap = summarize_paper(pdf_url, paper_id, summarizer_api_key)
|
30 |
-
post_blog(title, category, summary, mindmap, citation, access_key)
|
31 |
-
data['data'][category][paper_id] = {
|
32 |
-
"id": paper_id,
|
33 |
-
"doi": doi,
|
34 |
-
"title": title,
|
35 |
-
"category": category,
|
36 |
-
"citation": citation,
|
37 |
-
"summary": summary,
|
38 |
-
"mindmap": mindmap,
|
39 |
-
}
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
pdata = paper_data(data)
|
53 |
return pdata
|
|
|
1 |
+
import json
|
2 |
+
import os
|
3 |
+
import dotenv
|
4 |
+
from summarize_paper import summarize_paper
|
5 |
+
from fetch_data import fetch_paper_data_with_category
|
6 |
+
from post_blog import post_blog
|
7 |
+
|
8 |
+
# Load environment variables
|
9 |
+
dotenv.load_dotenv()
|
10 |
+
summarizer_api_key = os.getenv("SUMMARIZER_API_KEY")
|
11 |
+
mail_api = os.getenv("MAIL_API")
|
12 |
+
access_key = os.getenv("ACCESS_KEY")
|
13 |
+
|
14 |
+
def paper_data(paper_data):
|
15 |
+
data = {"status": "success"}
|
16 |
+
data['data'] = {}
|
17 |
+
paper_data = json.loads(paper_data)
|
18 |
+
for category, papers in paper_data.items():
|
19 |
+
print(f"Processing category: {category}")
|
20 |
+
data['data'][category] = {}
|
21 |
+
for paper_id, details in papers.items():
|
22 |
+
doi = details.get("doi")
|
23 |
+
pdf_url = details.get("pdf_url")
|
24 |
+
title = details.get("title")
|
25 |
+
citation = details.get("citation")
|
26 |
+
if not all([paper_id, doi, pdf_url, title, citation]):
|
27 |
+
print(f"Skipping paper with ID: {paper_id} (missing details)")
|
28 |
+
continue
|
29 |
+
summary, mindmap = summarize_paper(pdf_url, paper_id, summarizer_api_key)
|
30 |
+
post_blog(title, category, summary, mindmap, citation, access_key)
|
31 |
+
data['data'][category][paper_id] = {
|
32 |
+
"id": paper_id,
|
33 |
+
"doi": doi,
|
34 |
+
"title": title,
|
35 |
+
"category": category,
|
36 |
+
"citation": citation,
|
37 |
+
"summary": summary,
|
38 |
+
"mindmap": mindmap,
|
39 |
+
}
|
40 |
+
output_file = "paper_data_with_summary.json"
|
41 |
+
data = json.dumps(data, indent=4, ensure_ascii=False)
|
42 |
+
with open(output_file, "w", encoding="utf-8") as file:
|
43 |
+
json.dump(data, file, indent=4)
|
44 |
+
print(f"Processed data saved to {output_file}")
|
45 |
+
return data
|
46 |
+
|
47 |
+
def post_blogpost(uaccess_key):
|
48 |
+
if uaccess_key != access_key:
|
49 |
+
return False
|
50 |
+
data = fetch_paper_data_with_category(uaccess_key)
|
51 |
+
pdata = paper_data(data)
|
|
|
52 |
return pdata
|