Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -24,30 +24,7 @@ SERVICE_ACCOUNT_FILE = r"C:\Users\bhagy\AI\credentials.json"
|
|
24 |
|
25 |
csv_file_path = r"C:\Users\bhagy\OneDrive\Desktop\INFOSYS PROJECT\900_products_dataset.csv"
|
26 |
|
27 |
-
|
28 |
-
class CustomEmbeddingFunction:
|
29 |
-
def __init__(self, model_name="sentence-transformers/all-MiniLM-L6-v2"):
|
30 |
-
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
|
31 |
-
self.model = AutoModel.from_pretrained(model_name)
|
32 |
-
|
33 |
-
def __call__(self, text):
|
34 |
-
inputs = self.tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
|
35 |
-
with torch.no_grad():
|
36 |
-
outputs = self.model(**inputs)
|
37 |
-
embeddings = outputs.last_hidden_state.mean(dim=1).squeeze().numpy()
|
38 |
-
return embeddings
|
39 |
-
|
40 |
-
# Initialize components
|
41 |
-
sentiment_pipeline = pipeline("sentiment-analysis")
|
42 |
-
chroma_client = Client(Settings(persist_directory="chromadb_storage"))
|
43 |
-
embedding_fn = CustomEmbeddingFunction()
|
44 |
-
collection_name = "crm_data"
|
45 |
-
|
46 |
-
try:
|
47 |
-
collection = chroma_client.get_collection(collection_name)
|
48 |
-
except Exception:
|
49 |
-
collection = chroma_client.create_collection(collection_name)
|
50 |
-
|
51 |
def get_google_sheets_service():
|
52 |
creds = Credentials.from_service_account_file(
|
53 |
SERVICE_ACCOUNT_FILE,
|
@@ -176,7 +153,27 @@ def query_crm_data_with_context(prompt, top_k=3):
|
|
176 |
return ["Error in querying recommendations."]
|
177 |
|
178 |
|
|
|
|
|
|
|
|
|
179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
sentence_model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
181 |
faiss_index = faiss.IndexFlatL2(384)
|
182 |
|
|
|
24 |
|
25 |
csv_file_path = r"C:\Users\bhagy\OneDrive\Desktop\INFOSYS PROJECT\900_products_dataset.csv"
|
26 |
|
27 |
+
# sentiment_pipeline = pipeline("sentiment-analysis")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
def get_google_sheets_service():
|
29 |
creds = Credentials.from_service_account_file(
|
30 |
SERVICE_ACCOUNT_FILE,
|
|
|
153 |
return ["Error in querying recommendations."]
|
154 |
|
155 |
|
156 |
+
class CustomEmbeddingFunction:
|
157 |
+
def __init__(self, model_name="sentence-transformers/all-MiniLM-L6-v2"):
|
158 |
+
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
|
159 |
+
self.model = AutoModel.from_pretrained(model_name)
|
160 |
|
161 |
+
def __call__(self, text):
|
162 |
+
inputs = self.tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
|
163 |
+
with torch.no_grad():
|
164 |
+
outputs = self.model(**inputs)
|
165 |
+
embeddings = outputs.last_hidden_state.mean(dim=1).squeeze().numpy()
|
166 |
+
return embeddings
|
167 |
+
|
168 |
+
chroma_client = Client(Settings(persist_directory="chromadb_storage"))
|
169 |
+
embedding_fn = CustomEmbeddingFunction()
|
170 |
+
collection_name = "crm_data"
|
171 |
+
|
172 |
+
try:
|
173 |
+
collection = chroma_client.get_collection(collection_name)
|
174 |
+
except Exception:
|
175 |
+
collection = chroma_client.create_collection(collection_name)
|
176 |
+
|
177 |
sentence_model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
178 |
faiss_index = faiss.IndexFlatL2(384)
|
179 |
|