naman1102 commited on
Commit
e410b86
·
1 Parent(s): 9169bdf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -56
app.py CHANGED
@@ -245,9 +245,8 @@ def create_ui() -> gr.Blocks:
245
  lines=5,
246
  placeholder="repo1, repo2\nrepo3"
247
  )
248
- with gr.Row():
249
- submit_btn = gr.Button("Submit Repo IDs", variant="primary")
250
- submit_loading = gr.Loading(visible=False)
251
 
252
  with gr.Column():
253
  gr.Markdown("### Or Search by Keywords")
@@ -256,9 +255,8 @@ def create_ui() -> gr.Blocks:
256
  lines=3,
257
  placeholder="Enter keywords separated by commas"
258
  )
259
- with gr.Row():
260
- search_btn = gr.Button("Search by Keywords", variant="primary")
261
- search_loading = gr.Loading(visible=False)
262
 
263
  df_output = gr.Dataframe(
264
  headers=["repo id", "strength", "weaknesses", "speciality", "relevance rating"],
@@ -266,7 +264,7 @@ def create_ui() -> gr.Blocks:
266
  )
267
  with gr.Row():
268
  analyze_btn = gr.Button("Start Analysis", variant="primary")
269
- analyze_loading = gr.Loading(visible=False)
270
  compare_btn = gr.Button("Compare Repositories", variant="secondary")
271
 
272
  # Analysis Page
@@ -286,10 +284,10 @@ def create_ui() -> gr.Blocks:
286
  summary_output = gr.Textbox(label="Analysis Summary", lines=10)
287
  with gr.Row():
288
  next_btn = gr.Button("Analyze Next Repository", variant="primary")
289
- next_loading = gr.Loading(visible=False)
290
  finish_btn = gr.Button("Finish Analysis", variant="secondary")
291
  export_btn = gr.Button("Export Results", variant="secondary")
292
- export_loading = gr.Loading(visible=False)
293
 
294
  # Comparison Page
295
  with gr.Group(visible=False) as comparison_page:
@@ -337,9 +335,9 @@ def create_ui() -> gr.Blocks:
337
  )
338
  with gr.Row():
339
  send_btn = gr.Button("Send", variant="primary")
340
- send_loading = gr.Loading(visible=False)
341
  end_chat_btn = gr.Button("End Chat", variant="secondary")
342
- end_chat_loading = gr.Loading(visible=False)
343
 
344
  # Results Page
345
  with gr.Group(visible=False) as results_page:
@@ -394,99 +392,99 @@ def create_ui() -> gr.Blocks:
394
  outputs=[start_page, input_page, analysis_page, chatbot_page, results_page, help_page, comparison_page, history_page]
395
  )
396
 
397
- # Modified event handlers with loading states
398
- def process_repo_input_with_loading(text: str, state: AppState) -> Tuple[pd.DataFrame, gr.update]:
399
- """Process repo input with loading state."""
400
- return process_repo_input(text, state), gr.update(visible=False)
401
 
402
- def keyword_search_with_loading(keyword: str, state: AppState) -> Tuple[pd.DataFrame, gr.update]:
403
- """Search keywords with loading state."""
404
- return keyword_search_and_update(keyword, state), gr.update(visible=False)
405
 
406
- def analyze_with_loading(state: AppState) -> Tuple[str, str, pd.DataFrame, gr.update]:
407
- """Analyze with loading state."""
408
- return *show_combined_repo_and_llm(state), gr.update(visible=False)
409
 
410
- def send_message_with_loading(user_message: str, history: List[Dict[str, str]], state: AppState) -> Tuple[List[Dict[str, str]], str, gr.update]:
411
- """Send message with loading state."""
412
  if not user_message:
413
- return history, "", gr.update(visible=False)
414
  history.append({"role": "user", "content": user_message})
415
  response = chat_with_user(user_message, history, CHATBOT_SYSTEM_PROMPT)
416
  history.append({"role": "assistant", "content": response})
417
- return history, "", gr.update(visible=False)
418
 
419
- def end_chat_with_loading(history: List[Dict[str, str]], state: AppState) -> Tuple[List[str], gr.update, gr.update]:
420
  """End chat and extract keywords."""
421
  if not history:
422
- return [], gr.update(visible=True), gr.update(visible=False)
423
  keywords = extract_keywords_from_conversation(history)
424
  state.generated_keywords = keywords
