Spaces:
Paused
Paused
Commit
·
dd4c21a
1
Parent(s):
3b1fa6d
Finish app.py and requirements.txt
Browse files- app.py +32 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import chromadb
|
| 2 |
+
import gradio
|
| 3 |
+
import sentence_transformers
|
| 4 |
+
from chromadb.config import Settings
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
from sentence_transformers import SentenceTransformer
|
| 8 |
+
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
| 9 |
+
|
| 10 |
+
# Creating client
|
| 11 |
+
client = chromadb.PersistentClient(path="./chromadb")
|
| 12 |
+
collection = client.get_or_create_collection("my_collection")
|
| 13 |
+
# The above code snippet was created by chatGPT 5.0 at 1:55p on 11/17/25
|
| 14 |
+
|
| 15 |
+
print(collection.count())
|
| 16 |
+
|
| 17 |
+
# Define a search function
|
| 18 |
+
def semantic_search(query):
|
| 19 |
+
query_embedding = model.encode([query])
|
| 20 |
+
results = collection.query(query_embeddings=query_embedding.tolist(), n_results=1)
|
| 21 |
+
return "\n\n".join(results['documents'][0])
|
| 22 |
+
|
| 23 |
+
# Simple Gradio interface
|
| 24 |
+
demo = gr.Interface(
|
| 25 |
+
fn=semantic_search,
|
| 26 |
+
inputs=gr.Textbox(label="Enter your search query"),
|
| 27 |
+
outputs=gr.Textbox(label="Top Matches"),
|
| 28 |
+
title="Semantic Search Engine",
|
| 29 |
+
description="Search over your custom dataset using semantic similarity."
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nltk
|
| 2 |
+
sentence_transformers
|
| 3 |
+
chromadb
|
| 4 |
+
gradio
|