Spaces:
Running
Running
raannakasturi
commited on
Commit
·
adbfd57
1
Parent(s):
0485034
Refactor paper_data and summarize_paper functions for improved parameter handling and clarity
Browse files- app.py +1 -2
- main.py +22 -12
- post_blog.py +0 -39
- summarize_paper.py +7 -7
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
from main import post_blogpost
|
3 |
-
from post_blog import test
|
4 |
|
5 |
theme = gr.themes.Soft(
|
6 |
primary_hue="purple",
|
|
|
1 |
import gradio as gr
|
2 |
+
from main import post_blogpost, test
|
|
|
3 |
|
4 |
theme = gr.themes.Soft(
|
5 |
primary_hue="purple",
|
main.py
CHANGED
@@ -25,7 +25,7 @@ def paper_data(paper_data, wait_time=5):
|
|
25 |
if not all([paper_id, doi, pdf_url, title, citation]):
|
26 |
print(f"Skipping paper with ID: {paper_id} (missing details)")
|
27 |
continue
|
28 |
-
fixed_title, summary, mindmap, fixed_citation = summarize_paper(title, pdf_url, paper_id, access_key)
|
29 |
if not fixed_title:
|
30 |
title = title
|
31 |
else:
|
@@ -35,18 +35,11 @@ def paper_data(paper_data, wait_time=5):
|
|
35 |
else:
|
36 |
citation = fixed_citation
|
37 |
if not summary or not mindmap:
|
38 |
-
print(f"Skipping paper with ID: {paper_id} (
|
39 |
continue
|
40 |
try:
|
41 |
title = html.escape(str(title).strip())
|
42 |
-
|
43 |
-
try:
|
44 |
-
encoded_bytes = citation.encode('latin1').decode('utf-8', errors='replace')
|
45 |
-
except:
|
46 |
-
encoded_bytes = repr(citation).strip().encode('latin1').decode('utf-8', errors='replace')
|
47 |
-
except:
|
48 |
-
encoded_bytes = repr(citation).strip()
|
49 |
-
citation = html.unescape(encoded_bytes)
|
50 |
status = post_blog(doi, title, category, summary, mindmap, citation, access_key, wait_time)
|
51 |
except Exception as e:
|
52 |
print(f"Error posting blog '{title}': {e}")
|
@@ -78,5 +71,22 @@ def post_blogpost(uaccess_key, wait_time=5):
|
|
78 |
print("\n-------------------------------------------------------\nProcess Completed\n-------------------------------------------------------\n")
|
79 |
return pdata
|
80 |
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
if not all([paper_id, doi, pdf_url, title, citation]):
|
26 |
print(f"Skipping paper with ID: {paper_id} (missing details)")
|
27 |
continue
|
28 |
+
fixed_title, summary, mindmap, fixed_citation = summarize_paper(title, pdf_url, paper_id, citation, access_key)
|
29 |
if not fixed_title:
|
30 |
title = title
|
31 |
else:
|
|
|
35 |
else:
|
36 |
citation = fixed_citation
|
37 |
if not summary or not mindmap:
|
38 |
+
print(f"Skipping paper with ID: {paper_id} (Summary/Mindmap not found)")
|
39 |
continue
|
40 |
try:
|
41 |
title = html.escape(str(title).strip())
|
42 |
+
citation = html.escape(str(citation).strip())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
status = post_blog(doi, title, category, summary, mindmap, citation, access_key, wait_time)
|
44 |
except Exception as e:
|
45 |
print(f"Error posting blog '{title}': {e}")
|
|
|
71 |
print("\n-------------------------------------------------------\nProcess Completed\n-------------------------------------------------------\n")
|
72 |
return pdata
|
73 |
|
74 |
+
def test(uaccess_key):
|
75 |
+
if uaccess_key != access_key:
|
76 |
+
return False
|
77 |
+
data = {
|
78 |
+
"Astrophysics": {
|
79 |
+
"2412.20276": {
|
80 |
+
"doi": "https://doi.org/10.48550/arXiv.2412.20276",
|
81 |
+
"title": "Demographics of black holes at $<$100 R$_{\\rm g}$ scales: accretion flows, jets, and shadows. From Painlev\xe9 equations to ${\cal N}=2$ susy gauge theories: prolegomena TDI-$\\infty$",
|
82 |
+
"pdf_url": "http://ftp.ncbi.nlm.nih.gov/pub/pmc/oa_pdf/97/ea/41598_2024_Article_78595.PMC11551141.pdf",
|
83 |
+
"citation": "Nair, D. G., Nagar, N. M., Ramakrishnan, V., Wielgus, M., Arratia, V., Krichbaum, T. P., Zhang, X. A., Ricarte, A., S., S., Hernández-Yévenes, J., Ford, N. M., Bandyopadhyay, B., Gurwell, M., Burridge, R., Pesce, D. W., Doeleman, S. S., Kim, J.-Y., Kim, D., Janssen, M., ⦠Zensus, J. A. (2024). Demographics of black holes at $<$100 R$_{\\rm g}$ scales: accretion flows, jets, and shadows (Version 1). arXiv. https://doi.org/10.48550/ARXIV.2412.20276"
|
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)
|
post_blog.py
CHANGED
@@ -197,42 +197,3 @@ def post_blog(doi, title, category, summary, mindmap, citation, uaccess_key, wai
|
|
197 |
print('Failed to create post')
|
198 |
return False
|
199 |
|
200 |
-
def test(uaccess_key):
|
201 |
-
data = {
|
202 |
-
"status": "success",
|
203 |
-
"Astrophysics": {
|
204 |
-
"2412.16344": {
|
205 |
-
"id": "2412.20276",
|
206 |
-
"doi": "https://doi.org/10.48550/arXiv.2412.20276",
|
207 |
-
"title": "From Painlev\xe9 equations to ${\cal N}=2$ susy gauge theories: prolegomena TDI-$\\infty$",
|
208 |
-
"category": "Astrophysics",
|
209 |
-
"citation": "Nair, D. G., Nagar, N. M., Ramakrishnan, V., Wielgus, M., Arratia, V., Krichbaum, T. P., Zhang, X. A., Ricarte, A., S., S., Hernández-Yévenes, J., Ford, N. M., Bandyopadhyay, B., Gurwell, M., Burridge, R., Pesce, D. W., Doeleman, S. S., Kim, J.-Y., Kim, D., Janssen, M., ⦠Zensus, J. A. (2024). Demographics of black holes at $<$100 R$_{\\rm g}$ scales: accretion flows, jets, and shadows (Version 1). arXiv. https://doi.org/10.48550/ARXIV.2412.20276",
|
210 |
-
"summary": "## Summary\nThe Event Horizon Telescope (EHT) has imaged supermassive black holes (SMBHs) in M87 and Sgr A*, testing General Relativity and constraining black hole mass. The EHT has also imaged inner jets of several SMBHs, but at coarser resolutions than 100 Rg. The \"Event Horizon and Environs\" (ETHER) sample is a comprehensive database of SMBH mass estimates, radio to hard X-ray flux densities, and spectral energy distribution information.\n\n## Highlights\n- The EHT has imaged SMBH shadows in M87 and Sgr A*, testing General Relativity and constraining black hole mass.\n- The EHT has imaged the inner jets of several SMBHs, but at coarser resolutions than 100 Rg.\n- The ETHER sample is a comprehensive database of SMBH mass estimates, radio to hard X-ray flux densities, and spectral energy distribution information.\n- The ETHER database includes predictions for the 230 GHz and 345 GHz flux densities in the EHT field of view for approximately 40,000 SMBHs.\n- The 43 GHz VLBA is the highest frequency sensitive phase-referenced VLBI network, providing valuable constraints for SED modeling.\n- The ngEHT is expected to measure approximately 50 SMBH masses, 30 SMBH spins, and 7 SMBH shadows.\n- The ngEHT will enable demographic studies of SMBHs, testing General Relativity and constraining black hole mass.\n\n## Key Insights\n- The EHT's ability to image SMBH shadows and inner jets has opened a new window into understanding these enigmatic objects, allowing for tests of General Relativity and constraints on black hole mass.\n- The ETHER sample provides a comprehensive database for identifying and optimizing target selection for the EHT and its upgrades, enabling the identification of a \"Gold Sample\" of nearby low-luminosity Active Galactic Nuclei (AGNs) optimal for studying jet bases and potentially imaging black hole shadows.\n- The ngEHT will enable the measurement of approximately 50 SMBH masses, 30 SMBH spins, and 7 SMBH shadows, providing a significant increase in the number of SMBHs that can be studied in detail.\n- The 43 GHz VLBA provides valuable constraints for SED modeling, allowing for the prediction of EHT flux densities and the identification of optimal targets for EHT observations.\n- The ETHER database includes predictions for the 230 GHz and 345 GHz flux densities in the EHT field of view for approximately 40,000 SMBHs, enabling the identification of potential targets for EHT observations.\n- The ngEHT will enable demographic studies of SMBHs, testing General Relativity and constraining black hole mass, and providing insights into the properties of these enigmatic objects.\n- The EHT's ability to image SMBH shadows and inner jets has significant implications for our understanding of these objects and the role they play in the universe, and will continue to be an important area of research in the coming years.",
|
211 |
-
"mindmap": "## Introduction\n- Event Horizon Telescope (EHT) project introduced\n- Studies black holes with high angular resolution\n- Provides insights into black hole physics\n\n## Black Hole Demographics\n- ETHER database for black hole demographics\n- Contains 3.15 million SMBH mass estimates\n- 20,000 VLBI radio flux densities included\n\n## EHT and ngEHT Capabilities\n- EHT resolves SMBH shadows at 10 Rg scale\n- ngEHT expected to improve imaging capabilities\n- Will study SMBHs with higher angular resolution\n\n## Observational Programs\n- 43 GHz VLBA imaging of ETHER targets\n- 230 GHz EHT+ALMA observations planned\n- GMVA+ALMA observations for deep imaging\n\n## Scientific Goals\n- Study jet launching and accretion flows\n- Investigate black hole physics and GR\n- Measure SMBH masses and spins\n\n## Future Prospects\n- ngEHT will improve imaging capabilities\n- Will enable study of more SMBHs\n- Provide insights into black hole physics\n\n## Collaboration and Funding\n- EHT collaboration for research and development\n- Funding agencies supporting the project\n- International collaboration for astronomy research\n\n## Research and Development\n- Developing new imaging techniques\n- Improving telescope sensitivity and resolution\n- Enhancing data analysis and modeling capabilities\n\n## Challenges and Limitations\n- Overcoming technical challenges and limitations\n- Addressing observational and theoretical uncertainties\n- Improving data quality and interpretation\n\n## Conclusion\n- EHT and ngEHT for black hole research\n- Studying SMBH demographics and physics\n- Advancing our understanding of the universe"
|
212 |
-
}
|
213 |
-
}
|
214 |
-
}
|
215 |
-
if data['status'] != 'success':
|
216 |
-
print('Failed to fetch data')
|
217 |
-
else:
|
218 |
-
for category, catdata in data.items():
|
219 |
-
if category != 'status':
|
220 |
-
for paper_id, paperdata in catdata.items():
|
221 |
-
title = paperdata['title']
|
222 |
-
category = paperdata['category']
|
223 |
-
summary = paperdata.get('summary', '')
|
224 |
-
mindmap = paperdata.get('mindmap', '')
|
225 |
-
citation = paperdata.get('citation', '')
|
226 |
-
uaccess_key = access_key
|
227 |
-
title = html.escape(str(title).strip()[1:-1])
|
228 |
-
try:
|
229 |
-
encoded_bytes = citation.encode('latin1').decode('utf-8', errors='replace')
|
230 |
-
except:
|
231 |
-
encoded_bytes = repr(citation)
|
232 |
-
citation = html.unescape(encoded_bytes)
|
233 |
-
status = post_blog("2412.20276", title, category, summary, mindmap, citation, uaccess_key, 0)
|
234 |
-
print(status)
|
235 |
-
return status
|
236 |
-
|
237 |
-
if __name__ == '__main__':
|
238 |
-
test(access_key)
|
|
|
197 |
print('Failed to create post')
|
198 |
return False
|
199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
summarize_paper.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import json
|
2 |
from gradio_client import Client
|
3 |
|
4 |
-
def summarize_paper(
|
5 |
mindmap = None
|
6 |
summary = None
|
7 |
title = None
|
@@ -9,12 +9,12 @@ def summarize_paper(pdf_url, paper_title, paper_id, paper_citation, access_key):
|
|
9 |
try:
|
10 |
summarizer_client = Client("raannakasturi/ReXploreAPI")
|
11 |
result = summarizer_client.predict(
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
)
|
19 |
if result:
|
20 |
data = json.loads(result[0])
|
|
|
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
|
|
|
9 |
try:
|
10 |
summarizer_client = Client("raannakasturi/ReXploreAPI")
|
11 |
result = summarizer_client.predict(
|
12 |
+
url=pdf_url,
|
13 |
+
title=paper_title,
|
14 |
+
id=paper_id,
|
15 |
+
citation=paper_citation,
|
16 |
+
access_key=access_key,
|
17 |
+
api_name="/rexplore_summarizer"
|
18 |
)
|
19 |
if result:
|
20 |
data = json.loads(result[0])
|