Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ from docx import Document
|
|
8 |
import io
|
9 |
import tempfile
|
10 |
from astroquery.nasa_ads import ADS
|
|
|
11 |
|
12 |
# Load the NASA-specific bi-encoder model and tokenizer
|
13 |
bi_encoder_model_name = "nasa-impact/nasa-smd-ibm-st-v2"
|
@@ -62,6 +63,24 @@ def fetch_nasa_ads_references(prompt):
|
|
62 |
except Exception as e:
|
63 |
return [("Error fetching references", str(e), "N/A")]
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
def generate_response(user_input, relevant_context="", references=[], max_tokens=150, temperature=0.7, top_p=0.9, frequency_penalty=0.5, presence_penalty=0.0):
|
66 |
if relevant_context:
|
67 |
combined_input = f"Context: {relevant_context}\nQuestion: {user_input}\nAnswer (please organize the answer in a structured format with topics and subtopics):"
|
@@ -117,6 +136,9 @@ def chatbot(user_input, context="", use_encoder=False, max_tokens=150, temperatu
|
|
117 |
|
118 |
# Export the response to a Word document
|
119 |
word_doc_path = export_to_word(response)
|
|
|
|
|
|
|
120 |
|
121 |
# Embed Miro iframe
|
122 |
iframe_html = """
|
@@ -151,7 +173,7 @@ def chatbot(user_input, context="", use_encoder=False, max_tokens=150, temperatu
|
|
151 |
<button class="mapify-button">Create Mind Map on Mapify</button>
|
152 |
</a>
|
153 |
"""
|
154 |
-
return response, iframe_html, mapify_button_html, word_doc_path
|
155 |
|
156 |
iface = gr.Interface(
|
157 |
fn=chatbot,
|
@@ -170,8 +192,9 @@ iface = gr.Interface(
|
|
170 |
gr.HTML(label="Miro"),
|
171 |
gr.HTML(label="Generate Mind Map on Mapify"),
|
172 |
gr.File(label="Download SCDD", type="filepath"),
|
|
|
173 |
],
|
174 |
-
title="SCDDBot - NASA SMD SCDD AI Assistant [version-0.
|
175 |
description="SCDDBot is an AI-powered assistant for generating and visualising HWO Science Cases",
|
176 |
)
|
177 |
|
|
|
8 |
import io
|
9 |
import tempfile
|
10 |
from astroquery.nasa_ads import ADS
|
11 |
+
import pyvo as vo
|
12 |
|
13 |
# Load the NASA-specific bi-encoder model and tokenizer
|
14 |
bi_encoder_model_name = "nasa-impact/nasa-smd-ibm-st-v2"
|
|
|
63 |
except Exception as e:
|
64 |
return [("Error fetching references", str(e), "N/A")]
|
65 |
|
66 |
+
def fetch_exoplanet_data():
|
67 |
+
# Connect to NASA Exoplanet Archive TAP Service
|
68 |
+
tap_service = vo.dal.TAPService("https://exoplanetarchive.ipac.caltech.edu/TAP")
|
69 |
+
|
70 |
+
# Query to fetch all columns from the pscomppars table
|
71 |
+
ex_query = """
|
72 |
+
SELECT TOP 10 *
|
73 |
+
FROM pscomppars
|
74 |
+
"""
|
75 |
+
# Execute the query
|
76 |
+
qresult = tap_service.search(ex_query)
|
77 |
+
|
78 |
+
# Convert to a Pandas DataFrame
|
79 |
+
ptable = qresult.to_table()
|
80 |
+
exoplanet_data = ptable.to_pandas()
|
81 |
+
|
82 |
+
return exoplanet_data
|
83 |
+
|
84 |
def generate_response(user_input, relevant_context="", references=[], max_tokens=150, temperature=0.7, top_p=0.9, frequency_penalty=0.5, presence_penalty=0.0):
|
85 |
if relevant_context:
|
86 |
combined_input = f"Context: {relevant_context}\nQuestion: {user_input}\nAnswer (please organize the answer in a structured format with topics and subtopics):"
|
|
|
136 |
|
137 |
# Export the response to a Word document
|
138 |
word_doc_path = export_to_word(response)
|
139 |
+
|
140 |
+
# Fetch exoplanet data
|
141 |
+
exoplanet_data = fetch_exoplanet_data()
|
142 |
|
143 |
# Embed Miro iframe
|
144 |
iframe_html = """
|
|
|
173 |
<button class="mapify-button">Create Mind Map on Mapify</button>
|
174 |
</a>
|
175 |
"""
|
176 |
+
return response, iframe_html, mapify_button_html, word_doc_path, exoplanet_data
|
177 |
|
178 |
iface = gr.Interface(
|
179 |
fn=chatbot,
|
|
|
192 |
gr.HTML(label="Miro"),
|
193 |
gr.HTML(label="Generate Mind Map on Mapify"),
|
194 |
gr.File(label="Download SCDD", type="filepath"),
|
195 |
+
gr.Dataframe(label="Exoplanet Data Table")
|
196 |
],
|
197 |
+
title="SCDDBot - NASA SMD SCDD AI Assistant [version-0.4a]",
|
198 |
description="SCDDBot is an AI-powered assistant for generating and visualising HWO Science Cases",
|
199 |
)
|
200 |
|