Spaces:
Running
Running
File size: 2,832 Bytes
542c765 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | """
Test the new /upload_and_chat endpoint - uploads file and gets HUMAN greeting
instead of raw schema.
"""
import requests
import json
import sys
BASE_URL = "http://localhost:8000"
def upload_and_start_dialogue(pdf_path, patient_name="Ramesh Kumar Sharma"):
"""Upload PDF and immediately get doctor greeting."""
print(f"\n{'='*70}")
print("π UPLOADING AND STARTING DIALOGUE")
print(f"{'='*70}\n")
with open(pdf_path, 'rb') as f:
files = {'file': f}
data = {'patient_name': patient_name, 'language': 'EN'}
try:
response = requests.post(
f"{BASE_URL}/upload_and_chat",
files=files,
data=data,
timeout=10
)
if response.status_code == 200:
result = response.json()
# Show analysis metadata
analysis = result.get('analysis', {})
print(f"π Analysis Status: {'β
READABLE' if analysis.get('is_readable') else 'β NOT READABLE'}")
print(f"π Report Type: {analysis.get('report_type')}")
print(f"β οΈ Severity: {analysis.get('severity_level')}")
print(f"π₯ Affected Organs: {', '.join(analysis.get('affected_organs', []))}")
# MAIN PART: Show human greeting
print(f"\n{'β'*70}")
print("π¬ DOCTOR'S GREETING (NOT SCHEMA):")
print(f"{'β'*70}\n")
print(result.get('doctor_greeting', 'No greeting'))
# Show what to do next
print(f"\n{'β'*70}")
print("π What to do next:")
print(" 1. Type your question/concern")
print(" 2. Send to /chat endpoint with the analysis context")
print(" 3. Continue back-and-forth dialogue")
print(f"{'β'*70}\n")
return result
else:
print(f"β Error: {response.status_code}")
print(response.text)
return None
except requests.exceptions.ConnectionError:
print("β Connection Error: Server not running!")
print("Start server with: python -m uvicorn app.main:app --reload --port 8000")
return None
except Exception as e:
print(f"β Error: {e}")
return None
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python human_upload.py <pdf_path>")
print("\nExample:")
print(" python human_upload.py C:\\path\\to\\report.pdf")
sys.exit(1)
pdf_path = sys.argv[1]
result = upload_and_start_dialogue(pdf_path)
|