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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI ,File, UploadFile,Form
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from typing import List,Optional
|
| 4 |
+
from component.mongoconnection import provideClient
|
| 5 |
+
from component.checkaccountexists import checkAccount
|
| 6 |
+
from component.filechecker import checkFile
|
| 7 |
+
from component.getproblems import GetProblems
|
| 8 |
+
from component.getdeep import GetDeepDive
|
| 9 |
+
from component.getbreakdown import GetBreakdown
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
from component.legal_points_agent import LegalKeyPoints
|
| 14 |
+
from component.legal_deepdive_agent import LegalDeepDive
|
| 15 |
+
from component.legal_breakdown_agent import LegalBreakdown
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
from component.medical_points_agent import MedicalKeyPoints
|
| 19 |
+
from component.medical_deepdive_agent import MedicalDeepDive
|
| 20 |
+
from component.medical_breakdown_agent import MedicalBreakdown
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
from component.research_deepdive_agent import ResearchDeepDive
|
| 25 |
+
from component.research_points_agent import ResearchKeyPoints
|
| 26 |
+
from component.research_breakdown_agent import ResearchBreakdown
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 30 |
+
from PyPDF2 import PdfReader
|
| 31 |
+
import io
|
| 32 |
+
import time
|
| 33 |
+
|
| 34 |
+
origins=[
|
| 35 |
+
"http://localhost:3000"
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
app = FastAPI()
|
| 40 |
+
app.add_middleware(
|
| 41 |
+
CORSMiddleware,
|
| 42 |
+
allow_origins=origins,
|
| 43 |
+
allow_credentials=True,
|
| 44 |
+
allow_methods=["*"],
|
| 45 |
+
allow_headers=["*"],
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
mclient=provideClient()
|
| 51 |
+
|
| 52 |
+
db=mclient["askmydoc_db"]
|
| 53 |
+
coll=db["askmydoc_col"]
|
| 54 |
+
|
| 55 |
+
class Item(BaseModel):
|
| 56 |
+
owner:str
|
| 57 |
+
|
| 58 |
+
class Item2(BaseModel):
|
| 59 |
+
owner: str
|
| 60 |
+
filetype:str
|
| 61 |
+
|
| 62 |
+
class QAI(BaseModel):
|
| 63 |
+
owner:str
|
| 64 |
+
files:List[str]
|
| 65 |
+
question:str
|
| 66 |
+
msg_type:str
|
| 67 |
+
|
| 68 |
+
class QA2(BaseModel):
|
| 69 |
+
owner:str
|
| 70 |
+
files:List[str]
|
| 71 |
+
|
| 72 |
+
class QA3(BaseModel):
|
| 73 |
+
owner:str
|
| 74 |
+
msg_type:str
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class QA4(BaseModel):
|
| 78 |
+
owner:str
|
| 79 |
+
msg_type:str
|
| 80 |
+
files:List[str]
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
@app.get("/")
|
| 84 |
+
def read_root():
|
| 85 |
+
return {"Hello": "World"}
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
@app.post("/setupaccount")
|
| 89 |
+
def create_item(data: Item):
|
| 90 |
+
print(data.owner)
|
| 91 |
+
payload={
|
| 92 |
+
|
| 93 |
+
"owner":data.owner,
|
| 94 |
+
"app_id":"askmydoc_v1",
|
| 95 |
+
"files":[],
|
| 96 |
+
"keypoints":[],
|
| 97 |
+
"deepdive":[],
|
| 98 |
+
"breakdown":[]
|
| 99 |
+
|
| 100 |
+
}
|
| 101 |
+
inserted=coll.insert_one(payload)
|
| 102 |
+
if inserted.inserted_id:
|
| 103 |
+
return {"status":True}
|
| 104 |
+
else:
|
| 105 |
+
|
| 106 |
+
return {"status":False}
|
| 107 |
+
|
| 108 |
+
@app.post("/checkaccount")
|
| 109 |
+
def checkaccount(data:Item):
|
| 110 |
+
status=checkAccount(data.owner)
|
| 111 |
+
print(data)
|
| 112 |
+
if status==True:
|
| 113 |
+
return {'status':True}
|
| 114 |
+
else:
|
| 115 |
+
return {"status":False}
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
@app.post("/checkfile")
|
| 119 |
+
def checkfileexistence(data:Item2):
|
| 120 |
+
filechecksresponse=checkFile(data.owner,data.filetype)
|
| 121 |
+
return filechecksresponse
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
@app.post("/checkproblems")
|
| 126 |
+
def checkProblems(data:QA4):
|
| 127 |
+
problems=GetProblems(data.owner,data.msg_type,data.files)
|
| 128 |
+
return problems
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
@app.post("/checkdive")
|
| 132 |
+
def checkProblems(data:QA4):
|
| 133 |
+
DIVE=GetDeepDive(data.owner,data.msg_type,data.files)
|
| 134 |
+
return DIVE
|
| 135 |
+
|
| 136 |
+
3
|
| 137 |
+
@app.post("/checkbreakdown")
|
| 138 |
+
def checkProblems(data:QA4):
|
| 139 |
+
DIVE=GetBreakdown(data.owner,data.msg_type,files=data.files)
|
| 140 |
+
return DIVE
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
@app.post("/upload-files")
|
| 145 |
+
async def upload_files(
|
| 146 |
+
files: List[UploadFile] = File(...),
|
| 147 |
+
owner: Optional[str] = Form(None),
|
| 148 |
+
filetype:Optional[str]=Form(None)
|
| 149 |
+
):
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
MAX_FILE_SIZE = 5 * 1024 * 1024
|
| 153 |
+
results = []
|
| 154 |
+
if len(files) > 2:
|
| 155 |
+
return {"error":"maximum 2 files allowed"}
|
| 156 |
+
try:
|
| 157 |
+
for file in files:
|
| 158 |
+
contents = await file.read()
|
| 159 |
+
if len(contents) > MAX_FILE_SIZE:
|
| 160 |
+
return {
|
| 161 |
+
"error": f"File '{file.filename}' exceeds 5MB limit",
|
| 162 |
+
"max_size": "5MB"
|
| 163 |
+
}
|
| 164 |
+
file_info = {
|
| 165 |
+
"filename": file.filename,
|
| 166 |
+
"content_type": file.content_type,
|
| 167 |
+
"size": len(contents),
|
| 168 |
+
"filetype":filetype
|
| 169 |
+
}
|
| 170 |
+
if file.content_type == "text/plain":
|
| 171 |
+
# Decode text files - now we can safely return full content
|
| 172 |
+
text_content = contents.decode("utf-8")
|
| 173 |
+
file_info["content"] = text_content # Full content since we have size limit
|
| 174 |
+
elif file.content_type == "application/pdf":
|
| 175 |
+
# Extract text from PDF
|
| 176 |
+
try:
|
| 177 |
+
pdf_file = io.BytesIO(contents)
|
| 178 |
+
pdf_reader = PdfReader(pdf_file)
|
| 179 |
+
text_content = ""
|
| 180 |
+
for page in pdf_reader.pages:
|
| 181 |
+
text_content += page.extract_text() + "\n"
|
| 182 |
+
file_info["content"] = text_content
|
| 183 |
+
file_info["pages"] = len(pdf_reader.pages)
|
| 184 |
+
except Exception as e:
|
| 185 |
+
file_info["error"] = f"Failed to read PDF: {str(e)}"
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
results.append(file_info)
|
| 189 |
+
coll.update_one(
|
| 190 |
+
{"owner": owner},
|
| 191 |
+
{"$push": {"files": {"$each": results}}}
|
| 192 |
+
)
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
return {"status":True}
|
| 196 |
+
except Exception as e:
|
| 197 |
+
return {"status":False}
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
@app.post("/legalproblems")
|
| 204 |
+
def LegalProblems(data:QA2):
|
| 205 |
+
documents=coll.find_one({"owner":data.owner})
|
| 206 |
+
print(data)
|
| 207 |
+
content=[]
|
| 208 |
+
if documents:
|
| 209 |
+
|
| 210 |
+
checkifalreadypresent=GetProblems(data.owner,"legal",data.files)
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
if len(checkifalreadypresent["problems"]) !=0:
|
| 214 |
+
return checkifalreadypresent["problems"]
|
| 215 |
+
|
| 216 |
+
for file in documents["files"]:
|
| 217 |
+
if file["filename"] in data.files:
|
| 218 |
+
content_payload=f"""
|
| 219 |
+
|
| 220 |
+
FILENAME :{file["filename"]}
|
| 221 |
+
CONTENT : {file["content"]}
|
| 222 |
+
"""
|
| 223 |
+
content.append(content_payload)
|
| 224 |
+
problems=LegalKeyPoints(content=content)
|
| 225 |
+
payload={"type":"legal","problems":problems,"files":data.files}
|
| 226 |
+
|
| 227 |
+
coll.update_one(
|
| 228 |
+
{"owner": data.owner},
|
| 229 |
+
{"$push": {"keypoints": payload}}
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
return {"problems":problems}
|
| 233 |
+
else:
|
| 234 |
+
|
| 235 |
+
return {"problems":None}
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
@app.post("/legaldeepdive")
|
| 240 |
+
def LegalDDive(data:QA2):
|
| 241 |
+
documents=coll.find_one({"owner":data.owner})
|
| 242 |
+
content=[]
|
| 243 |
+
if documents:
|
| 244 |
+
|
| 245 |
+
checkifalreadypresent=GetDeepDive(data.owner,"legal",data.files)
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
if len(checkifalreadypresent["dive"]) !=0:
|
| 249 |
+
return checkifalreadypresent["dive"]
|
| 250 |
+
|
| 251 |
+
for file in documents["files"]:
|
| 252 |
+
if file["filename"] in data.files:
|
| 253 |
+
content_payload=f"""
|
| 254 |
+
|
| 255 |
+
FILENAME :{file["filename"]}
|
| 256 |
+
CONTENT : {file["content"]}
|
| 257 |
+
"""
|
| 258 |
+
content.append(content_payload)
|
| 259 |
+
dive=LegalDeepDive(content=content)
|
| 260 |
+
payload={"type":"legal","dive":dive,"files":data.files}
|
| 261 |
+
|
| 262 |
+
coll.update_one(
|
| 263 |
+
{"owner": data.owner},
|
| 264 |
+
{"$push": {"deepdive": payload}}
|
| 265 |
+
)
|
| 266 |
+
return {"deepdive":dive}
|
| 267 |
+
else:
|
| 268 |
+
|
| 269 |
+
return {"deepdive":None}
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
@app.post("/legalbreakdown")
|
| 277 |
+
def LegalB(data:QA2):
|
| 278 |
+
documents=coll.find_one({"owner":data.owner})
|
| 279 |
+
print(data)
|
| 280 |
+
content=[]
|
| 281 |
+
if documents:
|
| 282 |
+
|
| 283 |
+
checkifalreadypresent=GetBreakdown(data.owner,"legal",data.files)
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
if len(checkifalreadypresent["breakdown"])!=0:
|
| 287 |
+
return checkifalreadypresent["breakdown"]
|
| 288 |
+
|
| 289 |
+
for file in documents["files"]:
|
| 290 |
+
if file["filename"] in data.files:
|
| 291 |
+
content_payload=f"""
|
| 292 |
+
|
| 293 |
+
FILENAME :{file["filename"]}
|
| 294 |
+
CONTENT : {file["content"]}
|
| 295 |
+
"""
|
| 296 |
+
content.append(content_payload)
|
| 297 |
+
breakdown=LegalBreakdown(content=content)
|
| 298 |
+
payload={"type":"legal","breakdown":breakdown,"files":data.files}
|
| 299 |
+
|
| 300 |
+
coll.update_one(
|
| 301 |
+
{"owner": data.owner},
|
| 302 |
+
{"$push": {"breakdown": payload}}
|
| 303 |
+
)
|
| 304 |
+
|
| 305 |
+
return {"problems":breakdown}
|
| 306 |
+
else:
|
| 307 |
+
|
| 308 |
+
return {"problems":None}
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
@app.post("/medicalproblems")
|
| 316 |
+
def MedicalProblems(data:QA2):
|
| 317 |
+
documents=coll.find_one({"owner":data.owner})
|
| 318 |
+
content=[]
|
| 319 |
+
if documents:
|
| 320 |
+
|
| 321 |
+
checkifalreadypresent=GetProblems(data.owner,"medical",data.files)
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
if len(checkifalreadypresent["problems"]) !=0:
|
| 325 |
+
return checkifalreadypresent["problems"]
|
| 326 |
+
|
| 327 |
+
for file in documents["files"]:
|
| 328 |
+
if file["filename"] in data.files:
|
| 329 |
+
content_payload=f"""
|
| 330 |
+
|
| 331 |
+
FILENAME :{file["filename"]}
|
| 332 |
+
CONTENT : {file["content"]}
|
| 333 |
+
"""
|
| 334 |
+
content.append(content_payload)
|
| 335 |
+
problems=MedicalKeyPoints(content=content)
|
| 336 |
+
payload={"type":"medical","problems":problems,"files":data.files}
|
| 337 |
+
|
| 338 |
+
coll.update_one(
|
| 339 |
+
{"owner": data.owner},
|
| 340 |
+
{"$push": {"keypoints": payload}}
|
| 341 |
+
)
|
| 342 |
+
|
| 343 |
+
return {"problems":problems}
|
| 344 |
+
else:
|
| 345 |
+
|
| 346 |
+
return {"problems":None}
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
@app.post("/medicaldeepdive")
|
| 352 |
+
def MedicalDDive(data:QA2):
|
| 353 |
+
documents=coll.find_one({"owner":data.owner})
|
| 354 |
+
content=[]
|
| 355 |
+
if documents:
|
| 356 |
+
|
| 357 |
+
checkifalreadypresent=GetDeepDive(data.owner,"medical",data.files)
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
if len(checkifalreadypresent["dive"]) !=0:
|
| 361 |
+
return checkifalreadypresent["dive"]
|
| 362 |
+
|
| 363 |
+
for file in documents["files"]:
|
| 364 |
+
if file["filename"] in data.files:
|
| 365 |
+
content_payload=f"""
|
| 366 |
+
|
| 367 |
+
FILENAME :{file["filename"]}
|
| 368 |
+
CONTENT : {file["content"]}
|
| 369 |
+
"""
|
| 370 |
+
content.append(content_payload)
|
| 371 |
+
dive=MedicalDeepDive(content=content)
|
| 372 |
+
payload={"type":"medical","dive":dive,"files":data.files}
|
| 373 |
+
|
| 374 |
+
coll.update_one(
|
| 375 |
+
{"owner": data.owner},
|
| 376 |
+
{"$push": {"deepdive": payload}}
|
| 377 |
+
)
|
| 378 |
+
|
| 379 |
+
return {"deepdive":dive}
|
| 380 |
+
else:
|
| 381 |
+
|
| 382 |
+
return {"deepdive":None}
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
@app.post("/medicalbreakdown")
|
| 388 |
+
def MedicalB(data:QA2):
|
| 389 |
+
documents=coll.find_one({"owner":data.owner})
|
| 390 |
+
print(data)
|
| 391 |
+
content=[]
|
| 392 |
+
if documents:
|
| 393 |
+
|
| 394 |
+
checkifalreadypresent=GetBreakdown(data.owner,"medical",data.files)
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
if len(checkifalreadypresent["breakdown"]) !=0:
|
| 398 |
+
return checkifalreadypresent["breakdown"]
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
|
| 402 |
+
for file in documents["files"]:
|
| 403 |
+
if file["filename"] in data.files:
|
| 404 |
+
content_payload=f"""
|
| 405 |
+
|
| 406 |
+
FILENAME :{file["filename"]}
|
| 407 |
+
CONTENT : {file["content"]}
|
| 408 |
+
"""
|
| 409 |
+
content.append(content_payload)
|
| 410 |
+
breakdown=MedicalBreakdown(content=content)
|
| 411 |
+
payload={"type":"medical","breakdown":breakdown,"files":data.files}
|
| 412 |
+
|
| 413 |
+
coll.update_one(
|
| 414 |
+
{"owner": data.owner},
|
| 415 |
+
{"$push": {"breakdown": payload}}
|
| 416 |
+
)
|
| 417 |
+
|
| 418 |
+
return {"problems":breakdown}
|
| 419 |
+
else:
|
| 420 |
+
|
| 421 |
+
return {"problems":None}
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
@app.post("/researchproblems")
|
| 428 |
+
def ResearchProblems(data:QA2):
|
| 429 |
+
documents=coll.find_one({"owner":data.owner})
|
| 430 |
+
content=[]
|
| 431 |
+
if documents:
|
| 432 |
+
|
| 433 |
+
checkifalreadypresent=GetProblems(data.owner,"research",data.files)
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
if len(checkifalreadypresent["problems"])!=0:
|
| 437 |
+
return checkifalreadypresent["problems"]
|
| 438 |
+
|
| 439 |
+
for file in documents["files"]:
|
| 440 |
+
if file["filename"] in data.files:
|
| 441 |
+
content_payload=f"""
|
| 442 |
+
|
| 443 |
+
FILENAME :{file["filename"]}
|
| 444 |
+
CONTENT : {file["content"]}
|
| 445 |
+
"""
|
| 446 |
+
content.append(content_payload)
|
| 447 |
+
problems=ResearchKeyPoints(content=content)
|
| 448 |
+
payload={"type":"research","problems":problems,"files":data.files}
|
| 449 |
+
|
| 450 |
+
coll.update_one(
|
| 451 |
+
{"owner": data.owner},
|
| 452 |
+
{"$push": {"keypoints": payload}}
|
| 453 |
+
)
|
| 454 |
+
|
| 455 |
+
return {"problems":problems}
|
| 456 |
+
else:
|
| 457 |
+
|
| 458 |
+
return {"problems":None}
|
| 459 |
+
|
| 460 |
+
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
@app.post("/researchbreakdown")
|
| 464 |
+
def ResearchB(data:QA2):
|
| 465 |
+
documents=coll.find_one({"owner":data.owner})
|
| 466 |
+
print(data)
|
| 467 |
+
content=[]
|
| 468 |
+
if documents:
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
checkifalreadypresent=GetBreakdown(data.owner,"research",data.files)
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
if len(checkifalreadypresent["breakdown"]) !=0:
|
| 475 |
+
return checkifalreadypresent["breakdown"]
|
| 476 |
+
|
| 477 |
+
for file in documents["files"]:
|
| 478 |
+
if file["filename"] in data.files:
|
| 479 |
+
content_payload=f"""
|
| 480 |
+
|
| 481 |
+
FILENAME :{file["filename"]}
|
| 482 |
+
CONTENT : {file["content"]}
|
| 483 |
+
"""
|
| 484 |
+
content.append(content_payload)
|
| 485 |
+
breakdown=ResearchBreakdown(content=content)
|
| 486 |
+
payload={"type":"research","breakdown":breakdown,"files":data.files}
|
| 487 |
+
|
| 488 |
+
coll.update_one(
|
| 489 |
+
{"owner": data.owner},
|
| 490 |
+
{"$push": {"breakdown": payload}}
|
| 491 |
+
)
|
| 492 |
+
|
| 493 |
+
return {"problems":breakdown}
|
| 494 |
+
else:
|
| 495 |
+
|
| 496 |
+
return {"problems":None}
|
| 497 |
+
|
| 498 |
+
'''
|
| 499 |
+
|
| 500 |
+
'''
|
| 501 |
+
@app.post("/researchdeepdive")
|
| 502 |
+
def ResearchDDive(data:QA2):
|
| 503 |
+
documents=coll.find_one({"owner":data.owner})
|
| 504 |
+
content=[]
|
| 505 |
+
if documents:
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
checkifalreadypresent=GetDeepDive(data.owner,"research",data.files)
|
| 510 |
+
|
| 511 |
+
|
| 512 |
+
if len(checkifalreadypresent["dive"]) !=0:
|
| 513 |
+
return checkifalreadypresent["dive"]
|
| 514 |
+
|
| 515 |
+
for file in documents["files"]:
|
| 516 |
+
if file["filename"] in data.files:
|
| 517 |
+
content_payload=f"""
|
| 518 |
+
|
| 519 |
+
FILENAME :{file["filename"]}
|
| 520 |
+
CONTENT : {file["content"]}
|
| 521 |
+
"""
|
| 522 |
+
content.append(content_payload)
|
| 523 |
+
dive=ResearchDeepDive(content=content)
|
| 524 |
+
payload={"type":"research","dive":dive,"files":data.files}
|
| 525 |
+
|
| 526 |
+
coll.update_one(
|
| 527 |
+
{"owner": data.owner},
|
| 528 |
+
{"$push": {"deepdive": payload}}
|
| 529 |
+
)
|
| 530 |
+
|
| 531 |
+
return {"deepdive":dive}
|
| 532 |
+
else:
|
| 533 |
+
|
| 534 |
+
return {"deepdive":None}
|
| 535 |
+
|
| 536 |
+
|
| 537 |
+
|