nomadicsynth commited on
Commit
e65f100
·
1 Parent(s): 3fe9024

Refactor code for improved readability and consistency in function definitions and error handling

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -68,15 +68,18 @@ if os.path.exists(cache_file):
68
  else:
69
  query_cache = {}
70
 
 
71
  def hash_query(query: str) -> str:
72
  """Generate a unique hash for the query."""
73
  return hashlib.sha256(query.encode("utf-8")).hexdigest()
74
 
 
75
  def save_cache():
76
  """Save the cache to a file."""
77
  with open(cache_file, "wb") as f:
78
  pickle.dump(query_cache, f)
79
 
 
80
  def init_embedding_model(
81
  model_name_or_path: str, model_revision: str = None, hf_token: str = None
82
  ) -> SentenceTransformer:
@@ -317,9 +320,7 @@ def format_search_results(abstract: str) -> tuple[pd.DataFrame, list[dict]]:
317
  papers = find_synergistic_papers(abstract)
318
  except ValueError as e:
319
  error_message = str(e)
320
- df = pd.DataFrame(
321
- [{"Error": error_message}]
322
- )
323
  return df, []
324
 
325
  # Convert to DataFrame for display
@@ -475,7 +476,9 @@ def create_interface():
475
  key="paper_details",
476
  )
477
  analyze_btn = gr.Button("Analyze Connection", variant="primary", visible=False)
478
- with gr.Accordion(label="Feedback and Flagging", open=True, visible=False) as paper_feedback_accordion:
 
 
479
  gr.Markdown(
480
  """
481
  Please provide feedback on the relevance of this paper to your input.
@@ -602,7 +605,10 @@ def create_interface():
602
  outputs=[paper_details_output, selected_paper_state],
603
  api_name=False,
604
  ).then(
605
- lambda: (gr.update(visible=True), gr.update(visible=True)), # Show analyze button and feedback accordion
 
 
 
606
  outputs=[analyze_btn, paper_feedback_accordion],
607
  api_name=False,
608
  )
 
68
  else:
69
  query_cache = {}
70
 
71
+
72
  def hash_query(query: str) -> str:
73
  """Generate a unique hash for the query."""
74
  return hashlib.sha256(query.encode("utf-8")).hexdigest()
75
 
76
+
77
  def save_cache():
78
  """Save the cache to a file."""
79
  with open(cache_file, "wb") as f:
80
  pickle.dump(query_cache, f)
81
 
82
+
83
  def init_embedding_model(
84
  model_name_or_path: str, model_revision: str = None, hf_token: str = None
85
  ) -> SentenceTransformer:
 
320
  papers = find_synergistic_papers(abstract)
321
  except ValueError as e:
322
  error_message = str(e)
323
+ df = pd.DataFrame([{"Error": error_message}])
 
 
324
  return df, []
325
 
326
  # Convert to DataFrame for display
 
476
  key="paper_details",
477
  )
478
  analyze_btn = gr.Button("Analyze Connection", variant="primary", visible=False)
479
+ with gr.Accordion(
480
+ label="Feedback and Flagging", open=True, visible=False
481
+ ) as paper_feedback_accordion:
482
  gr.Markdown(
483
  """
484
  Please provide feedback on the relevance of this paper to your input.
 
605
  outputs=[paper_details_output, selected_paper_state],
606
  api_name=False,
607
  ).then(
608
+ lambda: (
609
+ gr.update(visible=True),
610
+ gr.update(visible=True),
611
+ ), # Show analyze button and feedback accordion
612
  outputs=[analyze_btn, paper_feedback_accordion],
613
  api_name=False,
614
  )