Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,8 @@ from chromadb.config import Settings
|
|
6 |
import torch
|
7 |
from sentence_transformers import CrossEncoder
|
8 |
import gradio as gr
|
9 |
-
from datetime import datetime
|
|
|
10 |
|
11 |
# Load environment variables and initialize clients
|
12 |
load_dotenv()
|
@@ -14,6 +15,23 @@ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
|
14 |
client = Groq(api_key=GROQ_API_KEY)
|
15 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
def initialize_system():
|
18 |
chroma_client = chromadb.PersistentClient(
|
19 |
path="./chroma_db",
|
|
|
6 |
import torch
|
7 |
from sentence_transformers import CrossEncoder
|
8 |
import gradio as gr
|
9 |
+
from datetime import datetime
|
10 |
+
from huggingface_hub import hf_hub_download
|
11 |
|
12 |
# Load environment variables and initialize clients
|
13 |
load_dotenv()
|
|
|
15 |
client = Groq(api_key=GROQ_API_KEY)
|
16 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
17 |
|
18 |
+
def load_chroma_db():
|
19 |
+
# Load from Hugging Face dataset
|
20 |
+
print("Using ChromaDB from Hugging Face dataset...")
|
21 |
+
# Download the database file from Hugging Face
|
22 |
+
db_file_path = hf_hub_download(repo_id="Mr-Geo/chroma_db", filename="chroma.sqlite3")
|
23 |
+
# Initialize your ChromaDB with the downloaded file
|
24 |
+
db = chromadb.Client(path=db_file_path)
|
25 |
+
return db
|
26 |
+
|
27 |
+
# Check if running locally
|
28 |
+
if os.path.exists("./chroma_db/chroma.sqlite3"):
|
29 |
+
print("Using local ChromaDB setup...")
|
30 |
+
db = chromadb.Client(path="./chroma_db/chroma.sqlite3") # Adjust the path as needed
|
31 |
+
else:
|
32 |
+
# Load from Hugging Face dataset
|
33 |
+
db = load_chroma_db()
|
34 |
+
|
35 |
def initialize_system():
|
36 |
chroma_client = chromadb.PersistentClient(
|
37 |
path="./chroma_db",
|