425
- return keywords, gr.update(visible=True), gr.update(visible=False)
426
 
427
- def export_with_loading(df: pd.DataFrame) -> Tuple[str, gr.update]:
428
- """Export with loading state."""
429
- return export_results(df), gr.update(visible=False)
430
 
431
- # Update event handlers with loading states
432
  submit_btn.click(
433
- fn=lambda: gr.update(visible=True),
434
  inputs=[],
435
- outputs=[submit_loading]
436
  ).then(
437
- fn=process_repo_input_with_loading,
438
  inputs=[repo_id_input, state],
439
- outputs=[df_output, submit_loading]
440
  )
441
 
442
  search_btn.click(
443
- fn=lambda: gr.update(visible=True),
444
  inputs=[],
445
- outputs=[search_loading]
446
  ).then(
447
- fn=keyword_search_with_loading,
448
  inputs=[keyword_input, state],
449
- outputs=[df_output, search_loading]
450
  )
451
 
452
  next_btn.click(
453
- fn=lambda: gr.update(visible=True),
454
  inputs=[],
455
- outputs=[next_loading]
456
  ).then(
457
- fn=analyze_with_loading,
458
  inputs=[state],
459
- outputs=[content_output, summary_output, df_output, next_loading]
460
  )
461
 
462
  send_btn.click(
463
- fn=lambda: gr.update(visible=True),
464
  inputs=[],
465
- outputs=[send_loading]
466
  ).then(
467
- fn=send_message_with_loading,
468
  inputs=[msg, chatbot, state],
469
- outputs=[chatbot, msg, send_loading]
470
  )
471
 
472
  end_chat_btn.click(
473
- fn=lambda: gr.update(visible=True),
474
  inputs=[],
475
- outputs=[end_chat_loading]
476
  ).then(
477
- fn=end_chat_with_loading,
478
  inputs=[chatbot, state],
479
- outputs=[gr.Textbox(label="Extracted Keywords"), results_page, end_chat_loading]
480
  )
481
 
482
  export_btn.click(
483
- fn=lambda: gr.update(visible=True),
484
  inputs=[],
485
- outputs=[export_loading]
486
  ).then(
487
- fn=export_with_loading,
488
  inputs=[results_df],
489
- outputs=[gr.Textbox(label="Export Status"), export_loading]
490
  )
491
 
492
  restart_btn.click(
 
245
  lines=5,
246
  placeholder="repo1, repo2\nrepo3"
247
  )
248
+ submit_btn = gr.Button("Submit Repo IDs", variant="primary")
249
+ submit_status = gr.Textbox(label="Status", visible=False)
 
250
 
251
  with gr.Column():
252
  gr.Markdown("### Or Search by Keywords")
 
255
  lines=3,
256
  placeholder="Enter keywords separated by commas"
257
  )
258
+ search_btn = gr.Button("Search by Keywords", variant="primary")
259
+ search_status = gr.Textbox(label="Status", visible=False)
 
260
 
261
  df_output = gr.Dataframe(
262
  headers=["repo id", "strength", "weaknesses", "speciality", "relevance rating"],
 
264
  )
265
  with gr.Row():
266
  analyze_btn = gr.Button("Start Analysis", variant="primary")
267
+ analyze_status = gr.Textbox(label="Status", visible=False)
268
  compare_btn = gr.Button("Compare Repositories", variant="secondary")
269
 
270
  # Analysis Page
 
284
  summary_output = gr.Textbox(label="Analysis Summary", lines=10)
285
  with gr.Row():
286
  next_btn = gr.Button("Analyze Next Repository", variant="primary")
287
+ next_status = gr.Textbox(label="Status", visible=False)
288
  finish_btn = gr.Button("Finish Analysis", variant="secondary")
289
  export_btn = gr.Button("Export Results", variant="secondary")
290
+ export_status = gr.Textbox(label="Status", visible=False)
291
 
292
  # Comparison Page
293
  with gr.Group(visible=False) as comparison_page:
 
335
  )
336
  with gr.Row():
337
  send_btn = gr.Button("Send", variant="primary")
338
+ send_status = gr.Textbox(label="Status", visible=False)
339
  end_chat_btn = gr.Button("End Chat", variant="secondary")
340
+ end_chat_status = gr.Textbox(label="Status", visible=False)
341
 
342
  # Results Page
343
  with gr.Group(visible=False) as results_page:
 
