Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,56 +13,13 @@ from langgraph.prebuilt import create_react_agent
|
|
| 13 |
@tool
|
| 14 |
def get_lat_lng(location_description: str) -> dict[str, float]:
|
| 15 |
"""Get the latitude and longitude of a location."""
|
| 16 |
-
|
| 17 |
-
return {"lat": 51.1, "lng": -0.1} # London coordinates as dummy response
|
| 18 |
-
|
| 19 |
-
params = {
|
| 20 |
-
"q": location_description,
|
| 21 |
-
"api_key": os.getenv("GEO_API_KEY"),
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
r = requests.get("https://geocode.maps.co/search", params=params)
|
| 25 |
-
r.raise_for_status()
|
| 26 |
-
data = r.json()
|
| 27 |
-
|
| 28 |
-
if data:
|
| 29 |
-
return {"lat": float(data[0]["lat"]), "lng": float(data[0]["lon"])}
|
| 30 |
-
else:
|
| 31 |
-
raise ValueError("Could not find the location")
|
| 32 |
|
| 33 |
@tool
|
| 34 |
def get_weather(lat: float, lng: float) -> dict[str, str]:
|
| 35 |
"""Get the weather at a location."""
|
| 36 |
-
|
| 37 |
-
return {"temperature": "21°C", "description": "Sunny"} # Dummy response
|
| 38 |
|
| 39 |
-
params = {
|
| 40 |
-
"apikey": os.getenv("WEATHER_API_KEY"),
|
| 41 |
-
"location": f"{lat},{lng}",
|
| 42 |
-
"units": "metric",
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
r = requests.get("https://api.tomorrow.io/v4/weather/realtime", params=params)
|
| 46 |
-
r.raise_for_status()
|
| 47 |
-
data = r.json()
|
| 48 |
-
|
| 49 |
-
values = data["data"]["values"]
|
| 50 |
-
weather_codes = {
|
| 51 |
-
1000: "Clear, Sunny", 1100: "Mostly Clear", 1101: "Partly Cloudy",
|
| 52 |
-
1102: "Mostly Cloudy", 1001: "Cloudy", 2000: "Fog",
|
| 53 |
-
2100: "Light Fog", 4000: "Drizzle", 4001: "Rain",
|
| 54 |
-
4200: "Light Rain", 4201: "Heavy Rain", 5000: "Snow",
|
| 55 |
-
5001: "Flurries", 5100: "Light Snow", 5101: "Heavy Snow",
|
| 56 |
-
6000: "Freezing Drizzle", 6001: "Freezing Rain",
|
| 57 |
-
6200: "Light Freezing Rain", 6201: "Heavy Freezing Rain",
|
| 58 |
-
7000: "Ice Pellets", 7101: "Heavy Ice Pellets",
|
| 59 |
-
7102: "Light Ice Pellets", 8000: "Thunderstorm"
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
return {
|
| 63 |
-
"temperature": f'{values["temperatureApparent"]:0.0f}°C',
|
| 64 |
-
"description": weather_codes.get(values["weatherCode"], "Unknown")
|
| 65 |
-
}
|
| 66 |
|
| 67 |
def stream_from_agent(message: str, history: List[Dict[str, str]]) -> gr.ChatMessage:
|
| 68 |
"""Process messages through the LangChain agent with visible reasoning."""
|
|
|
|
| 13 |
@tool
|
| 14 |
def get_lat_lng(location_description: str) -> dict[str, float]:
|
| 15 |
"""Get the latitude and longitude of a location."""
|
| 16 |
+
return {"lat": 51.1, "lng": -0.1} # London coordinates as dummy response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
@tool
|
| 19 |
def get_weather(lat: float, lng: float) -> dict[str, str]:
|
| 20 |
"""Get the weather at a location."""
|
| 21 |
+
return {"temperature": "21°C", "description": "Sunny"} # Dummy response
|
|
|
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
def stream_from_agent(message: str, history: List[Dict[str, str]]) -> gr.ChatMessage:
|
| 25 |
"""Process messages through the LangChain agent with visible reasoning."""
|