Update app.py
Browse files
app.py
CHANGED
@@ -440,43 +440,7 @@ async def synthesize_voice(request: VoiceOutputRequest):
|
|
440 |
logger.error(f"Error in voice synthesis: {e}")
|
441 |
raise HTTPException(status_code=500, detail="Error generating voice output")
|
442 |
|
443 |
-
@app.post("/upload")
|
444 |
-
async def upload_and_analyze_file(file: UploadFile = File(...), format: str = Form("clean")):
|
445 |
-
try:
|
446 |
-
# 1. Read file content
|
447 |
-
contents = await file.read()
|
448 |
-
filename = file.filename.lower()
|
449 |
-
|
450 |
-
# 2. Extract text depending on file type
|
451 |
-
if filename.endswith(".pdf"):
|
452 |
-
import fitz # PyMuPDF
|
453 |
-
doc = fitz.open(stream=contents, filetype="pdf")
|
454 |
-
text = "\n".join([page.get_text() for page in doc])
|
455 |
-
elif filename.endswith(".txt"):
|
456 |
-
text = contents.decode("utf-8", errors="ignore")
|
457 |
-
elif filename.endswith(".csv"):
|
458 |
-
import pandas as pd
|
459 |
-
df = pd.read_csv(io.BytesIO(contents))
|
460 |
-
text = df.to_string()
|
461 |
-
elif filename.endswith(".xlsx"):
|
462 |
-
import pandas as pd
|
463 |
-
df = pd.read_excel(io.BytesIO(contents))
|
464 |
-
text = df.to_string()
|
465 |
-
else:
|
466 |
-
raise HTTPException(status_code=400, detail="Unsupported file type")
|
467 |
|
468 |
-
# 3. Send to TxAgent
|
469 |
-
message = (
|
470 |
-
f"You are a clinical assistant AI.\n\n"
|
471 |
-
f"Analyze the following patient document:\n\n{text[:10000]}"
|
472 |
-
)
|
473 |
-
response = agent.chat(message=message, history=[], temperature=0.7, max_new_tokens=1024)
|
474 |
-
|
475 |
-
return {"status": "success", "filename": file.filename, "response": response}
|
476 |
-
|
477 |
-
except Exception as e:
|
478 |
-
logger.error(f"File upload + analysis failed: {e}")
|
479 |
-
raise HTTPException(status_code=500, detail="Failed to process and analyze the file")
|
480 |
|
481 |
|
482 |
@app.post("/voice/chat")
|
|
|
440 |
logger.error(f"Error in voice synthesis: {e}")
|
441 |
raise HTTPException(status_code=500, detail="Error generating voice output")
|
442 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
443 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
444 |
|
445 |
|
446 |
@app.post("/voice/chat")
|