Overview
TheHallucinationDetectorApp class provides a complete application wrapper around the PAS2 detector, including database storage for feedback, progress tracking, and Gradio UI integration.
Constructor
Class attributes
The initialized PAS2 detector instance. Initially
None until initialize_api is called.Directory path for persistent data storage (default:
"/data").Full path to the SQLite database file for storing feedback.
Registered callback function for progress updates.
Methods
initialize_api
Mistral API key for accessing the Mistral API.
OpenAI API key for accessing the OpenAI API.
Status message indicating success or failure of initialization.
process_query
The user query to analyze for hallucinations.
Dictionary containing detection results with keys:
original_query: The input queryoriginal_response: Response to the original queryparaphrased_queries: List of paraphrased queriesparaphrased_responses: List of responses to paraphrased querieshallucination_detected: Boolean indicating detection resultconfidence_score: Float between 0-1conflicting_facts: List of detected conflictsreasoning: Detailed reasoningsummary: Summary of analysiserror: Error message if processing failed
save_feedback
The results dictionary returned from
process_query.User feedback text to store with the results.
Status message indicating success or failure of the save operation.
get_feedback_stats
Dictionary containing statistics with keys:
total_feedback: Total number of feedback entrieshallucinations_detected: Count of detections with hallucinationsno_hallucinations: Count of detections without hallucinationsaverage_confidence: Average confidence score across all entries
None if an error occurs.set_progress_callback
Function to call with progress updates. Should accept
(stage: str, **kwargs).Database schema
The app automatically creates a SQLite database with the following schema:Example usage
Example with progress callback
The database is created in the
/data directory by default for persistent storage in Hugging Face Spaces. If this directory is not accessible, the app falls back to a temporary directory.