tharu22 commited on
Commit
304c996
·
0 Parent(s):
Files changed (5) hide show
  1. Dockerfile +20 -0
  2. README.md +8 -0
  3. __pycache__/main.cpython-313.pyc +0 -0
  4. main.py +32 -0
  5. requirements.txt +9 -0
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use an official Python base image
2
+ FROM python:3.10-slim
3
+
4
+ # Set the working directory inside the container
5
+ WORKDIR /app
6
+
7
+ # Copy the requirements file
8
+ COPY requirements.txt .
9
+
10
+ # Install dependencies
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ # Copy the entire app to the container
14
+ COPY . .
15
+
16
+ # Expose FastAPI's default port
17
+ EXPOSE 7860
18
+
19
+ # Run FastAPI with Uvicorn
20
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
README.md ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Embeddings RestAPI
3
+ emoji: 🏆
4
+ colorFrom: blue
5
+ colorTo: gray
6
+ sdk: docker
7
+ pinned: false
8
+ ---
__pycache__/main.cpython-313.pyc ADDED
Binary file (1.51 kB). View file
 
main.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from sentence_transformers import SentenceTransformer
4
+ import numpy as np
5
+
6
+ # Initialize FastAPI app
7
+ app = FastAPI()
8
+
9
+ from sentence_transformers import SentenceTransformer
10
+
11
+ embedding_model = SentenceTransformer('Alibaba-NLP/gte-base-en-v1.5', trust_remote_code=True)
12
+
13
+
14
+ # Define request body structure
15
+ class TextRequest(BaseModel):
16
+ text: str
17
+
18
+ # Define response structure
19
+ class EmbeddingResponse(BaseModel):
20
+ dimensions: int
21
+ embedding: list[float]
22
+
23
+ # Create API endpoint
24
+ @app.post("/get_embedding", response_model=EmbeddingResponse)
25
+ async def get_embedding(request: TextRequest):
26
+ # Generate embedding
27
+ embedding = embedding_model.encode([request.text])[0] # Extract first item
28
+
29
+ # Convert to list and return response
30
+ return {"dimensions": len(embedding), "embedding": embedding.tolist()}
31
+
32
+ # Run the API using: uvicorn app:app --host 0.0.0.0 --port 8000
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ fastapi==0.100.0
2
+ uvicorn==0.22.0
3
+ pandas==1.5.3
4
+ openpyxl==3.1.2
5
+ scikit-learn==1.2.2
6
+ sentence-transformers==2.2.2
7
+ numpy==1.23.5
8
+ pydantic==1.10.8
9
+ torch==2.0.1 # Required for sentence-transformers