naman1102 commited on
Commit
d5449f8
·
1 Parent(s): 91ecbc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -84
app.py CHANGED
@@ -1036,16 +1036,25 @@ def create_ui() -> gr.Blocks:
1036
  return gr.update(visible=False), hf_url
1037
  return gr.update(visible=False), ""
1038
 
1039
- def handle_explore_repo(repo_id: str) -> Tuple[Any, Any]:
1040
- """Handle navigating to the repo explorer."""
1041
  logger.info(f"DEBUG: handle_explore_repo called with repo_id: '{repo_id}'")
1042
  logger.info(f"DEBUG: repo_id type: {type(repo_id)}")
1043
  logger.info(f"DEBUG: repo_id length: {len(repo_id) if repo_id else 'None'}")
1044
 
1045
- return (
1046
- gr.update(visible=False), # close modal
1047
- gr.update(selected="repo_explorer_tab") # switch tab
1048
- )
 
 
 
 
 
 
 
 
 
1049
 
1050
  def handle_cancel_modal() -> Any:
1051
  """Handle closing the modal."""
@@ -1195,56 +1204,14 @@ def create_ui() -> gr.Blocks:
1195
  inputs=[selected_repo_display],
1196
  outputs=[
1197
  repo_action_modal,
1198
- tabs
 
1199
  ],
1200
  js="""(repo_id) => {
1201
- console.log('DEBUG: JS called with repo_id:', repo_id);
1202
- console.log('DEBUG: repo_id type:', typeof repo_id);
1203
-
1204
- // Try multiple ways to get the repo_id
1205
- let actualRepoId = repo_id;
1206
-
1207
- // Check if repo_id is valid
1208
- if (!actualRepoId || actualRepoId === 'None' || actualRepoId === null || actualRepoId === 'null') {
1209
- console.log('DEBUG: repo_id is null/undefined, trying alternatives...');
1210
-
1211
- // Try to get from global variable
1212
- if (window.selectedRepoId) {
1213
- actualRepoId = window.selectedRepoId;
1214
- console.log('DEBUG: Found repo_id in global variable:', actualRepoId);
1215
- }
1216
-
1217
- // Try to get from the modal text input
1218
- if (!actualRepoId) {
1219
- const modalTextboxes = document.querySelectorAll('label:contains("Selected Repository") + textarea, label:contains("Selected Repository") + input');
1220
- console.log('DEBUG: Found modal textboxes:', modalTextboxes.length);
1221
- modalTextboxes.forEach((input, index) => {
1222
- console.log('DEBUG: Modal input', index, 'value:', input.value);
1223
- if (input.value && input.value.trim()) {
1224
- actualRepoId = input.value.trim();
1225
- }
1226
- });
1227
- }
1228
- }
1229
-
1230
- console.log('DEBUG: Final repo_id to use:', actualRepoId);
1231
-
1232
  setTimeout(() => {
1233
  window.scrollTo({top: 0, behavior: 'smooth'});
1234
- window.dispatchEvent(new Event('repoExplorerNavigation'));
1235
-
1236
- // Find and set the repo explorer input
1237
- const inputs = document.querySelectorAll('input[placeholder*="microsoft/DialoGPT-medium"], input[placeholder*="Repository ID"], label:contains("Repository ID") + input');
1238
- console.log('DEBUG: Found repo explorer inputs:', inputs.length);
1239
- inputs.forEach((input, index) => {
1240
- console.log('DEBUG: Setting repo explorer input', index, 'to value:', actualRepoId);
1241
- if (actualRepoId) {
1242
- input.value = actualRepoId;
1243
- input.dispatchEvent(new Event('input', { bubbles: true }));
1244
- input.dispatchEvent(new Event('change', { bubbles: true }));
1245
- }
1246
- });
1247
- }, 300);
1248
  }"""
1249
  )
