Bias Analysis

The module consists of APIs used to analyze the bias in text and images.

analyze_text_for_bias(text_input, use_summarizer, progress=<gradio.helpers.Progress object>)[source]

Analyzes a given text for bias and provides a detailed analysis.

Parameters:
  • text_input (str) – The input text to analyze for bias.

  • use_summarizer (bool) – Whether to use the summarizer to condense the response.

  • progress (Progress) – A callback function to report progress.

Returns:

A tuple containing the highlighted text with bias words and the detailed analysis.

Return type:

Tuple[str, str]

Example

>>> highlighted, analysis = analyze_text_for_bias("This text may contain bias.", use_summarizer=True)
analyze_image_for_bias(image, use_summarizer, progress=<gradio.helpers.Progress object>)[source]

Analyzes an image for bias by extracting text using OCR and by generating image caption.

Parameters:
  • image (<module ‘PIL.Image’ from ‘/Users/mukundchettiar/Library/Caches/pypoetry/virtualenvs/fair-sense-ai-oZvE-iUE-py3.11/lib/python3.11/site-packages/PIL/Image.py’>) – The input image to analyze for bias.

  • use_summarizer (bool) – Whether to use the summarizer to condense the response.

  • progress – A callback function to report progress.

Returns:

A tuple containing the highlighted text with bias words and the detailed analysis.

Return type:

Tuple[str, str]

Example

>>> image = Image.open("example.jpg")
>>> highlighted, analysis = analyze_image_for_bias(image, use_summarizer=True)
analyze_text_csv(file, use_summarizer, output_filename='analysis_results.csv')[source]

Analyzes a CSV file containing multiple text entries for bias.

Parameters:
  • file (TextIO) – The input CSV file containing text data.

  • use_summarizer (bool) – Whether to use the summarizer to condense the response.

  • output_filename (Optional[str]) – The filename to save the analysis results.

Returns:

The HTML table containing results of batch analysis.

Return type:

str

Examples

>>> csv_file = open("data.csv", mode='r', newline='', encoding='utf-8')
>>> results_table_html = analyze_text_csv(csv_file, use_summarizer=True)
analyze_images_batch(images, use_summarizer, output_filename='image_analysis_results.csv')[source]

Analyzes a batch of images for bias.

Parameters:
  • images (List[str]) – The list of images to analyze for bias.

  • use_summarizer (bool) – Whether to use the summarizer to condense the response.

  • output_filename (Optional[str]) – The filename to save the analysis results.

Returns:

The HTML table containing results of batch analysis.

Return type:

str

Example

>>> results_table_html = analyze_images_batch(["image1.jpg", "image2.png"], use_summarizer=True)