Add files using upload-large-folder tool
Browse files- .idea/workspace.xml +4 -4
- fastapi_app.py +57 -0
.idea/workspace.xml
CHANGED
|
@@ -71,7 +71,7 @@
|
|
| 71 |
<window_info id="Commit_Guest" show_stripe_button="false" />
|
| 72 |
<window_info id="Pull Requests" />
|
| 73 |
<window_info id="Learn" />
|
| 74 |
-
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.
|
| 75 |
<window_info id="Commit" order="1" weight="0.25" />
|
| 76 |
<window_info id="Structure" order="2" side_tool="true" weight="0.25" />
|
| 77 |
<window_info anchor="bottom" id="Database Changes" />
|
|
@@ -81,7 +81,7 @@
|
|
| 81 |
<window_info anchor="bottom" id="Version Control" order="0" />
|
| 82 |
<window_info anchor="bottom" id="Problems" order="1" />
|
| 83 |
<window_info anchor="bottom" id="Problems View" order="2" />
|
| 84 |
-
<window_info active="true" anchor="bottom" id="Terminal" order="3" visible="true" weight="0.
|
| 85 |
<window_info anchor="bottom" id="Services" order="4" />
|
| 86 |
<window_info anchor="bottom" id="Python Packages" order="5" weight="0.1" />
|
| 87 |
<window_info anchor="bottom" id="Debug" order="6" weight="0.29618055" />
|
|
@@ -97,7 +97,7 @@
|
|
| 97 |
<window_info anchor="right" id="Database" order="2" weight="0.25" />
|
| 98 |
<window_info anchor="right" id="Gradle" order="3" weight="0.25" />
|
| 99 |
<window_info anchor="right" id="Maven" order="4" weight="0.25" />
|
| 100 |
-
<window_info anchor="right" id="CodeGPT" order="5" weight="0.
|
| 101 |
<window_info anchor="right" id="Plots" order="6" weight="0.1" />
|
| 102 |
</layout>
|
| 103 |
</component>
|
|
@@ -187,7 +187,7 @@
|
|
| 187 |
<workItem from="1729970270429" duration="53000" />
|
| 188 |
<workItem from="1729970419018" duration="9867000" />
|
| 189 |
<workItem from="1730030408588" duration="2251000" />
|
| 190 |
-
<workItem from="1730037237796" duration="
|
| 191 |
</task>
|
| 192 |
<servers />
|
| 193 |
</component>
|
|
|
|
| 71 |
<window_info id="Commit_Guest" show_stripe_button="false" />
|
| 72 |
<window_info id="Pull Requests" />
|
| 73 |
<window_info id="Learn" />
|
| 74 |
+
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.28670636" />
|
| 75 |
<window_info id="Commit" order="1" weight="0.25" />
|
| 76 |
<window_info id="Structure" order="2" side_tool="true" weight="0.25" />
|
| 77 |
<window_info anchor="bottom" id="Database Changes" />
|
|
|
|
| 81 |
<window_info anchor="bottom" id="Version Control" order="0" />
|
| 82 |
<window_info anchor="bottom" id="Problems" order="1" />
|
| 83 |
<window_info anchor="bottom" id="Problems View" order="2" />
|
| 84 |
+
<window_info active="true" anchor="bottom" id="Terminal" order="3" visible="true" weight="0.27142859" />
|
| 85 |
<window_info anchor="bottom" id="Services" order="4" />
|
| 86 |
<window_info anchor="bottom" id="Python Packages" order="5" weight="0.1" />
|
| 87 |
<window_info anchor="bottom" id="Debug" order="6" weight="0.29618055" />
|
|
|
|
| 97 |
<window_info anchor="right" id="Database" order="2" weight="0.25" />
|
| 98 |
<window_info anchor="right" id="Gradle" order="3" weight="0.25" />
|
| 99 |
<window_info anchor="right" id="Maven" order="4" weight="0.25" />
|
| 100 |
+
<window_info active="true" anchor="right" id="CodeGPT" order="5" visible="true" weight="0.32969576" />
|
| 101 |
<window_info anchor="right" id="Plots" order="6" weight="0.1" />
|
| 102 |
</layout>
|
| 103 |
</component>
|
|
|
|
| 187 |
<workItem from="1729970270429" duration="53000" />
|
| 188 |
<workItem from="1729970419018" duration="9867000" />
|
| 189 |
<workItem from="1730030408588" duration="2251000" />
|
| 190 |
+
<workItem from="1730037237796" duration="32282000" />
|
| 191 |
</task>
|
| 192 |
<servers />
|
| 193 |
</component>
|
fastapi_app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from typing import List
|
| 4 |
+
import uvicorn
|
| 5 |
+
from medimageinsightmodel import MedImageInsight
|
| 6 |
+
import base64
|
| 7 |
+
|
| 8 |
+
# Initialize FastAPI app
|
| 9 |
+
app = FastAPI(title="Medical Image Analysis API")
|
| 10 |
+
|
| 11 |
+
# Initialize model
|
| 12 |
+
classifier = MedImageInsight(
|
| 13 |
+
model_dir="2024.09.27",
|
| 14 |
+
vision_model_name="medimageinsigt-v1.0.0.pt",
|
| 15 |
+
language_model_name="language_model.pth"
|
| 16 |
+
)
|
| 17 |
+
classifier.load_model()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class ClassificationRequest(BaseModel):
|
| 21 |
+
images: List[str] # Base64 encoded images
|
| 22 |
+
labels: List[str]
|
| 23 |
+
multilabel : bool = False
|
| 24 |
+
|
| 25 |
+
class EmbeddingRequest(BaseModel):
|
| 26 |
+
images: List[str] = None # Base64 encoded images
|
| 27 |
+
texts: List[str] = None
|
| 28 |
+
|
| 29 |
+
@app.post("/predict")
|
| 30 |
+
async def predict(request: ClassificationRequest):
|
| 31 |
+
try:
|
| 32 |
+
results = classifier.predict(
|
| 33 |
+
images=request.images,
|
| 34 |
+
labels=request.labels,
|
| 35 |
+
multilabel = request.multilabel
|
| 36 |
+
)
|
| 37 |
+
return {"predictions": results}
|
| 38 |
+
except Exception as e:
|
| 39 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 40 |
+
|
| 41 |
+
@app.post("/encode")
|
| 42 |
+
async def encode(request: EmbeddingRequest):
|
| 43 |
+
try:
|
| 44 |
+
results = classifier.encode(images=request.images, texts= request.texts)
|
| 45 |
+
results["image_embeddings"] = results["image_embeddings"].tolist() if results["image_embeddings"] is not None else None
|
| 46 |
+
results["text_embeddings"] = results["text_embeddings"].tolist() if results["text_embeddings"] is not None else None
|
| 47 |
+
|
| 48 |
+
return results
|
| 49 |
+
except Exception as e:
|
| 50 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 51 |
+
|
| 52 |
+
@app.get("/health")
|
| 53 |
+
async def health():
|
| 54 |
+
return {"status": "healthy"}
|
| 55 |
+
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|