FALSHEIKHI commited on
Commit
1fd474e
1 Parent(s): 2f9807e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -12,7 +12,7 @@ import pickle
12
  df = None
13
 
14
  # Open the file in binary mode
15
- with open('df.pkl', 'rb') as file:
16
 
17
  # Call load method to deserialze
18
  df = pickle.load(file)
@@ -22,11 +22,33 @@ model = SentenceTransformer('all-MiniLM-L6-v2')
22
  cities = df['locality'].unique()
23
 
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  def filter_and_rank_by_similarity_sentiment_ranking(query, df, model,cities, k):
27
  city=None
28
  try:
29
- city = [word for word in query.split() if word in cities][0]
30
  except:
31
  pass
32
  cities = df['locality'].unique()
 
12
  df = None
13
 
14
  # Open the file in binary mode
15
+ with open('df_classifcation.pkl', 'rb') as file:
16
 
17
  # Call load method to deserialze
18
  df = pickle.load(file)
 
22
  cities = df['locality'].unique()
23
 
24
 
25
+ import spacy
26
+
27
+ nlp = spacy.load("en_core_web_sm")
28
+ cities = df['locality'].unique()
29
+ def extract_city(query,cities):
30
+ city = None
31
+ doc = nlp(query)
32
+ for ent in doc.ents:
33
+ if ent.label_ == "GPE": # Geo-Political Entity
34
+ # Assuming the entity is a city
35
+ return ent.text
36
+ print(cities)
37
+ if city in cities:
38
+
39
+ print(f"City found: {city}")
40
+ else:
41
+ print("No city found.")
42
+ return city
43
+
44
+
45
+
46
+
47
 
48
  def filter_and_rank_by_similarity_sentiment_ranking(query, df, model,cities, k):
49
  city=None
50
  try:
51
+ city = extract_city(qurey,cities)
52
  except:
53
  pass
54
  cities = df['locality'].unique()