DanielIglesias97 commited on
Commit
9fa6c15
·
1 Parent(s): 70d74ca

First upload to the repository.

Browse files
Files changed (5) hide show
  1. .gitignore +1 -0
  2. Dockerfile +18 -0
  3. main_service.py +22 -0
  4. requirements.txt +3 -0
  5. utils_model.py +49 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ __pycache__/
Dockerfile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.12-slim AS base
2
+
3
+ RUN apt-get update && apt-get install -y git
4
+
5
+ RUN useradd -m -u 1000 user
6
+ USER user
7
+ ENV HOME=/home/user \
8
+ PATH=/home/user/.local/bin:$PATH
9
+
10
+ WORKDIR $HOME/app
11
+
12
+ COPY --chown=user . $HOME/app
13
+
14
+ COPY requirements.txt .
15
+
16
+ RUN pip3 install -r requirements.txt
17
+
18
+ COPY . .
main_service.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from utils_model import ModelFactory
3
+
4
+ def retrieve_embeddings(input_text_query):
5
+ model_type = 'mock'
6
+ model_factory_obj = ModelFactory()
7
+ model = model_factory_obj.create_model(model_type)
8
+
9
+ query_embeddings = model.retrieve_embeddings(input_text_query)
10
+
11
+ return query_embeddings
12
+
13
+ def build():
14
+ app = gr.Interface(fn=retrieve_embeddings, inputs="text", outputs="dataframe")
15
+
16
+ return app
17
+
18
+ def run(app):
19
+ app.launch(server_name='0.0.0.0')
20
+
21
+ app = build()
22
+ run(app)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio==5.37.0
2
+ numpy==2.3.1
3
+ pandas==2.3.1
utils_model.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pandas as pd
3
+ # from sentence_transformers import SentenceTransformer
4
+
5
+ class ModelFactory():
6
+
7
+ def __init__(self):
8
+ pass
9
+
10
+ def create_model(self, model_type):
11
+ model = None
12
+
13
+ if (model_type=='mock'):
14
+ model = MockModel()
15
+
16
+ # if (model_type=='all-MiniLM-L6-v2'):
17
+ # model = MiniLM_L6_v2_Model()
18
+
19
+ return model
20
+
21
+ class BaseModel():
22
+
23
+ def __init__(self):
24
+ pass
25
+
26
+ def retrieve_embeddings(self, input_text):
27
+ pass
28
+
29
+ class MockModel(BaseModel):
30
+
31
+ def __init__(self):
32
+ pass
33
+
34
+ def retrieve_embeddings(self, input_text):
35
+ random_embeddings = np.random.randint(256, size=(370))/256
36
+
37
+ return pd.DataFrame(random_embeddings)
38
+
39
+ # class MiniLM_L6_v2_Model(BaseModel):
40
+
41
+ # def __init__(self):
42
+ # self.model = SentenceTransformer('all-MiniLM-L6-v2')
43
+
44
+ # def retrieve_embeddings(self, input_text):
45
+ # embeddings = self.model.encode(input_text, batch_size=32)
46
+ # embeddings *= 255
47
+ # embeddings = embeddings.astype(np.uint8).tolist()
48
+
49
+ # return embeddings