Update app.py
Browse files61 unmodified lines6263646566676818 unmodified lines87888990919249 unmodified lines14214314414514614714814915061 unmodified linesdef create_empty_figure(title):return go.Figure().update_layout(title=title, xaxis_title="", yaxis_title="", showlegend=False)# Function to process and visualize the full log probs with dynamic top_logprobsdef visualize_logprobs(json_input):try:# Parse the input (handles both JSON and Python dictionaries)18 unmodified lineslogprobs.append(logprob)# Get top_logprobs, default to empty dict if Nonetop_probs = entry.get("top_logprobs", {})# Ensure all values in top_logprobs are floats and create a list of tuplesfinite_top_probs = []for key, value in top_probs.items():49 unmodified linesmax_alternatives = max(len(alts) for alts in top_alternatives) if top_alternatives else 0for i, entry in enumerate(content):logprob = ensure_float(entry.get("logprob", None))if math.isfinite(logprob) and logprob >= -100000 and "top_logprobs" in entry and entry["top_logprobs"] is not None:token = entry["token"]top_logprobs = entry["top_logprobs"]# Ensure all values in top_logprobs are floatsfinite_top_logprobs = []for key, value in top_logprobs.items():61 unmodified lines6263646566676818 unmodified lines87888990919293949549 unmodified lines14514614714814915015115215315415515661 unmodified linesdef create_empty_figure(title):return go.Figure().update_layout(title=title, xaxis_title="", yaxis_title="", showlegend=False)# Function to process and visualize the full log probs with dynamic top_logprobs, handling Nonedef visualize_logprobs(json_input):try:# Parse the input (handles both JSON and Python dictionaries)18 unmodified lineslogprobs.append(logprob)# Get top_logprobs, default to empty dict if Nonetop_probs = entry.get("top_logprobs", {})if top_probs is None:logger.debug("top_logprobs is None for token: %s, using empty dict", entry["token"])top_probs = {} # Default to empty dict for None# Ensure all values in top_logprobs are floats and create a list of tuplesfinite_top_probs = []for key, value in top_probs.items():49 unmodified linesmax_alternatives = max(len(alts) for alts in top_alternatives) if top_alternatives else 0for i, entry in enumerate(content):logprob = ensure_float(entry.get("logprob", None))if math.isfinite(logprob) and logprob >= -100000 and "top_logprobs" in entry:token = entry["token"]top_logprobs = entry.get("top_logprobs", {})if top_logprobs is None:logger.debug("top_logprobs is None for token: %s, using empty dict", token)top_logprobs = {} # Default to empty dict for None# Ensure all values in top_logprobs are floatsfinite_top_logprobs = []for key, value in top_logprobs.items():
app.py+9-3