Chittrarasu commited on
Commit
21d405f
·
0 Parent(s):
Dockerfile ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use official Python base image
2
+ FROM python:3.11-slim
3
+
4
+ # Set the working directory
5
+ WORKDIR /app
6
+
7
+ # Copy all files to the container
8
+ COPY . /app
9
+
10
+ # Install dependencies
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ # Expose the port (Hugging Face uses port 7860 by default)
14
+ EXPOSE 7860
15
+
16
+ # Run the FastAPI server using uvicorn
17
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
README.md ADDED
File without changes
__pycache__/__init__.cpython-313.pyc ADDED
Binary file (131 Bytes). View file
 
__pycache__/main.cpython-313.pyc ADDED
Binary file (533 Bytes). View file
 
main.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from routes.sms_routes import router as sms_router
3
+
4
+ # Initialize FastAPI app
5
+ app = FastAPI
6
+
7
+ # Include the router for SMS endpoints
8
+ app.include_router(sms_router)
9
+
10
+ @app.get("/")
11
+ def home():
12
+
13
+ return {"message": "Welcome to embedded model"}
models/__init__.py ADDED
File without changes
models/model.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ from sentence_transformers import SentenceTransformer
2
+
3
+ # Load the pre-trained model once at startup
4
+ model = SentenceTransformer('Alibaba-NLP/gte-base-en-v1.5', trust_remote_code=True)
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ sentence-transformers
4
+ torch
5
+ scikit-learn
6
+ numpy
7
+ pandas
8
+ openpyxl
routes/__init__.py ADDED
File without changes
routes/__pycache__/__init__.cpython-313.pyc ADDED
Binary file (138 Bytes). View file
 
routes/__pycache__/sms_routes.cpython-313.pyc ADDED
Binary file (1.17 kB). View file
 
routes/sms_routes.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import APIRouter, HTTPException
2
+ from schema.pydantic_schema import SMSRequest, EmbeddingsResponse, EmbeddingResponse
3
+ from service.embedding_service import generate_embeddings
4
+
5
+ # Initialize Router
6
+ router = APIRouter()
7
+
8
+ @router.post("/get_embeddings/", response_model=EmbeddingsResponse)
9
+ async def get_embeddings(sms_request: SMSRequest):
10
+ # Check if the input list is not empty
11
+ if not sms_request.messages:
12
+ raise HTTPException(status_code=400, detail="No messages provided.")
13
+
14
+ # Generate embeddings
15
+ embeddings = generate_embeddings(sms_request.messages)
16
+
17
+ # Structure the response
18
+ response = [
19
+ EmbeddingResponse(message=msg, embedding=emb)
20
+ for msg, emb in zip(sms_request.messages, embeddings)
21
+ ]
22
+
23
+ return {"embeddings": response}
schema/__init__.py ADDED
File without changes
schema/__pycache__/__init__.cpython-313.pyc ADDED
Binary file (138 Bytes). View file
 
schema/__pycache__/pydantic_schema.cpython-313.pyc ADDED
Binary file (1.08 kB). View file
 
schema/pydantic_schema.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pydantic import BaseModel
2
+ from typing import List
3
+
4
+ # Request schema
5
+ class SMSRequest(BaseModel):
6
+ messages: List[str]
7
+
8
+ from pydantic import BaseModel
9
+ from typing import List
10
+
11
+ # Response schema for embedding vectors
12
+ class EmbeddingResponse(BaseModel):
13
+ message: str
14
+ embedding: List[float]
15
+
16
+ # Final response containing all embeddings
17
+ class EmbeddingsResponse(BaseModel):
18
+ embeddings: List[EmbeddingResponse]
service/__init__.py ADDED
File without changes
service/__pycache__/__init__.cpython-313.pyc ADDED
Binary file (139 Bytes). View file
 
service/__pycache__/embedding_service.cpython-313.pyc ADDED
Binary file (148 Bytes). View file
 
service/embedding_service.py ADDED
File without changes