codelion commited on
Commit
b8e291e
·
verified ·
1 Parent(s): f292ecf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -62,7 +62,7 @@ def ensure_float(value):
62
  def create_empty_figure(title):
63
  return go.Figure().update_layout(title=title, xaxis_title="", yaxis_title="", showlegend=False)
64
 
65
- # Function to process and visualize the full log probs with dynamic top_logprobs
66
  def visualize_logprobs(json_input):
67
  try:
68
  # Parse the input (handles both JSON and Python dictionaries)
@@ -87,6 +87,9 @@ def visualize_logprobs(json_input):
87
  logprobs.append(logprob)
88
  # Get top_logprobs, default to empty dict if None
89
  top_probs = entry.get("top_logprobs", {})
 
 
 
90
  # Ensure all values in top_logprobs are floats and create a list of tuples
91
  finite_top_probs = []
92
  for key, value in top_probs.items():
@@ -142,9 +145,12 @@ def visualize_logprobs(json_input):
142
  max_alternatives = max(len(alts) for alts in top_alternatives) if top_alternatives else 0
143
  for i, entry in enumerate(content):
144
  logprob = ensure_float(entry.get("logprob", None))
145
- if math.isfinite(logprob) and logprob >= -100000 and "top_logprobs" in entry and entry["top_logprobs"] is not None:
146
  token = entry["token"]
147
- top_logprobs = entry["top_logprobs"]
 
 
 
148
  # Ensure all values in top_logprobs are floats
149
  finite_top_logprobs = []
150
  for key, value in top_logprobs.items():
 
62
  def create_empty_figure(title):
63
  return go.Figure().update_layout(title=title, xaxis_title="", yaxis_title="", showlegend=False)
64
 
65
+ # Function to process and visualize the full log probs with dynamic top_logprobs, handling None
66
  def visualize_logprobs(json_input):
67
  try:
68
  # Parse the input (handles both JSON and Python dictionaries)
 
87
  logprobs.append(logprob)
88
  # Get top_logprobs, default to empty dict if None
89
  top_probs = entry.get("top_logprobs", {})
90
+ if top_probs is None:
91
+ logger.debug("top_logprobs is None for token: %s, using empty dict", entry["token"])
92
+ top_probs = {} # Default to empty dict for None
93
  # Ensure all values in top_logprobs are floats and create a list of tuples
94
  finite_top_probs = []
95
  for key, value in top_probs.items():
 
145
  max_alternatives = max(len(alts) for alts in top_alternatives) if top_alternatives else 0
146
  for i, entry in enumerate(content):
147
  logprob = ensure_float(entry.get("logprob", None))
148
+ if math.isfinite(logprob) and logprob >= -100000 and "top_logprobs" in entry:
149
  token = entry["token"]
150
+ top_logprobs = entry.get("top_logprobs", {})
151
+ if top_logprobs is None:
152
+ logger.debug("top_logprobs is None for token: %s, using empty dict", token)
153
+ top_logprobs = {} # Default to empty dict for None
154
  # Ensure all values in top_logprobs are floats
155
  finite_top_logprobs = []
156
  for key, value in top_logprobs.items():