Spaces:
Sleeping
Sleeping
FALSHEIKHI
commited on
Commit
•
d17fd09
1
Parent(s):
95bb032
Update app.py
Browse files
app.py
CHANGED
@@ -8,9 +8,6 @@ from sklearn.metrics.pairwise import cosine_similarity
|
|
8 |
import numpy as np
|
9 |
import pandas as pd
|
10 |
from transformers import pipeline
|
11 |
-
import subprocess
|
12 |
-
subprocess.run(["pythom","-m", "spacy","download","en_core_web_sm"])
|
13 |
-
import spacy
|
14 |
|
15 |
|
16 |
df = pd.read_csv("df_end.csv")
|
@@ -19,22 +16,9 @@ nlp = spacy.load("en_core_web_sm")
|
|
19 |
cities = df['locality'].unique()
|
20 |
|
21 |
|
22 |
-
def extract_city(query,cities):
|
23 |
-
city = None
|
24 |
-
doc = nlp(query)
|
25 |
-
for ent in doc.ents:
|
26 |
-
if ent.label_ == "GPE": # Geo-Political Entity
|
27 |
-
# Assuming the entity is a city
|
28 |
-
return ent.text
|
29 |
-
print(cities)
|
30 |
-
if city in cities :
|
31 |
-
df_to_test = df_to_test.loc[df_to_test['locality'] == city]
|
32 |
-
print(f"City found: {city}")
|
33 |
-
else:
|
34 |
-
print("No city found.")
|
35 |
-
return city
|
36 |
|
37 |
def filter_and_rank_by_similarity_sentiment_ranking(query, df, model,cities, k):
|
|
|
38 |
city = extract_city(query, cities)
|
39 |
cities = df['locality'].unique()
|
40 |
if city in cities:
|
@@ -43,7 +27,6 @@ def filter_and_rank_by_similarity_sentiment_ranking(query, df, model,cities, k):
|
|
43 |
else:
|
44 |
print("No city found.")
|
45 |
|
46 |
-
|
47 |
query_embedding = model.encode(query)
|
48 |
embeddings_matrix = np.stack(df['embedding'].values)
|
49 |
similarities = cosine_similarity([query_embedding], embeddings_matrix).flatten()
|
|
|
8 |
import numpy as np
|
9 |
import pandas as pd
|
10 |
from transformers import pipeline
|
|
|
|
|
|
|
11 |
|
12 |
|
13 |
df = pd.read_csv("df_end.csv")
|
|
|
16 |
cities = df['locality'].unique()
|
17 |
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
def filter_and_rank_by_similarity_sentiment_ranking(query, df, model,cities, k):
|
21 |
+
city = [word for word in query.split() if word in cities][0]
|
22 |
city = extract_city(query, cities)
|
23 |
cities = df['locality'].unique()
|
24 |
if city in cities:
|
|
|
27 |
else:
|
28 |
print("No city found.")
|
29 |
|
|
|
30 |
query_embedding = model.encode(query)
|
31 |
embeddings_matrix = np.stack(df['embedding'].values)
|
32 |
similarities = cosine_similarity([query_embedding], embeddings_matrix).flatten()
|