BoghdadyJR commited on
Commit
c95f62f
·
verified ·
1 Parent(s): 99ca88e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -21,6 +21,7 @@ load_dotenv(dotenv_path='api.env.txt')
21
  Langchain_API_KEY = os.getenv('LANGCHAIN_API')
22
  GOOGLE_API_KEY = os.getenv('GOOGLE_API')
23
  WEATHER_API_KEY = os.getenv('WEATHER_API')
 
24
 
25
  os.environ["GOOGLE_API_KEY"] = GOOGLE_API_KEY
26
 
@@ -35,13 +36,9 @@ llm = ChatGoogleGenerativeAI(
35
 
36
 
37
  def get_location_from_ip():
38
- ip =requests.get('https://api.ipify.org?format=json').json()['ip']
39
- response = requests.get(f"https://ipapi.co/{ip}/json/").json()
40
- return {
41
- 'city': response.get('city'),
42
- 'latitude': response.get('latitude'),
43
- 'longitude': response.get('longitude')
44
- }
45
 
46
  class WeatherInput(BaseModel):
47
  city: str = Field(default=None, description="The city to get the weather for.")
@@ -52,7 +49,7 @@ def get_weather_by_location(city: str = None):
52
 
53
  if (city == '') or (city == None) or (not city):
54
  location = get_location_from_ip()
55
- city = location['city']
56
 
57
  url = f"https://api.tomorrow.io/v4/timelines?apikey={WEATHER_API_KEY}"
58
  payload = {
 
21
  Langchain_API_KEY = os.getenv('LANGCHAIN_API')
22
  GOOGLE_API_KEY = os.getenv('GOOGLE_API')
23
  WEATHER_API_KEY = os.getenv('WEATHER_API')
24
+ LOCATION_API_KEY = os.getenv('LOCATION_API')
25
 
26
  os.environ["GOOGLE_API_KEY"] = GOOGLE_API_KEY
27
 
 
36
 
37
 
38
  def get_location_from_ip():
39
+ """Get the location of the user based on their IP address."""
40
+ response = requests.get(f"https://api.geoapify.com/v1/ipinfo?apiKey={LOCATION_API_KEY}").json()
41
+ return response
 
 
 
 
42
 
43
  class WeatherInput(BaseModel):
44
  city: str = Field(default=None, description="The city to get the weather for.")
 
49
 
50
  if (city == '') or (city == None) or (not city):
51
  location = get_location_from_ip()
52
+ city = location['city']['name']
53
 
54
  url = f"https://api.tomorrow.io/v4/timelines?apikey={WEATHER_API_KEY}"
55
  payload = {