File size: 775 Bytes
7430631
 
 
 
1f3c160
40e8576
7430631
a260b1b
dd6117e
be4dd45
 
 
 
 
 
 
 
60a8bbf
91bd2a8
108f832
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel, root_validator
from transformers import AutoModel
from typing import List
import os, platform , time



model = AutoModel.from_pretrained('jinaai/jina-embeddings-v2-base-en',  trust_remote_code=True)

app = FastAPI()

class Validation(BaseModel):
    prompt: List[str]


#Endpoint
@app.post("/jina_embedding")
async def generate_embeddings(item: Validation):
    start_time = time.time()  
    embeddings = model.encode(item.prompt).tolist()
    end_time = time.time()  
    time_taken = end_time - start_time  # Calculate the time taken

    return {
        "embeddings": embeddings,
        "time_taken": f"{time_taken:.2f} seconds",
        "Number_of_sentence_processed" : len(item.prompt)
    }