bhagyabonam commited on
Commit
a8b34c0
·
verified ·
1 Parent(s): 8030591

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -27
app.py CHANGED
@@ -21,16 +21,10 @@ SPREADSHEET_ID = "1CsBub3Jlwyo7WHMQty6SDnBShIZMjl5XTVSoOKrxZhc"
21
  RANGE_NAME = 'Sheet1!A1:E'
22
  SERVICE_ACCOUNT_FILE = r"C:\Users\bhagy\AI\credentials.json"
23
 
 
24
  csv_file_path = r"C:\Users\bhagy\OneDrive\Desktop\INFOSYS PROJECT\900_products_dataset.csv"
25
 
26
- persist_dir = r"C:\Users\bhagy\OneDrive\Desktop\INFOSYS PROJECT\chromadb_storage"
27
- os.makedirs(persist_dir, exist_ok=True) # Ensure the directory exists
28
- print(f"Persistence directory: {persist_dir}")
29
 
30
- chroma_client = Client(Settings(
31
- persist_directory=persist_dir, # Use /tmp/ for Hugging Face Spaces
32
- allow_reset=True # Enable reset to prevent database issues
33
- ))
34
  class CustomEmbeddingFunction:
35
  def __init__(self, model_name="sentence-transformers/all-MiniLM-L6-v2"):
36
  self.tokenizer = AutoTokenizer.from_pretrained(model_name)
@@ -43,12 +37,9 @@ class CustomEmbeddingFunction:
43
  embeddings = outputs.last_hidden_state.mean(dim=1).squeeze().numpy()
44
  return embeddings
45
 
46
- sentiment_pipeline = pipeline("sentiment-analysis")
47
- # chroma_client = Client(Settings(
48
- # persist_directory="/tmp/chromadb_storage", # Directory to store ChromaDB data
49
- # allow_reset=True # Enable reset to prevent database issues
50
- # ))
51
 
 
 
52
  embedding_fn = CustomEmbeddingFunction()
53
  collection_name = "crm_data"
54
 
@@ -57,20 +48,6 @@ try:
57
  except Exception:
58
  collection = chroma_client.create_collection(collection_name)
59
 
60
- # chroma_client = Client(Settings(persist_directory="chromadb_storage"))
61
- # chroma_client = Client(Settings(
62
- # persist_directory="/home/user/app/chromadb_storage",
63
- # tenant="default_tenant",
64
- # database="default_db"
65
- # ))
66
- # embedding_fn = CustomEmbeddingFunction()
67
- # collection_name = "crm_data"
68
-
69
- # try:
70
- # collection = chroma_client.get_collection(collection_name)
71
- # except Exception:
72
- # collection = chroma_client.create_collection(collection_name)
73
-
74
  def get_google_sheets_service():
75
  creds = Credentials.from_service_account_file(
76
  SERVICE_ACCOUNT_FILE,
@@ -107,7 +84,7 @@ def update_google_sheet(transcribed_text, sentiment,objection, recommendations,o
107
 
108
  load_dotenv()
109
  hf_token= os.getenv("HUGGINGFACE_TOKEN")
110
- # login(token=huggingface_api_key)
111
  if not hf_token:
112
  raise ValueError("Hugging Face API key not found! Please set the HUGGINGFACE_TOKEN variable.")
113
  print(f"API Key Loaded: {hf_token[:5]}****")
@@ -202,6 +179,7 @@ def query_crm_data_with_context(prompt, top_k=3):
202
  return ["Error in querying recommendations."]
203
 
204
 
 
205
  sentence_model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
206
  faiss_index = faiss.IndexFlatL2(384)
207
 
 
21
  RANGE_NAME = 'Sheet1!A1:E'
22
  SERVICE_ACCOUNT_FILE = r"C:\Users\bhagy\AI\credentials.json"
23
 
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)
 
37
  embeddings = outputs.last_hidden_state.mean(dim=1).squeeze().numpy()
38
  return embeddings
39
 
 
 
 
 
 
40
 
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
 
 
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,
 
84
 
85
  load_dotenv()
86
  hf_token= os.getenv("HUGGINGFACE_TOKEN")
87
+ login(token=hf_token)
88
  if not hf_token:
89
  raise ValueError("Hugging Face API key not found! Please set the HUGGINGFACE_TOKEN variable.")
90
  print(f"API Key Loaded: {hf_token[:5]}****")
 
179
  return ["Error in querying recommendations."]
180
 
181
 
182
+
183
  sentence_model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
184
  faiss_index = faiss.IndexFlatL2(384)
185