ashok2216 commited on
Commit
1788a8d
·
verified ·
1 Parent(s): 4473638

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -18
app.py CHANGED
@@ -29,25 +29,40 @@ config = Settings(
29
  chroma_db_impl="sqlite",
30
  )
31
 
32
- # Initialize ChromaDB client
 
 
 
33
  def setup_chromadb():
34
- try:
35
- client = chromadb.Client(config)
36
- collections = client.list_collections()
37
- print(f"Existing collections: {collections}")
38
- if "pdf_data" in [c.name for c in collections]:
39
- client.delete_collection("pdf_data")
40
- print("Existing collection 'pdf_data' deleted.")
41
- collection = client.create_collection(
42
- "pdf_data",
43
- embedding_function=chromadb.utils.embedding_functions.SentenceTransformerEmbeddingFunction(
44
- model_name="sentence-transformers/all-MiniLM-L6-v2"
45
- ),
46
- )
47
- return client, collection
48
- except Exception as e:
49
- print("Error setting up ChromaDB:", e)
50
- raise e
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
 
53
  # Step 2: Extract Text from PDF
 
29
  chroma_db_impl="sqlite",
30
  )
31
 
32
+
33
+ import chromadb
34
+
35
+ # Initialize persistent client with SQLite
36
  def setup_chromadb():
37
+ client = chromadb.PersistentClient(path="./chromadb_data")
38
+ collection = client.get_or_create_collection(
39
+ name="pdf_data",
40
+ embedding_function=chromadb.utils.embedding_functions.SentenceTransformerEmbeddingFunction(
41
+ model_name="sentence-transformers/all-MiniLM-L6-v2"
42
+ ),
43
+ )
44
+ return client, collection
45
+
46
+
47
+ # Initialize ChromaDB client
48
+ # def setup_chromadb():
49
+ # try:
50
+ # client = chromadb.Client(config)
51
+ # collections = client.list_collections()
52
+ # print(f"Existing collections: {collections}")
53
+ # if "pdf_data" in [c.name for c in collections]:
54
+ # client.delete_collection("pdf_data")
55
+ # print("Existing collection 'pdf_data' deleted.")
56
+ # collection = client.create_collection(
57
+ # "pdf_data",
58
+ # embedding_function=chromadb.utils.embedding_functions.SentenceTransformerEmbeddingFunction(
59
+ # model_name="sentence-transformers/all-MiniLM-L6-v2"
60
+ # ),
61
+ # )
62
+ # return client, collection
63
+ # except Exception as e:
64
+ # print("Error setting up ChromaDB:", e)
65
+ # raise e
66
 
67
 
68
  # Step 2: Extract Text from PDF