-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
23 changed files
with
184 additions
and
227 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Use an official Python runtime as a parent image | ||
FROM python:3.9-slim | ||
|
||
WORKDIR /app | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
build-essential \ | ||
git \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install requirements | ||
COPY requirements.txt requirements.txt | ||
RUN pip3 install -r requirements.txt | ||
|
||
RUN apt-get update && apt-get install -y wget | ||
# Download necessary files | ||
RUN gdown "https://drive.google.com/uc?id=1VlLcGWmDKAoK3aUthVXOFxzOdgzf-SNo" -O Testing1.csv | ||
|
||
# Clone necessary repositories | ||
RUN apt-get update && apt-get install -y git | ||
RUN git clone https://huggingface.co/GautamR/colbert_agri_embeddings | ||
|
||
# Copy the rest of the application code to the working directory | ||
COPY . /app/ | ||
EXPOSE 8000 | ||
# Set the entrypoint for the container | ||
CMD ["hypercorn", "--bind", "0.0.0.0:8000", "api:app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .request import ModelRequest | ||
from .request import Model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from model import Model | ||
from request import ModelRequest | ||
from quart import Quart, request | ||
import aiohttp | ||
import pandas as pd | ||
import gdown | ||
|
||
app = Quart(__name__) | ||
|
||
model = None | ||
|
||
@app.before_serving | ||
async def startup(): | ||
app.client = aiohttp.ClientSession() | ||
global model | ||
model = Model(app) | ||
|
||
@app.route('/', methods=['POST']) | ||
async def embed(): | ||
global model | ||
data = await request.get_json() | ||
req = ModelRequest(**data) | ||
return await model.inference(req) | ||
|
||
if __name__ == "__main__": | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pandas as pd | ||
from ragatouille import RAGPretrainedModel | ||
from request import ModelRequest | ||
from colbert import Indexer, Searcher | ||
from colbert.infra import Run, RunConfig, ColBERTConfig | ||
from colbert.data import Queries, Collection | ||
|
||
|
||
|
||
class Model(): | ||
def __new__(cls, context): | ||
cls.context = context | ||
if not hasattr(cls, 'instance'): | ||
cls.instance = super(Model, cls).__new__(cls) | ||
# Initialize Colbert | ||
cls.df = pd.read_csv('/Testing1.csv') | ||
cls.df['PID'] = cls.df.index.astype(str) | ||
with Run().context(RunConfig(experiment='notebook')): | ||
cls.searcher = Searcher(index='/colbert_agri_embeddings/', collection=cls.df['content'].to_list()) | ||
print(cls.df.columns) | ||
|
||
return cls.instance | ||
|
||
async def inference(self, request: ModelRequest): | ||
query = request.text | ||
k = request.k | ||
column_returned = 'id' | ||
results = self.searcher.search(query, k) | ||
searched_ids = self.df.loc[results[0], column_returned].to_list() | ||
searched_content = self.df.loc[results[0], 'content'].to_list() | ||
return {"ids": searched_ids, "content": searched_content, "scores": results[2]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import requests | ||
import json | ||
|
||
|
||
class ModelRequest(): | ||
def __init__(self, text, k ): | ||
self.text = text | ||
self.k = k | ||
|
||
def to_json(self): | ||
return json.dumps(self, default=lambda o: o.__dict__, | ||
sort_keys=True, indent=4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
torch | ||
scikit-learn | ||
quart | ||
aiohttp | ||
pandas | ||
faiss-gpu | ||
datasets | ||
gdown | ||
ragatouille | ||
langchain-openai | ||
colbert-ai | ||
gdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
torch==2.0.1 --index-url https://download.pytorch.org/whl/cpu | ||
torch | ||
quart | ||
aiohttp | ||
InstructorEmbedding | ||
wget | ||
pandas | ||
tqdm | ||
sentence_transformers | ||
sentence-transformers==2.2.2 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.