392
  outputs=[start_page, input_page, analysis_page, chatbot_page, results_page, help_page, comparison_page, history_page]
393
  )
394
 
395
+ # Modified event handlers with status updates
396
+ def process_repo_input_with_status(text: str, state: AppState) -> Tuple[pd.DataFrame, gr.update]:
397
+ """Process repo input with status update."""
398
+ return process_repo_input(text, state), gr.update(value="", visible=False)
399
 
400
+ def keyword_search_with_status(keyword: str, state: AppState) -> Tuple[pd.DataFrame, gr.update]:
401
+ """Search keywords with status update."""
402
+ return keyword_search_and_update(keyword, state), gr.update(value="", visible=False)
403
 
404
+ def analyze_with_status(state: AppState) -> Tuple[str, str, pd.DataFrame, gr.update]:
405
+ """Analyze with status update."""
406
+ return *show_combined_repo_and_llm(state), gr.update(value="", visible=False)
407
 
408
+ def send_message_with_status(user_message: str, history: List[Dict[str, str]], state: AppState) -> Tuple[List[Dict[str, str]], str, gr.update]:
409
+ """Send message with status update."""
410
  if not user_message:
411
+ return history, "", gr.update(value="", visible=False)
412
  history.append({"role": "user", "content": user_message})
413
  response = chat_with_user(user_message, history, CHATBOT_SYSTEM_PROMPT)
414
  history.append({"role": "assistant", "content": response})
415
+ return history, "", gr.update(value="", visible=False)
416
 
417
+ def end_chat_with_status(history: List[Dict[str, str]], state: AppState) -> Tuple[List[str], gr.update, gr.update]:
418
  """End chat and extract keywords."""
419
  if not history:
420
+ return [], gr.update(visible=True), gr.update(value="", visible=False)
421
  keywords = extract_keywords_from_conversation(history)
422
  state.generated_keywords = keywords
423
+ return keywords, gr.update(visible=True), gr.update(value="", visible=False)
424
 
425
+ def export_with_status(df: pd.DataFrame) -> Tuple[str, gr.update]:
426
+ """Export with status update."""
427
+ return export_results(df), gr.update(value="", visible=False)
428
 
429
+ # Update event handlers with status updates
430
  submit_btn.click(
431
+ fn=lambda: gr.update(value="Processing...", visible=True),
432
  inputs=[],
433
+ outputs=[submit_status]
434
  ).then(
435
+ fn=process_repo_input_with_status,
436
  inputs=[repo_id_input, state],
437
+ outputs=[df_output, submit_status]
438
  )
439
 
440
  search_btn.click(
441
+ fn=lambda: gr.update(value="Searching...", visible=True),
442
  inputs=[],
443
+ outputs=[search_status]
444
  ).then(
445
+ fn=keyword_search_with_status,
446
  inputs=[keyword_input, state],
447
+ outputs=[df_output, search_status]
448
  )
449
 
450
  next_btn.click(
451
+ fn=lambda: gr.update(value="Analyzing...", visible=True),
452
  inputs=[],
453
+ outputs=[next_status]
454
  ).then(
455
+ fn=analyze_with_status,
456
  inputs=[state],
457
+ outputs=[content_output, summary_output, df_output, next_status]
458
  )
459
 
460
  send_btn.click(
461
+ fn=lambda: gr.update(value="Sending...", visible=True),
462
  inputs=[],
463
+ outputs=[send_status]
464
  ).then(
465
+ fn=send_message_with_status,
466
  inputs=[msg, chatbot, state],
467
+ outputs=[chatbot, msg, send_status]
468
  )
469
 
470
  end_chat_btn.click(
471
+ fn=lambda: gr.update(value="Processing...", visible=True),
472
  inputs=[],
473
+ outputs=[end_chat_status]
474
  ).then(
475
+ fn=end_chat_with_status,
476
  inputs=[chatbot, state],
477
+ outputs=[gr.Textbox(label="Extracted Keywords"), results_page, end_chat_status]
478
  )
479
 
480
  export_btn.click(
481
+ fn=lambda: gr.update(value="Exporting...", visible=True),
482
  inputs=[],
483
+ outputs=[export_status]
484
  ).then(
485
+ fn=export_with_status,
486
  inputs=[results_df],
487
+ outputs=[gr.Textbox(label="Export Status"), export_status]
488
  )
489
 
490
  restart_btn.click(