Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -29,25 +29,40 @@ config = Settings(
|
|
29 |
chroma_db_impl="sqlite",
|
30 |
)
|
31 |
|
32 |
-
|
|
|
|
|
|
|
33 |
def setup_chromadb():
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|