Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -64,42 +64,33 @@ def extract_keywords_with_gpt(user_input, max_tokens=100, temperature=0.3):
|
|
| 64 |
|
| 65 |
return extracted_keywords
|
| 66 |
|
| 67 |
-
def fetch_nasa_ads_references(
|
| 68 |
try:
|
| 69 |
-
# Step 1: Extract keywords using GPT (
|
| 70 |
-
keywords = extract_keywords_with_gpt(
|
| 71 |
|
| 72 |
-
# Step 2:
|
| 73 |
-
simplified_query = keywords #
|
| 74 |
|
| 75 |
# Step 3: Query NASA ADS for relevant papers
|
| 76 |
papers = ADS.query_simple(simplified_query)
|
| 77 |
|
| 78 |
if not papers or len(papers) == 0:
|
| 79 |
-
return [("No results found", "N/A", "N/A"
|
| 80 |
-
|
| 81 |
-
# Step 4: Extract
|
| 82 |
-
references = [
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
#
|
| 89 |
-
|
| 90 |
-
doi_link = f"https://doi.org/{doi}" if doi != "N/A" else "N/A"
|
| 91 |
-
|
| 92 |
-
# Fetch journal and publication date
|
| 93 |
-
journal = paper.get('pub', 'Unknown Journal')
|
| 94 |
-
pubdate = paper.get('pubdate', 'Unknown Date')
|
| 95 |
-
|
| 96 |
-
# Add the extracted info to the list of references
|
| 97 |
-
references.append((title, authors, journal, pubdate, bibcode, doi_link))
|
| 98 |
-
|
| 99 |
return references
|
| 100 |
-
|
| 101 |
except Exception as e:
|
| 102 |
-
return [("Error fetching references", str(e), "N/A"
|
| 103 |
|
| 104 |
def fetch_exoplanet_data():
|
| 105 |
# Connect to NASA Exoplanet Archive TAP Service
|
|
@@ -142,7 +133,7 @@ def generate_response(user_input, relevant_context="", references=[], max_tokens
|
|
| 142 |
if references:
|
| 143 |
response_content = response.choices[0].message.content.strip()
|
| 144 |
references_text = "\n\nADS References:\n" + "\n".join(
|
| 145 |
-
[f"- {title} by {authors}
|
| 146 |
)
|
| 147 |
return f"{response_content}\n{references_text}"
|
| 148 |
|
|
|
|
| 64 |
|
| 65 |
return extracted_keywords
|
| 66 |
|
| 67 |
+
def fetch_nasa_ads_references(user_input):
|
| 68 |
try:
|
| 69 |
+
# Step 1: Extract keywords using GPT (assuming you have this function)
|
| 70 |
+
keywords = extract_keywords_with_gpt(user_input)
|
| 71 |
|
| 72 |
+
# Step 2: Build a query using the extracted keywords
|
| 73 |
+
simplified_query = keywords # Use keywords as the query
|
| 74 |
|
| 75 |
# Step 3: Query NASA ADS for relevant papers
|
| 76 |
papers = ADS.query_simple(simplified_query)
|
| 77 |
|
| 78 |
if not papers or len(papers) == 0:
|
| 79 |
+
return [("No results found", "N/A", "N/A")]
|
| 80 |
+
|
| 81 |
+
# Step 4: Extract title, authors, and bibcode from the papers
|
| 82 |
+
references = [
|
| 83 |
+
(
|
| 84 |
+
paper['title'][0],
|
| 85 |
+
", ".join(paper['author'][:3]) + (" et al." if len(paper['author']) > 3 else ""),
|
| 86 |
+
paper['bibcode']
|
| 87 |
+
)
|
| 88 |
+
for paper in papers[:5] # Limit to 5 references
|
| 89 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
return references
|
| 91 |
+
|
| 92 |
except Exception as e:
|
| 93 |
+
return [("Error fetching references", str(e), "N/A")]
|
| 94 |
|
| 95 |
def fetch_exoplanet_data():
|
| 96 |
# Connect to NASA Exoplanet Archive TAP Service
|
|
|
|
| 133 |
if references:
|
| 134 |
response_content = response.choices[0].message.content.strip()
|
| 135 |
references_text = "\n\nADS References:\n" + "\n".join(
|
| 136 |
+
[f"- {title} by {authors} (Bibcode: {bibcode})" for title, authors, bibcode in references]
|
| 137 |
)
|
| 138 |
return f"{response_content}\n{references_text}"
|
| 139 |
|