aquibmoin commited on
Commit
87b29c9
1 Parent(s): 219ff73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -28
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(prompt):
68
  try:
69
- # Step 1: Extract keywords using GPT (or another keyword extraction method)
70
- keywords = extract_keywords_with_gpt(prompt) # Assuming you have this function
71
 
72
- # Step 2: Refine the query using the extracted keywords
73
- simplified_query = keywords # Or use the full prompt if no keyword extraction is done
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", "N/A", "N/A", "N/A")]
80
-
81
- # Step 4: Extract references with title, authors, bibcode, DOI, journal, and publication date
82
- references = []
83
- for paper in papers[:5]: # Limit to 5 references
84
- title = paper['title'][0]
85
- authors = ", ".join(paper['author'][:3]) + (" et al." if len(paper['author']) > 3 else "")
86
- bibcode = paper['bibcode']
87
-
88
- # Fetch DOI if available
89
- doi = paper.get('doi', ['N/A'])[0]
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", "N/A", "N/A", "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}, {journal}, published on {pubdate} (Bibcode: {bibcode}) [DOI: {doi_link}]" for title, authors, journal, pubdate, bibcode, doi_link in references]
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