1250
  cancel_modal_btn.click(
@@ -1262,44 +1229,14 @@ def create_ui() -> gr.Blocks:
1262
  df_output.select(
1263
  fn=handle_dataframe_select,
1264
  inputs=[df_output],
1265
- outputs=[selected_repo_display, repo_action_modal, tabs, expanded_content_title, expanded_content_text, text_expansion_modal],
1266
- js="""(evt, df) => {
1267
- console.log('DEBUG: Dataframe selection event:', evt);
1268
- if (evt && evt.index && evt.index.length >= 2) {
1269
- const row = evt.index[0];
1270
- const col = evt.index[1];
1271
- console.log('DEBUG: Selected row', row, 'col', col);
1272
-
1273
- // Store selected repo_id globally for backup
1274
- if (col === 0 && df && df.length > row) {
1275
- const repoId = df[row][0];
1276
- console.log('DEBUG: Storing global repo_id:', repoId);
1277
- window.selectedRepoId = repoId;
1278
- }
1279
- }
1280
- }"""
1281
  )
1282
 
1283
  # Add selection event for top repositories dataframe too
1284
  top_repos_df.select(
1285
  fn=handle_dataframe_select,
1286
  inputs=[top_repos_df],
1287
- outputs=[selected_repo_display, repo_action_modal, tabs, expanded_content_title, expanded_content_text, text_expansion_modal],
1288
- js="""(evt, df) => {
1289
- console.log('DEBUG: Top repos dataframe selection event:', evt);
1290
- if (evt && evt.index && evt.index.length >= 2) {
1291
- const row = evt.index[0];
1292
- const col = evt.index[1];
1293
- console.log('DEBUG: Selected row', row, 'col', col);
1294
-
1295
- // Store selected repo_id globally for backup
1296
- if (col === 0 && df && df.length > row) {
1297
- const repoId = df[row][0];
1298
- console.log('DEBUG: Storing global repo_id:', repoId);
1299
- window.selectedRepoId = repoId;
1300
- }
1301
- }
1302
- }"""
1303
  )
1304
 
1305
  # Reset button event
 
1036
  return gr.update(visible=False), hf_url
1037
  return gr.update(visible=False), ""
1038
 
1039
+ def handle_explore_repo(repo_id: str) -> Tuple[Any, Any, Any]:
1040
+ """Handle navigating to the repo explorer and populate the repo ID."""
1041
  logger.info(f"DEBUG: handle_explore_repo called with repo_id: '{repo_id}'")
1042
  logger.info(f"DEBUG: repo_id type: {type(repo_id)}")
1043
  logger.info(f"DEBUG: repo_id length: {len(repo_id) if repo_id else 'None'}")
1044
 
1045
+ if repo_id and repo_id.strip() and repo_id.strip() != 'nan':
1046
+ clean_repo_id = repo_id.strip()
1047
+ return (
1048
+ gr.update(visible=False), # close modal
1049
+ gr.update(selected="repo_explorer_tab"), # switch tab
1050
+ gr.update(value=clean_repo_id) # populate repo explorer input
1051
+ )
1052
+ else:
1053
+ return (
1054
+ gr.update(visible=False), # close modal
1055
+ gr.update(selected="repo_explorer_tab"), # switch tab
1056
+ gr.update() # don't change repo explorer input
1057
+ )
1058
 
1059
  def handle_cancel_modal() -> Any:
1060
  """Handle closing the modal."""
 
1204
  inputs=[selected_repo_display],
1205
  outputs=[
1206
  repo_action_modal,
1207
+ tabs,
1208
+ repo_components["repo_explorer_input"]
1209
  ],
1210
  js="""(repo_id) => {
1211
+ console.log('DEBUG: Navigate to repo explorer for:', repo_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1212
  setTimeout(() => {
1213
  window.scrollTo({top: 0, behavior: 'smooth'});
1214
+ }, 200);
 
 
 
 
 
 
 
 
 
 
 
 
 
1215
  }"""
1216
  )
1217
  cancel_modal_btn.click(
 
1229
  df_output.select(
1230
  fn=handle_dataframe_select,
1231
  inputs=[df_output],
1232
+ outputs=[selected_repo_display, repo_action_modal, tabs, expanded_content_title, expanded_content_text, text_expansion_modal]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1233
  )
1234
 
1235
  # Add selection event for top repositories dataframe too
1236
  top_repos_df.select(
1237
  fn=handle_dataframe_select,
1238
  inputs=[top_repos_df],
1239
+ outputs=[selected_repo_display, repo_action_modal, tabs, expanded_content_title, expanded_content_text, text_expansion_modal]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1240
  )
1241
 
1242
  # Reset button event