Download debug_prediction.py from KShoichi/hallucination-detector-project: direct link, hf CLI and curl.
- Browser
- Download file 2.05 kB
-
https://huggingface.co/KShoichi/hallucination-detector-project/resolve/main/debug_prediction.py
- Command line
-
hf download hf://KShoichi/hallucination-detector-project/debug_prediction.py
-
curl -L -o debug_prediction.py https://huggingface.co/KShoichi/hallucination-detector-project/resolve/main/debug_prediction.py
2.05 kB
| #!/usr/bin/env python3 | |
| """ | |
| Quick test to see what the model is actually predicting | |
| """ | |
| import requests | |
| import json | |
| BASE_URL = "http://localhost:8000" | |
| def test_single_prediction(): | |
| """Test a single prediction to see raw output""" | |
| # Test obvious hallucination | |
| payload = { | |
| "prompt": "Question: What is the capital of France?", | |
| "response": "London is the capital of France", | |
| "question": "What is the capital of France?" | |
| } | |
| print("🧪 Testing obvious hallucination:") | |
| print(f"Question: {payload['question']}") | |
| print(f"Response: {payload['response']}") | |
| print(f"Expected: HALLUCINATION") | |
| print() | |
| try: | |
| response = requests.post(f"{BASE_URL}/api/debug-predict", json=payload, timeout=10) | |
| if response.status_code == 200: | |
| result = response.json() | |
| print("📊 Debug Results:") | |
| print(f"Raw Model Output: '{result.get('raw_model_output', '')}'") | |
| print(f"Extracted Prediction: '{result.get('extracted_prediction', '')}'") | |
| print(f"Is Hallucination: {result.get('is_hallucination', False)}") | |
| print(f"Confidence Score: {result.get('confidence_score', 0):.3f}") | |
| print() | |
| # Also test regular API | |
| response2 = requests.post(f"{BASE_URL}/api/predict", json=payload, timeout=10) | |
| if response2.status_code == 200: | |
| result2 = response2.json() | |
| print("📊 Regular API Results:") | |
| print(f"Is Hallucination: {result2.get('is_hallucination', False)}") | |
| print(f"Confidence Score: {result2.get('confidence_score', 0):.3f}") | |
| print(f"Raw Prediction: '{result2.get('raw_prediction', '')}'") | |
| else: | |
| print(f"❌ Error: {response.status_code}") | |
| print(response.text) | |
| except Exception as e: | |
| print(f"❌ Error: {e}") | |
| if __name__ == "__main__": | |
| test_single_prediction() | |