Hackathon Builder commited on
Commit
ea0f7e0
·
1 Parent(s): 49ca4d3

Fix 500 error on upload and add AI extraction fallback

Browse files
backend/main.py CHANGED
@@ -377,9 +377,20 @@ Return ONLY valid JSON matching this structure:
377
  RAW DOCUMENT:
378
  {text_content}
379
  """
 
380
  extracted = _gemini(extraction_prompt, retries=2, override_key=x_gemini_key)
 
381
  if not extracted:
382
- raise HTTPException(500, "AI failed to extract patient data from document. Check quota or format.")
 
 
 
 
 
 
 
 
 
383
  records = [extracted]
384
 
385
  added = []
 
377
  RAW DOCUMENT:
378
  {text_content}
379
  """
380
+ print(f"[UPLOAD] Running AI extraction on {len(text_content)} chars of text...")
381
  extracted = _gemini(extraction_prompt, retries=2, override_key=x_gemini_key)
382
+
383
  if not extracted:
384
+ print("[UPLOAD] AI extraction failed. Using basic fallback.")
385
+ # Fallback: Create a basic record from raw text
386
+ extracted = {
387
+ "id": f"FL-{len(PATIENTS)+1:03d}",
388
+ "display_name": f"Extracted Patient {len(PATIENTS)+1}",
389
+ "age": 45,
390
+ "gender": "unknown",
391
+ "risk_level": "moderate",
392
+ "clinical_notes": text_content[:2000] # Save some raw text
393
+ }
394
  records = [extracted]
395
 
396
  added = []
frontend/dist/assets/{index-CoJUskx2.js → index-B_BgTsDx.js} RENAMED
The diff for this file is too large to render. See raw diff
 
frontend/dist/index.html CHANGED
@@ -7,7 +7,7 @@
7
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
8
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
9
  <title>CodeBlue Context</title>
10
- <script type="module" crossorigin src="/assets/index-CoJUskx2.js"></script>
11
  <link rel="stylesheet" crossorigin href="/assets/index-DKXwe-v6.css">
12
  </head>
13
  <body>
 
7
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
8
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
9
  <title>CodeBlue Context</title>
10
+ <script type="module" crossorigin src="/assets/index-B_BgTsDx.js"></script>
11
  <link rel="stylesheet" crossorigin href="/assets/index-DKXwe-v6.css">
12
  </head>
13
  <body>
frontend/src/App.jsx CHANGED
@@ -57,7 +57,7 @@ export default function App() {
57
  setActiveTab('orchestrate');
58
  };
59
 
60
- // Upload patient JSON
61
  const handleUpload = async (e) => {
62
  const file = e.target.files[0];
63
  if (!file) return;
@@ -66,9 +66,16 @@ export default function App() {
66
  try {
67
  const geminiKey = localStorage.getItem('gemini_key');
68
  const headers = geminiKey ? { 'x-gemini-key': geminiKey } : {};
69
- await fetch(`${API}/patients/upload`, { method: 'POST', body: form, headers });
70
- fetchPatients();
71
- } catch { /* ignore */ }
 
 
 
 
 
 
 
72
  e.target.value = '';
73
  };
74
 
 
57
  setActiveTab('orchestrate');
58
  };
59
 
60
+ // Upload patient JSON/PDF
61
  const handleUpload = async (e) => {
62
  const file = e.target.files[0];
63
  if (!file) return;
 
66
  try {
67
  const geminiKey = localStorage.getItem('gemini_key');
68
  const headers = geminiKey ? { 'x-gemini-key': geminiKey } : {};
69
+ const res = await fetch(`${API}/patients/upload`, { method: 'POST', body: form, headers });
70
+ if (!res.ok) {
71
+ const err = await res.json();
72
+ alert(`Upload failed: ${err.detail || 'Internal Server Error'}`);
73
+ } else {
74
+ fetchPatients();
75
+ }
76
+ } catch (err) {
77
+ alert(`Network error during upload: ${err.message}`);
78
+ }
79
  e.target.value = '';
80
  };
81