Gaykar commited on
Commit
f8ab8c8
·
verified ·
1 Parent(s): 0387fb5

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +32 -0
  2. app.py +33 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.12-slim
2
+
3
+ # Set the working directory to /code
4
+ WORKDIR /code
5
+
6
+ # Copy the requirements.txt file into the container
7
+ COPY requirements.txt .
8
+
9
+ # Install the dependencies
10
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
+
12
+ # Set up a new user named "user" with user ID 1000
13
+ RUN useradd -m -u 1000 user
14
+
15
+ # Switch to the "user" user
16
+ USER user
17
+
18
+ # Set home to the user's home directory
19
+ ENV HOME=/home/user \
20
+ PATH=/home/user/.local/bin:$PATH
21
+
22
+ # Set the working directory to the user's home directory
23
+ WORKDIR $HOME/app
24
+
25
+ # Copy the current directory contents into the container at $HOME/app
26
+ COPY --chown=user . $HOME/app
27
+
28
+ # Expose the port FastAPI will run on
29
+ EXPOSE 7860
30
+
31
+ # Start the FastAPI app on port 7860 (HF Spaces default)
32
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from typing import List
4
+ from sentence_transformers import SentenceTransformer
5
+ import uvicorn
6
+
7
+ app = FastAPI(title="Medical Embedding Service")
8
+
9
+ # Load model ONCE at startup
10
+ print("Loading Medical RAG Model... this may take a moment.")
11
+ model = SentenceTransformer("Gaykar/all-MiniLM-L6-medical-rag")
12
+ print("Model loaded successfully!")
13
+
14
+ class QueryRequest(BaseModel):
15
+ text: str
16
+
17
+ class DocumentRequest(BaseModel):
18
+ texts: List[str]
19
+
20
+ @app.post("/embed_query")
21
+ async def embed_query(request: QueryRequest):
22
+ # Uses specialized encode_query for IR tasks
23
+ embedding = model.encode_query(request.text).tolist()
24
+ return {"embedding": embedding}
25
+
26
+ @app.post("/embed_docs")
27
+ async def embed_docs(request: DocumentRequest):
28
+ # Uses specialized encode_document for IR tasks
29
+ embeddings = model.encode_document(request.texts).tolist()
30
+ return {"embeddings": embeddings}
31
+
32
+ if __name__ == "__main__":
33
+ uvicorn.run(app, host="0.0.0.0", port=8001)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ sentence-transformers==5.0.0
2
+ fastapi==0.118.1
3
+ uvicorn==0.40.0