tiffany101 commited on
Commit
f92c2ba
·
verified ·
1 Parent(s): 2d0ad67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -1,9 +1,23 @@
1
- from sentence_transformers import SentenceTransformer
2
  from chromadb import PersistentClient
 
3
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- # Load ChromaDB
6
- client = PersistentClient(path="chromadb")
7
  collection = client.get_collection("my_collection")
8
 
9
  # Load embedding model
@@ -15,13 +29,13 @@ def semantic_search(query):
15
  results = collection.query(query_embeddings=query_embedding.tolist(), n_results=3)
16
  return "\n\n".join(results["documents"][0])
17
 
18
- # Launch Gradio interface
19
  demo = gr.Interface(
20
  fn=semantic_search,
21
  inputs=gr.Textbox(label="Enter your search query"),
22
  outputs=gr.Textbox(label="Top Matches"),
23
  title="Semantic Search Engine",
24
- description="Search over your custom dataset using semantic similarity."
25
  )
26
 
27
  if __name__ == "__main__":
 
1
+ from huggingface_hub import hf_hub_download
2
  from chromadb import PersistentClient
3
+ from sentence_transformers import SentenceTransformer
4
  import gradio as gr
5
+ import os
6
+
7
+ # Download your chroma.sqlite3 from the Hugging Face dataset
8
+ persist_dir = "chromadb"
9
+ os.makedirs(persist_dir, exist_ok=True)
10
+ db_path = os.path.join(persist_dir, "chroma.sqlite3")
11
+
12
+ if not os.path.exists(db_path):
13
+ print("⬇️ Downloading ChromaDB from Hugging Face Dataset...")
14
+ db_path = hf_hub_download(
15
+ repo_id="tiffany101/my-chromadb", # <-- replace with your dataset name
16
+ filename="chroma.sqlite3"
17
+ )
18
 
19
+ # Load the ChromaDB
20
+ client = PersistentClient(path=persist_dir)
21
  collection = client.get_collection("my_collection")
22
 
23
  # Load embedding model
 
29
  results = collection.query(query_embeddings=query_embedding.tolist(), n_results=3)
30
  return "\n\n".join(results["documents"][0])
31
 
32
+ # Launch Gradio app
33
  demo = gr.Interface(
34
  fn=semantic_search,
35
  inputs=gr.Textbox(label="Enter your search query"),
36
  outputs=gr.Textbox(label="Top Matches"),
37
  title="Semantic Search Engine",
38
+ description="Search over your dataset using semantic similarity."
39
  )
40
 
41
  if __name__ == "__main__":