CoolFace
Apppublic

22pc05/Research_paper_embedding

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
main.py52 linesDownload Raw Back to root
1from fastapi import FastAPI2from pydantic import BaseModel3from InstructorEmbedding import INSTRUCTOR4import uvicorn5from typing import List6 7app=FastAPI()8 9#The model for input10class AbstractData(BaseModel):11    abstract:str12 13class embedOutput(BaseModel):14    embedding:List[float]15 16#Description of this api endpoint17def get_app_description():18    return (19        "Hello everyone."20        "This api allows you to send text as request parameter and you get vector embeddings of the" \21        "given text embedded using the InstructionXL model as response"22        "Use the '/embed' endpoint and provide the text in json"23    )24 25def instructionXL(abstract_data):26    embedding_model=INSTRUCTOR("hkunlp/instructor-xl")27    instruction="Represent the document for retrieval"28    embedding_vector=embedding_model.encode([[instruction,abstract_data]])29    print(type(embedding_vector))30    print(len(embedding_vector))31    # print(embedding_vector[0])32    return embedding_vector33 34 35 36@app.get("/")37async def root():38    return{"message":get_app_description()}39 40@app.post("/embed/")41async def embed_using_instruction(abstractData:AbstractData):42    embedding=instructionXL(abstractData.abstract)43    embedding=embedding.tolist()44    print(len(embedding))45    return{"embedding":embedding}46 47if __name__=='__main__':48    uvicorn.run('main:app',reload=True)49 50# query="Research"51# instructionXL(query)52