astronolan commited on
Commit
5a63add
·
1 Parent(s): c56e632

Enhance search functionality and UI components

Browse files

- Added a new example button for "a bursty, star forming galaxy"
- Updated callback function to handle the new button click
- Changed distance logging to query similarity in search results
- Adjusted modal image size for better display

Files changed (4) hide show
  1. app.py +0 -1
  2. src/callbacks.py +7 -5
  3. src/components.py +4 -2
  4. src/utils.py +19 -34
app.py CHANGED
@@ -127,7 +127,6 @@ def main():
127
  host=args.host,
128
  port=args.port
129
  )
130
-
131
  app = create_app('aionsearchmodel.pt')
132
  server = app.server
133
 
 
127
  host=args.host,
128
  port=args.port
129
  )
 
130
  app = create_app('aionsearchmodel.pt')
131
  server = app.server
132
 
src/callbacks.py CHANGED
@@ -170,11 +170,12 @@ def register_callbacks(app, search_service: SearchService):
170
  Input("example-3", "n_clicks"),
171
  Input("example-5", "n_clicks"),
172
  Input("example-6", "n_clicks"),
173
- Input("example-7", "n_clicks")],
 
174
  [State("search-button", "n_clicks")],
175
  prevent_initial_call=True
176
  )
177
- def trigger_search_from_examples(click1, click2, click3, click5, click6, click7, current_clicks):
178
  """Trigger search when example buttons are clicked."""
179
  ctx = callback_context
180
  if not ctx.triggered:
@@ -188,7 +189,8 @@ def register_callbacks(app, search_service: SearchService):
188
  "example-3": "galaxy with stream",
189
  "example-5": "A violent merger in progress with visible tidal features",
190
  "example-6": "Low surface brightness",
191
- "example-7": "face-on ring galaxy"
 
192
  }
193
 
194
  search_query = example_queries.get(button_id, "")
@@ -472,7 +474,7 @@ def register_callbacks(app, search_service: SearchService):
472
  'ra': search_data['ra'],
473
  'dec': search_data['dec'],
474
  'r_mag': search_data['r_mag'],
475
- 'distance': search_data['distance'],
476
  'cutout_url': search_data['cutout_url']
477
  })
478
 
@@ -784,7 +786,7 @@ def build_modal_content(galaxy_info: dict) -> tuple:
784
  """
785
  image_element = html.Img(
786
  src=galaxy_info["cutout_url"],
787
- style={"width": "100%", "max-width": "500px", "height": "auto"}
788
  )
789
 
790
  # Format primary key label (convert snake_case to Title Case)
 
170
  Input("example-3", "n_clicks"),
171
  Input("example-5", "n_clicks"),
172
  Input("example-6", "n_clicks"),
173
+ Input("example-7", "n_clicks"),
174
+ Input("example-8", "n_clicks")],
175
  [State("search-button", "n_clicks")],
176
  prevent_initial_call=True
177
  )
178
+ def trigger_search_from_examples(click1, click2, click3, click5, click6, click7, click8, current_clicks):
179
  """Trigger search when example buttons are clicked."""
180
  ctx = callback_context
181
  if not ctx.triggered:
 
189
  "example-3": "galaxy with stream",
190
  "example-5": "A violent merger in progress with visible tidal features",
191
  "example-6": "Low surface brightness",
192
+ "example-7": "face-on ring galaxy",
193
+ "example-8": "a bursty, star forming galaxy"
194
  }
195
 
196
  search_query = example_queries.get(button_id, "")
 
474
  'ra': search_data['ra'],
475
  'dec': search_data['dec'],
476
  'r_mag': search_data['r_mag'],
477
+ 'query_similarity': search_data['distance'],
478
  'cutout_url': search_data['cutout_url']
479
  })
480
 
 
786
  """
787
  image_element = html.Img(
788
  src=galaxy_info["cutout_url"],
789
+ style={"width": "100%", "max-width": "350px", "height": "auto"}
790
  )
791
 
792
  # Format primary key label (convert snake_case to Title Case)
src/components.py CHANGED
@@ -553,7 +553,9 @@ def create_search_container():
553
  dbc.Button([html.I(className="fas fa-moon me-2"), "Low surface brightness"],
554
  id="example-6", className="example-button me-2 mb-2", size="sm", color="light"),
555
  dbc.Button([html.I(className="fas fa-ring me-2"), "Ring galaxy"],
556
- id="example-7", className="example-button mb-2", size="sm", color="light")
 
 
557
  ], className="text-center")
558
  ], className="mb-3"),
559
 
@@ -825,7 +827,7 @@ def create_galaxy_modal():
825
  ]),
826
  dbc.ModalFooter([
827
  dbc.Button(
828
- [html.I(className="fas fa-plus-circle me-2"), "Add to Advanced Search"],
829
  id="add-to-advanced-search",
830
  color="primary",
831
  className="me-2"
 
553
  dbc.Button([html.I(className="fas fa-moon me-2"), "Low surface brightness"],
554
  id="example-6", className="example-button me-2 mb-2", size="sm", color="light"),
555
  dbc.Button([html.I(className="fas fa-ring me-2"), "Ring galaxy"],
556
+ id="example-7", className="example-button me-2 mb-2", size="sm", color="light"),
557
+ dbc.Button([html.I(className="fas fa-star me-2"), "a bursty, star forming galaxy"],
558
+ id="example-8", className="example-button mb-2", size="sm", color="light")
559
  ], className="text-center")
560
  ], className="mb-3"),
