fairsenseai.analysis.risk_assessment.analyze_text_for_risks¶
- analyze_text_for_risks(text_input, top_k_risk=5, top_k_ai_rmf=1, embedding_model_name='all-MiniLM-L6-v2', progress=<gradio.helpers.Progress object>)[source]¶
Analyzes input text for AI-related risks and maps them to AI RMF guidelines using embedding-based similarity search.
- Parameters:
text_input (str) – The user scenario text describing an AI project to be analyzed
top_k_risk (int, optional) – Number of similar risks to retrieve, by default 5
top_k_ai_rmf (int, optional) – Number of AI RMF matches per risk to retrieve, by default 1
progress (gr.Progress, optional) – Gradio progress bar object for tracking analysis progress, by default gr.Progress()
embedding_model_name (str, optional) – Name of the sentence transformer model to use as embedder, by default “all-MiniLM-L6-v2”
- Returns:
- A tuple containing:
- highlighted_outputstr
HTML formatted string with highlighted risk entries.
- temp_csv_pathstr
Path to the saved CSV file containing detailed analysis results. Returns an empty string if analysis fails.
- Return type:
Examples
>>> scenario = "We're developing a facial recognition system for public spaces" >>> highlighted, csv_path = analyze_text_for_risks( ... scenario, ... top_k_risk=3, ... top_k_ai_rmf=2 ... ) >>> print(f"Results saved to: {csv_path}")
- Raises:
Exception – If there’s an error during the analysis process, returns error message and empty string as CSV path