bhagyabonam commited on
Commit
829a348
·
verified ·
1 Parent(s): 0683725

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -26,9 +26,9 @@ SERVICE_ACCOUNT_FILE = r"C:\Users\bhagy\AI\credentials.json"
26
  csv_file_path = r"C:\Users\bhagy\OneDrive\Desktop\INFOSYS PROJECT\900_products_dataset.csv"
27
 
28
 
29
- storage_path = "chromadb_storage"
30
- if not os.path.exists(storage_path):
31
- os.makedirs(storage_path)
32
 
33
  # Define Custom Embedding Function
34
  class CustomEmbeddingFunction:
@@ -47,22 +47,33 @@ class CustomEmbeddingFunction:
47
  sentiment_pipeline = pipeline("sentiment-analysis")
48
 
49
  # Ensure no corrupted ChromaDB storage
 
 
50
  try:
 
51
  chroma_client = Client(Settings(persist_directory=storage_path))
52
- except ValueError:
53
- print("ChromaDB storage may be corrupted. Resetting storage...")
 
 
 
54
  shutil.rmtree(storage_path, ignore_errors=True)
55
  os.makedirs(storage_path)
 
 
56
  chroma_client = Client(Settings(persist_directory=storage_path))
57
 
58
  # Initialize Embedding Function
59
  embedding_fn = CustomEmbeddingFunction()
 
 
60
  collection_name = "crm_data"
61
 
62
  # Try fetching collection; create if missing
63
  try:
64
  collection = chroma_client.get_collection(collection_name)
65
- except Exception:
 
66
  collection = chroma_client.create_collection(collection_name)
67
 
68
  def get_google_sheets_service():
 
26
  csv_file_path = r"C:\Users\bhagy\OneDrive\Desktop\INFOSYS PROJECT\900_products_dataset.csv"
27
 
28
 
29
+ # storage_path = "chromadb_storage"
30
+ # if not os.path.exists(storage_path):
31
+ # os.makedirs(storage_path)
32
 
33
  # Define Custom Embedding Function
34
  class CustomEmbeddingFunction:
 
47
  sentiment_pipeline = pipeline("sentiment-analysis")
48
 
49
  # Ensure no corrupted ChromaDB storage
50
+ storage_path = r"C:\Users\bhagy\OneDrive\Desktop\INFOSYS PROJECT\chromadb_storage" # Replace with the correct path
51
+
52
  try:
53
+ # Initialize ChromaDB Client
54
  chroma_client = Client(Settings(persist_directory=storage_path))
55
+ except ValueError as e:
56
+ print(f"Error: {str(e)}")
57
+ print("ChromaDB storage may be corrupted or the tenant might be missing. Resetting storage...")
58
+
59
+ # Remove the existing storage path and recreate it
60
  shutil.rmtree(storage_path, ignore_errors=True)
61
  os.makedirs(storage_path)
62
+
63
+ # Try reconnecting to ChromaDB after reset
64
  chroma_client = Client(Settings(persist_directory=storage_path))
65
 
66
  # Initialize Embedding Function
67
  embedding_fn = CustomEmbeddingFunction()
68
+
69
+ # Define collection name
70
  collection_name = "crm_data"
71
 
72
  # Try fetching collection; create if missing
73
  try:
74
  collection = chroma_client.get_collection(collection_name)
75
+ except Exception as e:
76
+ print(f"Error fetching collection: {str(e)}. Creating new collection...")
77
  collection = chroma_client.create_collection(collection_name)
78
 
79
  def get_google_sheets_service():