Spaces:
Sleeping
Sleeping
File size: 1,226 Bytes
b767276 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | """Helpers for preparing and (optionally) copying results to the clipboard.
This module intentionally avoids external clipboard dependencies to keep the
package lightweight; it returns a formatted string that callers can copy
using their preferred mechanism.
"""
from typing import Any, Dict, List
def format_results_for_clipboard(results: List[Dict[str, Any]]) -> str:
"""Return a human-readable string representation of `results` suitable
for placing on the clipboard.
Args:
results: List of result dictionaries to format.
Returns:
A single string with a readable summary of each result.
"""
lines = []
for r in results:
text = r.get("text", "")
prob = r.get("bias_probability", "")
cls = r.get("bias_class", "")
lines.append(f"Text: {text}\nBias: {prob} ({cls})\n---")
return "\n".join(lines)
def copy_to_clipboard_text(results: List[Dict[str, Any]]) -> str:
"""Format results and return the string to be copied by the caller.
This function deliberately does NOT interact with the system clipboard so
it remains safe to call in headless or CI environments.
"""
return format_results_for_clipboard(results)
|