Spaces:
Running
Running
| #!/usr/bin/env python3 | |
| """ | |
| Demo: Full Schema β Text β Chat Pipeline | |
| Shows the /upload_and_chat endpoint working end-to-end | |
| """ | |
| import requests | |
| import json | |
| from pathlib import Path | |
| def demo_pipeline(): | |
| pdf_path = Path('/c/Users/DEVANG MISHRA/OneDrive/Documents/rahat1/sample_lab_report.pdf') | |
| # Check if file exists | |
| if not pdf_path.exists(): | |
| print("β PDF not found, trying alternate path...") | |
| pdf_path = Path('../sample_lab_report.pdf') | |
| if pdf_path.exists(): | |
| print('=' * 80) | |
| print('π§ͺ TESTING: Schema β Text β Chat Pipeline') | |
| print('=' * 80) | |
| print(f'π Uploading: {pdf_path.name}') | |
| print() | |
| try: | |
| with open(pdf_path, 'rb') as f: | |
| files = {'file': f} | |
| response = requests.post('http://localhost:8000/upload_and_chat', files=files) | |
| if response.status_code == 200: | |
| data = response.json() | |
| # STEP 1: Show Schema Analysis | |
| print('β STEP 1: PDF Analysis β Schema Generated') | |
| print('-' * 80) | |
| analysis = data.get('analysis', {}) | |
| findings = analysis.get('findings', []) | |
| affected_organs = analysis.get('affected_organs', []) | |
| severity = analysis.get('severity_level', 'UNKNOWN') | |
| print(f' Parameters Found: {len(findings)}') | |
| print(f' Severity Level: {severity}') | |
| print(f' Affected Organs: {", ".join(affected_organs)}') | |
| print() | |
| print(' Sample Findings:') | |
| for finding in findings[:3]: | |
| status_emoji = 'β¬οΈ' if finding.get('status') == 'LOW' else 'β¬οΈ' if finding.get('status') == 'HIGH' else 'β' | |
| print(f' {status_emoji} {finding["parameter"]}: {finding["value"]} {finding["unit"]} ({finding["status"]})') | |
| print() | |
| # STEP 2: Show Schema as Text | |
| print('β STEP 2: Schema β Converted to Natural Language Text') | |
| print('-' * 80) | |
| schema_text = data.get('schema_as_text', '') | |
| if schema_text: | |
| lines = schema_text.split('\n') | |
| for i, line in enumerate(lines[:6]): | |
| if line.strip(): | |
| print(f' {line}') | |
| else: | |
| print(' (No schema_as_text in response)') | |
| print() | |
| # STEP 3: Show Doctor Response | |
| print('β STEP 3: Text β Fed to Dr. Raahat AI Chat System') | |
| print('-' * 80) | |
| doctor_greeting = data.get('doctor_greeting', '') | |
| if doctor_greeting: | |
| lines = doctor_greeting.split('\n') | |
| for i, line in enumerate(lines[:10]): | |
| print(f' {line}') | |
| if len(lines) > 10: | |
| print(f' ... ({len(lines) - 10} more lines)') | |
| else: | |
| print(' (No doctor response)') | |
| print() | |
| # Final Result | |
| print('=' * 80) | |
| print('β¨ SUCCESS: Full Pipeline Working!') | |
| print(' PDF β Schema β Natural Text β Human Doctor Response') | |
| print('=' * 80) | |
| else: | |
| print(f'β API Error: {response.status_code}') | |
| print(response.text[:200]) | |
| except Exception as e: | |
| print(f'β Error: {str(e)}') | |
| else: | |
| print(f'β PDF not found at: {pdf_path}') | |
| print(' Please check sample_lab_report.pdf location') | |
| if __name__ == '__main__': | |
| demo_pipeline() | |