561
 
 
827
  ]),
828
  dbc.ModalFooter([
829
  dbc.Button(
830
+ [html.I(className="fas fa-plus me-2"), "Search for similar"],
831
  id="add-to-advanced-search",
832
  color="primary",
833
  className="me-2"
src/utils.py CHANGED
@@ -36,7 +36,7 @@ def log_zilliz_query(
36
  query_time: float,
37
  cost_vcu: int = 0
38
  ) -> None:
39
- """Log Zilliz queries to a file in logs/ directory.
40
 
41
  Args:
42
  query_type: Type of query (e.g., "vector_search", "text_search")
@@ -45,17 +45,13 @@ def log_zilliz_query(
45
  query_time: Query execution time in seconds
46
  cost_vcu: Cost in vCU units
47
  """
48
- logs_dir = Path("logs")
49
- logs_dir.mkdir(parents=True, exist_ok=True)
50
-
51
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")
52
- log_file = logs_dir / f"zilliz_query_{timestamp}.json"
53
 
54
  # Convert vCU cost to dollars
55
  cost_usd = (cost_vcu / 1e6) * VCU_COST_PER_MILLION
56
 
57
  log_data = {
58
- "timestamp": datetime.now().isoformat(),
59
  "query_type": query_type,
60
  "query_info": query_info,
61
  "result_count": result_count,
@@ -64,11 +60,15 @@ def log_zilliz_query(
64
  "cost_usd": cost_usd
65
  }
66
 
67
- with open(log_file, 'w') as f:
68
- json.dump(log_data, f, indent=2)
 
 
 
 
69
 
70
  logger.info(
71
- f"Query logged to {log_file} | {result_count} results in {query_time:.3f}s | "
72
  f"{cost_vcu} vCU (${cost_usd:.6f})"
73
  )
74
 
@@ -162,34 +162,19 @@ def log_query_to_csv(
162
  query_xml: str,
163
  csv_path: str = "logs/query_log.csv"
164
  ) -> None:
165
- """Log a query to CSV file with datetime and XML string.
166
 
167
  Args:
168
  query_xml: XML string representation of the query
169
- csv_path: Path to the CSV log file
170
  """
171
- import csv
172
- import os
173
-
174
- # Create logs directory if it doesn't exist
175
- log_dir = Path(csv_path).parent
176
- log_dir.mkdir(parents=True, exist_ok=True)
177
-
178
- # Prepare log entry
179
  timestamp = datetime.now().isoformat()
180
 
181
- # Check if file exists to determine if we need to write header
182
- file_exists = Path(csv_path).exists()
183
-
184
- # Append to CSV
185
- with open(csv_path, 'a', newline='', encoding='utf-8') as f:
186
- writer = csv.writer(f)
187
-
188
- # Write header if file is new
189
- if not file_exists:
190
- writer.writerow(['datetime', 'query'])
191
-
192
- # Write the query log
193
- writer.writerow([timestamp, query_xml])
194
 
195
- logger.info(f"Query logged to {csv_path}")
 
36
  query_time: float,
37
  cost_vcu: int = 0
38
  ) -> None:
39
+ """Print Zilliz query info to terminal instead of saving to file.
40
 
41
  Args:
42
  query_type: Type of query (e.g., "vector_search", "text_search")
 
45
  query_time: Query execution time in seconds
46
  cost_vcu: Cost in vCU units
47
  """
48
+ timestamp = datetime.now().isoformat()
 
 
 
 
49
 
50
  # Convert vCU cost to dollars
51
  cost_usd = (cost_vcu / 1e6) * VCU_COST_PER_MILLION
52
 
53
  log_data = {
54
+ "timestamp": timestamp,
55
  "query_type": query_type,
56
  "query_info": query_info,
57
  "result_count": result_count,
 
60
  "cost_usd": cost_usd
61
  }
62
 
63
+ # Print to terminal
64
+ print("\n" + "="*80)
65
+ print(f"ZILLIZ QUERY: {query_type}")
66
+ print("="*80)
67
+ print(json.dumps(log_data, indent=2))
68
+ print("="*80 + "\n")
69
 
70
  logger.info(
71
+ f"{result_count} results in {query_time:.3f}s | "
72
  f"{cost_vcu} vCU (${cost_usd:.6f})"
73
  )
74
 
 
162
  query_xml: str,
163
  csv_path: str = "logs/query_log.csv"
164
  ) -> None:
165
+ """Print query XML to terminal instead of saving to file.
166
 
167
  Args:
168
  query_xml: XML string representation of the query
169
+ csv_path: Deprecated parameter (kept for backward compatibility)
170
  """
 
 
 
 
 
 
 
 
171
  timestamp = datetime.now().isoformat()
172
 
173
+ # Print query to terminal
174
+ print("\n" + "="*80)
175
+ print(f"QUERY EXECUTED AT: {timestamp}")
176
+ print("="*80)
177
+ print(query_xml)
178
+ print("="*80 + "\n")
 
 
 
 
 
 
 
179
 
180
+ logger.info(f"Query printed to terminal")