This repository was archived by the owner on Oct 22, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +70
-3
lines changed
Expand file tree Collapse file tree 5 files changed +70
-3
lines changed Original file line number Diff line number Diff line change 4848# pytest
4949* pytest_cache
5050
51+ # Credentials
5152key_openai.txt
53+
54+ # Models saved locally
55+ models /
Original file line number Diff line number Diff line change @@ -36,6 +36,50 @@ To run REMO, you will need the following:
36362 . Interact with the API using a REST client or web browser: ` http://localhost:8000 `
3737
3838
39+ ## Models
40+
41+ ### Embedding Model
42+
43+ REMO currently uses the
44+ Universal Sentence Encoder v5 for generating embeddings.
45+
46+ #### Loading from TensorFlow Hub
47+
48+ This is the default option.
49+
50+ When
51+
52+ ``` python
53+ ARE_YOU_TESTING__LOAD_MODEL_LOCAL = False
54+ ```
55+
56+ in file ` utils.py ` , the model is loaded from TensorFlow Hub.
57+
58+ #### Loading from a local file
59+
60+ Downloading the model from TensorFlow Hub every time you need to spin up
61+ the microservice would be expensive and time-consuming.
62+
63+ 1 . Download the ` .tar.gz ` file from
64+ TensorFlow Hub: https://tfhub.dev/google/universal-sentence-encoder-large/5
65+
66+ ![ img.png] ( docs/images/embedding_local_1.png )
67+
68+ 2 . Extract the file to the folder
69+ ```
70+ models/universal-sentence-encoder-large_5/
71+ ```
72+ with
73+ ``` shell
74+ tar -xvzf universal-sentence-encoder-large_5.tar.gz
75+ ```
76+
77+ 3 . Set
78+ ``` python
79+ ARE_YOU_TESTING__LOAD_MODEL_LOCAL = True
80+ ```
81+ in file ` utils.py ` .
82+
3983## API Endpoints
4084
4185- ** POST /add_message** : Add a new message to REMO. Speaker, timestamp, and content required.
Original file line number Diff line number Diff line change 11from fastapi import FastAPI
22import utils
33import os
4+ import uvicorn
45
56app = FastAPI ()
67root_folder = os .getcwd ()
@@ -48,3 +49,7 @@ async def maintain_tree():
4849 utils .maintain_tree (root_folder )
4950
5051 return {"detail" : "Tree maintenance completed" }
52+
53+
54+ if __name__ == '__main__' :
55+ uvicorn .run (app , host = '0.0.0.0' , port = 8000 )
Original file line number Diff line number Diff line change 11import os
2+ from pathlib import Path
3+
24import yaml
35import shutil
46import openai
79from typing import Dict , Any , List
810from sklearn .metrics .pairwise import cosine_similarity
911from sklearn .cluster import KMeans
12+ import tensorflow as tf
1013import tensorflow_hub as hub
1114
1215
13- embedding_model = hub .load (
14- "https://tfhub.dev/google/universal-sentence-encoder-large/5"
15- )
16+ ARE_YOU_TESTING__LOAD_MODEL_LOCAL = True
17+
18+ ROOT_REPO_PATH = Path ().parent .absolute ()
19+
20+ if ARE_YOU_TESTING__LOAD_MODEL_LOCAL :
21+ embedding_model = tf .saved_model .load (
22+ ROOT_REPO_PATH
23+ / "models/universal-sentence-encoder-large_5"
24+ )
25+
26+ else :
27+ embedding_model = hub .load (
28+ "https://tfhub.dev/google/universal-sentence-encoder-large/5"
29+ )
1630
1731
1832def open_file (filepath ):
You can’t perform that action at this time.
0 commit comments