MukeshKapoor25 commited on
Commit
e57a398
·
verified ·
1 Parent(s): 4452393

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -1,7 +1,7 @@
1
- from fastapi import FastAPI, Query
 
2
  from pydantic import BaseModel
3
  from typing import Optional, Dict, Any
4
- import spacy
5
 
6
  # Load spaCy language model
7
  nlp = spacy.load("en_core_web_sm")
@@ -29,6 +29,8 @@ KEYWORD_MAPPINGS = {
29
  "popular": {"popular": True},
30
  "trending": {"trending": True},
31
  "near me": {"radius": 500},
 
 
32
  },
33
  }
34
 
@@ -38,7 +40,6 @@ class QueryRequest(BaseModel):
38
  latitude: Optional[float] = None
39
  longitude: Optional[float] = None
40
 
41
- # Function to parse the sentence using spaCy
42
  def parse_sentence_to_query_ner(sentence: str, lat: Optional[float] = None, lng: Optional[float] = None) -> Dict[str, Any]:
43
  """
44
  Parse a sentence using spaCy NER and build a search query.
@@ -58,6 +59,7 @@ def parse_sentence_to_query_ner(sentence: str, lat: Optional[float] = None, lng:
58
  "longitude": lng,
59
  "radius": None,
60
  "merchant_category": None,
 
61
  "top_rated": False,
62
  "popular": False,
63
  "trending": False,
@@ -78,8 +80,14 @@ def parse_sentence_to_query_ner(sentence: str, lat: Optional[float] = None, lng:
78
  if phrase in sentence.lower():
79
  query.update(filter_dict)
80
 
 
 
 
 
 
 
81
  # Use NER to extract location context
82
- if "near me" in sentence.lower() or "around me" in sentence.lower():
83
  if lat is not None and lng is not None:
84
  query["radius"] = 500 # Default radius for "near me"
85
 
 
1
+ import spacy
2
+ from fastapi import FastAPI
3
  from pydantic import BaseModel
4
  from typing import Optional, Dict, Any
 
5
 
6
  # Load spaCy language model
7
  nlp = spacy.load("en_core_web_sm")
 
29
  "popular": {"popular": True},
30
  "trending": {"trending": True},
31
  "near me": {"radius": 500},
32
+ "around me": {"radius": 500},
33
+ "nearby": {"radius": 500},
34
  },
35
  }
36
 
 
40
  latitude: Optional[float] = None
41
  longitude: Optional[float] = None
42
 
 
43
  def parse_sentence_to_query_ner(sentence: str, lat: Optional[float] = None, lng: Optional[float] = None) -> Dict[str, Any]:
44
  """
45
  Parse a sentence using spaCy NER and build a search query.
 
59
  "longitude": lng,
60
  "radius": None,
61
  "merchant_category": None,
62
+ "business_name": None,
63
  "top_rated": False,
64
  "popular": False,
65
  "trending": False,
 
80
  if phrase in sentence.lower():
81
  query.update(filter_dict)
82
 
83
+ # Extract potential business names using NER
84
+ for ent in doc.ents:
85
+ if ent.label_ in ["ORG", "PERSON", "GPE"]: # Relevant entity types
86
+ query["business_name"] = ent.text
87
+ break
88
+
89
  # Use NER to extract location context
90
+ if "near me" in sentence.lower() or "around me" in sentence.lower() or "nearby" in sentence.lower():
91
  if lat is not None and lng is not None:
92
  query["radius"] = 500 # Default radius for "near me"
93