Mr-Geo commited on
Commit
5f6acb3
·
verified ·
1 Parent(s): 6e0a272

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
  from dotenv import load_dotenv
3
  from groq import Groq
4
  import chromadb
@@ -19,23 +20,27 @@ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
19
  hf_token = os.getenv("HF_TOKEN")
20
 
21
  def load_chroma_db():
22
- # Load from Hugging Face dataset
23
  print("Using ChromaDB from Hugging Face dataset...")
24
- # Download the database file from Hugging Face with authentication
25
- db_file_path = hf_hub_download(
 
26
  repo_id="Mr-Geo/chroma_db",
27
- filename="chroma.sqlite3",
28
  repo_type="dataset",
29
  use_auth_token=hf_token
30
  )
31
- print(f"Downloaded database file to: {db_file_path}")
 
 
 
 
 
32
 
33
- # Get the directory path of the downloaded file
34
- db_directory = os.path.dirname(db_file_path)
35
 
36
- # Initialize ChromaDB with the persistent client and point it to the downloaded database
37
  db = chromadb.PersistentClient(
38
- path=db_directory, # Use the directory where the file was downloaded
39
  settings=Settings(
40
  anonymized_telemetry=False,
41
  allow_reset=True,
 
1
  import os
2
+ import zipfile
3
  from dotenv import load_dotenv
4
  from groq import Groq
5
  import chromadb
 
20
  hf_token = os.getenv("HF_TOKEN")
21
 
22
  def load_chroma_db():
 
23
  print("Using ChromaDB from Hugging Face dataset...")
24
+
25
+ # Download the zipped database from Hugging Face
26
+ zip_path = hf_hub_download(
27
  repo_id="Mr-Geo/chroma_db",
28
+ filename="chroma_db.zip",
29
  repo_type="dataset",
30
  use_auth_token=hf_token
31
  )
32
+ print(f"Downloaded database zip to: {zip_path}")
33
+
34
+ # Extract to a temporary directory
35
+ extract_dir = "/tmp/chroma_db"
36
+ with zipfile.ZipFile(zip_path, 'r') as zip_ref:
37
+ zip_ref.extractall(extract_dir)
38
 
39
+ print(f"Extracted database to: {extract_dir}")
 
40
 
41
+ # Initialize ChromaDB with the extracted database
42
  db = chromadb.PersistentClient(
43
+ path=extract_dir,
44
  settings=Settings(
45
  anonymized_telemetry=False,
46
  allow_reset=True,