aquibmoin commited on
Commit
ee80e0c
1 Parent(s): 317197e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -1
app.py CHANGED
@@ -110,6 +110,37 @@ def generate_response(user_input, relevant_context="", references=[], max_tokens
110
 
111
  return response.choices[0].message.content.strip()
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  def export_to_word(response_content):
114
  doc = Document()
115
  doc.add_heading('AI Generated SCDD', 0)
@@ -139,6 +170,12 @@ def chatbot(user_input, context="", use_encoder=False, max_tokens=150, temperatu
139
 
140
  # Fetch exoplanet data
141
  exoplanet_data = fetch_exoplanet_data()
 
 
 
 
 
 
142
 
143
  # Embed Miro iframe
144
  iframe_html = """
@@ -173,7 +210,7 @@ def chatbot(user_input, context="", use_encoder=False, max_tokens=150, temperatu
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,
 
110
 
111
  return response.choices[0].message.content.strip()
112
 
113
+ def generate_data_insights(user_input, exoplanet_data, max_tokens=250, temperature=0.3):
114
+ """
115
+ Generate insights by passing the user's input along with the exoplanet data to GPT-4.
116
+ """
117
+ # Convert the dataframe to a readable format for GPT (e.g., CSV-style text)
118
+ data_as_text = exoplanet_data.to_csv(index=False) # CSV-style for better readability
119
+
120
+ # Create a prompt with the user query and the data sample
121
+ insights_prompt = (
122
+ f"Analyze the following user query and provide relevant insights based on the provided exoplanet data.\n\n"
123
+ f"User Query: {user_input}\n\n"
124
+ f"Exoplanet Data:\n{data_as_text}\n\n"
125
+ f"Please provide insights that are relevant to the user's query."
126
+ )
127
+
128
+ # Call GPT-4 to generate insights based on the data and user input
129
+ response = client.chat.completions.create(
130
+ model="gpt-4",
131
+ messages=[
132
+ {"role": "system", "content": "You are an expert in analyzing astronomical data and generating insights."},
133
+ {"role": "user", "content": insights_prompt}
134
+ ],
135
+ max_tokens=max_tokens,
136
+ temperature=temperature
137
+ )
138
+
139
+ # Extract and return GPT-4's insights
140
+ data_insights = response.choices[0].message.content.strip()
141
+ return data_insights
142
+
143
+
144
  def export_to_word(response_content):
145
  doc = Document()
146
  doc.add_heading('AI Generated SCDD', 0)
 
170
 
171
  # Fetch exoplanet data
172
  exoplanet_data = fetch_exoplanet_data()
173
+
174
+ # Generate insights based on the user query and exoplanet data
175
+ data_insights = generate_data_insights(user_input, exoplanet_data)
176
+
177
+ # Combine the response and the data insights
178
+ full_response = f"{response}\n\nInsights from Existing Data: {data_insights}"
179
 
180
  # Embed Miro iframe
181
  iframe_html = """
 
210
  <button class="mapify-button">Create Mind Map on Mapify</button>
211
  </a>
212
  """
213
+ return full_response, iframe_html, mapify_button_html, word_doc_path, exoplanet_data
214
 
215
  iface = gr.Interface(
216
  fn=chatbot,