Spaces:
Sleeping
Sleeping
Update server.py
Browse files
server.py
CHANGED
@@ -1,9 +1,51 @@
|
|
|
|
|
|
1 |
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from utilities.transcripts import VTTTranscriptLoader, DocumentEmbedder
|
3 |
|
4 |
+
class EmbeddingService:
|
5 |
+
def __init__(self, conf):
|
6 |
+
self.keys = self.get_keys()
|
7 |
+
self.conf = conf
|
8 |
|
9 |
+
|
10 |
+
def get_keys(self):
|
11 |
+
"Get keys required to set up loading"
|
12 |
+
return {
|
13 |
+
"pinecone": os.environ["PINECONE_TOKEN"],
|
14 |
+
"hugginface": os.environ["HUGGINFACE_TOKEN"],
|
15 |
+
"openai": "", # leaving this alone for future use.
|
16 |
+
}
|
17 |
+
|
18 |
+
|
19 |
+
def get_transcripts(self, files):
|
20 |
+
# Get filepaths and load them in document format
|
21 |
+
filepaths = [file.name for file in files]
|
22 |
+
loader = VTTTranscriptLoader(file_path)
|
23 |
+
results = loader.load()
|
24 |
+
|
25 |
+
return results
|
26 |
+
|
27 |
|
28 |
+
def run(self, files):
|
29 |
+
# gets the files, cleans them, and loads them into pinecone
|
30 |
+
results = get_transcripts(files)
|
31 |
+
|
32 |
+
doc_embedder = DocumentEmbedder(
|
33 |
+
api_keys=self.keys,
|
34 |
+
files=results,
|
35 |
+
embedding=self.conf["embeddings"]["embedding"],
|
36 |
+
index_name=self.conf["embeddings"]["index_name"],
|
37 |
+
)
|
38 |
+
|
39 |
+
# uploads them into pinecone
|
40 |
+
doc_embedder.embed()
|
41 |
+
|
42 |
+
return 0
|
43 |
+
|
44 |
+
|
45 |
+
class QAService:
|
46 |
+
def __init__(self, conf):
|
47 |
+
self.keys = get_keys()
|
48 |
+
self.conf = conf
|
49 |
+
|
50 |
+
def run():
|
51 |
+
return 0
|