Update app.py
Browse files
app.py
CHANGED
|
@@ -4,9 +4,22 @@ from langchain.text_splitter import CharacterTextSplitter
|
|
| 4 |
import chromadb
|
| 5 |
import chromadb.config
|
| 6 |
from chromadb.config import Settings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def get_context(query_text):
|
| 12 |
query_emb = st_model.encode(query_text)
|
|
@@ -54,7 +67,6 @@ def upload_pdf(file):
|
|
| 54 |
ids = [str(uuid.uuid1()) for _ in doc_emb]
|
| 55 |
|
| 56 |
client = chromadb.Client()
|
| 57 |
-
# Create collection. get_collection, get_or_create_collection, delete_collection also available!
|
| 58 |
collection = client.create_collection("test_db")
|
| 59 |
|
| 60 |
collection.add(
|
|
@@ -66,21 +78,10 @@ def upload_pdf(file):
|
|
| 66 |
return 'hello'
|
| 67 |
|
| 68 |
|
| 69 |
-
from transformers import T5ForConditionalGeneration, AutoTokenizer
|
| 70 |
-
import torch
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
model_name = 'google/flan-t5-base'
|
| 74 |
|
| 75 |
-
model = T5ForConditionalGeneration.from_pretrained(model_name, device_map='auto', offload_folder="offload")
|
| 76 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 77 |
|
| 78 |
-
import uuid
|
| 79 |
-
from sentence_transformers import SentenceTransformer
|
| 80 |
|
| 81 |
-
ST_name = 'sentence-transformers/sentence-t5-base'
|
| 82 |
|
| 83 |
-
st_model = SentenceTransformer(ST_name)
|
| 84 |
|
| 85 |
|
| 86 |
|
|
|
|
| 4 |
import chromadb
|
| 5 |
import chromadb.config
|
| 6 |
from chromadb.config import Settings
|
| 7 |
+
from transformers import T5ForConditionalGeneration, AutoTokenizer
|
| 8 |
+
import torch
|
| 9 |
+
import gradio as gr
|
| 10 |
+
import uuid
|
| 11 |
+
from sentence_transformers import SentenceTransformer
|
| 12 |
+
|
| 13 |
+
model_name = 'google/flan-t5-base'
|
| 14 |
+
model = T5ForConditionalGeneration.from_pretrained(model_name, device_map='auto', offload_folder="offload")
|
| 15 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 16 |
+
print('flan read')
|
| 17 |
|
| 18 |
|
| 19 |
+
ST_name = 'sentence-transformers/sentence-t5-base'
|
| 20 |
+
st_model = SentenceTransformer(ST_name)
|
| 21 |
+
print('sentence read')
|
| 22 |
+
|
| 23 |
|
| 24 |
def get_context(query_text):
|
| 25 |
query_emb = st_model.encode(query_text)
|
|
|
|
| 67 |
ids = [str(uuid.uuid1()) for _ in doc_emb]
|
| 68 |
|
| 69 |
client = chromadb.Client()
|
|
|
|
| 70 |
collection = client.create_collection("test_db")
|
| 71 |
|
| 72 |
collection.add(
|
|
|
|
| 78 |
return 'hello'
|
| 79 |
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
|
|
|
|
|
|
| 82 |
|
|
|
|
|
|
|
| 83 |
|
|
|
|
| 84 |
|
|
|
|
| 85 |
|
| 86 |
|
| 87 |
|