Spaces:
Running
Running
adding files
Browse files- app.py +3 -3
- embeddings_quran.pkl → embeddings_hadith.pkl +2 -2
- hadith_combined.csv +0 -0
- quran_data.csv +0 -0
app.py
CHANGED
@@ -5,14 +5,14 @@ from sklearn.neighbors import NearestNeighbors
|
|
5 |
import gradio as gr
|
6 |
|
7 |
# Load the embeddings from the file
|
8 |
-
with open('
|
9 |
embeddings = pickle.load(f)
|
10 |
|
11 |
# Initialize the Nearest Neighbors model with cosine similarity
|
12 |
nbrs = NearestNeighbors(n_neighbors=10, metric='cosine').fit(embeddings)
|
13 |
|
14 |
# Load the dataset
|
15 |
-
df = pd.read_csv('
|
16 |
|
17 |
# Initialize the SentenceTransformer model
|
18 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
@@ -25,7 +25,7 @@ def semantic_search(query, model, embeddings, nbrs):
|
|
25 |
distances, indices = nbrs.kneighbors([query_embedding])
|
26 |
|
27 |
# Return the k most similar sentences and their distances
|
28 |
-
similar_sentences = [(df['
|
29 |
return similar_sentences
|
30 |
|
31 |
def search_interface(query):
|
|
|
5 |
import gradio as gr
|
6 |
|
7 |
# Load the embeddings from the file
|
8 |
+
with open('embeddings_hadith.pkl', 'rb') as f:
|
9 |
embeddings = pickle.load(f)
|
10 |
|
11 |
# Initialize the Nearest Neighbors model with cosine similarity
|
12 |
nbrs = NearestNeighbors(n_neighbors=10, metric='cosine').fit(embeddings)
|
13 |
|
14 |
# Load the dataset
|
15 |
+
df = pd.read_csv('hadith_combined.csv', delimiter='\t')
|
16 |
|
17 |
# Initialize the SentenceTransformer model
|
18 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
|
|
25 |
distances, indices = nbrs.kneighbors([query_embedding])
|
26 |
|
27 |
# Return the k most similar sentences and their distances
|
28 |
+
similar_sentences = [(df['text'].iloc[idx], dist) for idx, dist in zip(indices[0], distances[0])]
|
29 |
return similar_sentences
|
30 |
|
31 |
def search_interface(query):
|
embeddings_quran.pkl → embeddings_hadith.pkl
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d5e670ba9df7be27831614831af8a57e8e3f13ff632093c946196cdcf24b7357
|
3 |
+
size 31225507
|
hadith_combined.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
quran_data.csv
DELETED
The diff for this file is too large to render.
See raw diff
|
|