Spaces:
Sleeping
Sleeping
Tiffany Degbotse commited on
Commit ·
d74e01c
0
Parent(s):
Initial commit - semantic search engine
Browse files- Readme.md +7 -0
- app.py +28 -0
- requirements.txt +0 -0
Readme.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Semantic Search Engine
|
| 2 |
+
|
| 3 |
+
A simple semantic search app using Sentence Transformers and ChromaDB.
|
| 4 |
+
|
| 5 |
+
## Run locally
|
| 6 |
+
pip install -r requirements.txt
|
| 7 |
+
python app.py
|
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 10 |
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
| 11 |
+
|
| 12 |
+
# Define search
|
| 13 |
+
def semantic_search(query):
|
| 14 |
+
query_embedding = model.encode([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__":
|
| 28 |
+
demo.launch()
|
requirements.txt
ADDED
|
File without changes
|