raannakasturi commited on
Commit
6ad097c
·
1 Parent(s): adbfd57

Update .gitignore and enhance HTML generation in post_blog.py for improved file handling and formatting

Browse files
Files changed (4) hide show
  1. .gitignore +3 -1
  2. main.py +3 -3
  3. post_blog.py +7 -11
  4. summarize_paper.py +3 -2
.gitignore CHANGED
@@ -3,4 +3,6 @@
3
  *.json
4
  /BLOGGER
5
  .html
6
- .js
 
 
 
3
  *.json
4
  /BLOGGER
5
  .html
6
+ .js
7
+ test*
8
+ *.html
main.py CHANGED
@@ -84,9 +84,9 @@ def test(uaccess_key):
84
  }
85
  },
86
  }
87
- status = paper_data(json.dumps(data))
88
- print(status)
89
  return status
90
 
91
  if __name__ == '__main__':
92
- test(access_key)
 
 
84
  }
85
  },
86
  }
87
+ status = paper_data(json.dumps(data, ensure_ascii=False, indent=4))
 
88
  return status
89
 
90
  if __name__ == '__main__':
91
+ data = test(access_key)
92
+ print(data)
post_blog.py CHANGED
@@ -17,12 +17,9 @@ imgbb_api_key = os.getenv('IMGBB_API_KEY')
17
 
18
  def generate_post_html(doi, title, category, summary, mindmap, citation):
19
  doi = doi.split("https://")[-1]
20
- title = title.replace("{", r'{').replace("}", r'}')
21
- title = re.sub(r"\\(?![a-zA-Z])", r"", title)
22
  summary = summary.replace("{", r'{').replace("}", r'}')
23
  mindmap = mindmap.replace("{", r'{').replace("}", r'}')
24
- citation = citation.replace("{", r'{').replace("}", r'}')
25
- citation = mistune.html(citation.replace("&", "&").strip())
26
  image = fetch_image(title, summary, imgbb_api_key)
27
  html_summary = mistune.html(summary)
28
  post = f"""
@@ -47,7 +44,7 @@ def generate_post_html(doi, title, category, summary, mindmap, citation):
47
  <br>
48
  <h2>Citation</h2>
49
  <div id="paper_citation">
50
- {mistune.html(citation.replace("&amp;", "&").strip())}
51
  </div>
52
  <script>
53
  const paperImage = document.querySelector(
@@ -122,16 +119,15 @@ def create_post(doi, title, category, summary, mindmap, citation):
122
  post_category = f"{category}"
123
  try:
124
  post_body, post_image = generate_post_html(doi, title, category, summary, mindmap, citation)
125
- # with open('post.html', 'w') as f:
126
- # f.write(post_body)
127
- # exit(code=0)
128
  except Exception as e:
129
  print(f"Error generating post: {e}")
130
  return None, None, None, None
131
  return post_title, post_category, post_body, post_image
132
 
133
  def post_post(title, category, body, image):
134
- title = re.sub(r"\\(?![a-zA-Z])", r"", title)
135
  response = None
136
  try:
137
  data = requests.post(
@@ -156,7 +152,7 @@ def post_post(title, category, body, image):
156
  "images": [{
157
  "url": image
158
  }],
159
- "title": title,
160
  "content": body,
161
  "labels": [category, "ZZZZZZZZZ"]
162
  }
@@ -174,7 +170,7 @@ def post_post(title, category, body, image):
174
  print(response)
175
  print(f"Error posting {title}: {e}")
176
  return False
177
-
178
  def post_blog(doi, title, category, summary, mindmap, citation, uaccess_key, wait_time=5):
179
  if uaccess_key != access_key:
180
  return False
 
17
 
18
  def generate_post_html(doi, title, category, summary, mindmap, citation):
19
  doi = doi.split("https://")[-1]
 
 
20
  summary = summary.replace("{", r'{').replace("}", r'}')
21
  mindmap = mindmap.replace("{", r'{').replace("}", r'}')
22
+ citation = mistune.html(repr(citation.replace("&amp;", "&").strip())[1:-1])
 
23
  image = fetch_image(title, summary, imgbb_api_key)
24
  html_summary = mistune.html(summary)
25
  post = f"""
 
44
  <br>
45
  <h2>Citation</h2>
46
  <div id="paper_citation">
47
+ {citation}
48
  </div>
49
  <script>
50
  const paperImage = document.querySelector(
 
119
  post_category = f"{category}"
120
  try:
121
  post_body, post_image = generate_post_html(doi, title, category, summary, mindmap, citation)
122
+ with open('post.html', 'w', encoding='utf-8') as f:
123
+ f.write(post_body)
124
+ exit(code=0)
125
  except Exception as e:
126
  print(f"Error generating post: {e}")
127
  return None, None, None, None
128
  return post_title, post_category, post_body, post_image
129
 
130
  def post_post(title, category, body, image):
 
131
  response = None
132
  try:
133
  data = requests.post(
 
152
  "images": [{
153
  "url": image
154
  }],
155
+ "title": r"{}".format(title),
156
  "content": body,
157
  "labels": [category, "ZZZZZZZZZ"]
158
  }
 
170
  print(response)
171
  print(f"Error posting {title}: {e}")
172
  return False
173
+
174
  def post_blog(doi, title, category, summary, mindmap, citation, uaccess_key, wait_time=5):
175
  if uaccess_key != access_key:
176
  return False
summarize_paper.py CHANGED
@@ -1,7 +1,7 @@
1
  import json
2
  from gradio_client import Client
3
 
4
- def summarize_paper(paper_title, pdf_url,paper_id, paper_citation, access_key):
5
  mindmap = None
6
  summary = None
7
  title = None
@@ -18,6 +18,7 @@ def summarize_paper(paper_title, pdf_url,paper_id, paper_citation, access_key):
18
  )
19
  if result:
20
  data = json.loads(result[0])
 
21
  if data['title']:
22
  title = data['title']
23
  if data['citation']:
@@ -28,4 +29,4 @@ def summarize_paper(paper_title, pdf_url,paper_id, paper_citation, access_key):
28
  summary = data["summary"]
29
  except Exception as e:
30
  print(f"Error summarizing paper: {e}")
31
- return title, summary, mindmap, citation
 
1
  import json
2
  from gradio_client import Client
3
 
4
+ def summarize_paper(paper_title, pdf_url, paper_id, paper_citation, access_key):
5
  mindmap = None
6
  summary = None
7
  title = None
 
18
  )
19
  if result:
20
  data = json.loads(result[0])
21
+ print
22
  if data['title']:
23
  title = data['title']
24
  if data['citation']:
 
29
  summary = data["summary"]
30
  except Exception as e:
31
  print(f"Error summarizing paper: {e}")
32
+ return title, summary, mindmap, citation