Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -351,6 +351,71 @@ def generate_map(location_names):
|
|
351 |
|
352 |
map_html = m._repr_html_()
|
353 |
return map_html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
354 |
|
355 |
def fetch_local_news():
|
356 |
api_key = os.environ['SERP_API']
|
|
|
351 |
|
352 |
map_html = m._repr_html_()
|
353 |
return map_html
|
354 |
+
#------------------------------------
|
355 |
+
|
356 |
+
|
357 |
+
# Step 1: Define the Yelp Search Tool
|
358 |
+
class YelpSearchTool(BaseTool):
|
359 |
+
name = "YelpSearch"
|
360 |
+
description = "A tool to search for restaurants in Birmingham, AL using Yelp."
|
361 |
+
|
362 |
+
def _run(self, query: str) -> str:
|
363 |
+
params = {
|
364 |
+
"engine": "yelp",
|
365 |
+
"find_desc": "Restaurant",
|
366 |
+
"find_loc": "Birmingham, AL, USA",
|
367 |
+
"api_key": os.getenv("SERP_API_KEY")
|
368 |
+
}
|
369 |
+
|
370 |
+
response = requests.get("https://serpapi.com/search.json", params=params)
|
371 |
+
if response.status_code == 200:
|
372 |
+
results = response.json().get("organic_results", [])
|
373 |
+
if not results:
|
374 |
+
return "No results found."
|
375 |
+
|
376 |
+
result_str = "Top Restaurants:\n"
|
377 |
+
for result in results[:5]: # Limit to top 5 results
|
378 |
+
name = result.get("title", "No name")
|
379 |
+
rating = result.get("rating", "No rating")
|
380 |
+
reviews = result.get("reviews", "No reviews")
|
381 |
+
address = result.get("address", "No address available")
|
382 |
+
result_str += f"Name: {name}\nRating: {rating}\nReviews: {reviews}\nAddress: {address}\n\n"
|
383 |
+
|
384 |
+
return result_str
|
385 |
+
else:
|
386 |
+
return f"Failed to fetch data from Yelp. Status code: {response.status_code}"
|
387 |
+
|
388 |
+
def _arun(self, query: str):
|
389 |
+
raise NotImplementedError("YelpSearchTool does not support async execution.")
|
390 |
+
|
391 |
+
# Initialize the LLM and the Tool
|
392 |
+
yelp_tool = YelpSearchTool()
|
393 |
+
tools = [
|
394 |
+
Tool(
|
395 |
+
name="YelpSearch",
|
396 |
+
func=yelp_tool._run,
|
397 |
+
description="Search for restaurants in Birmingham using Yelp."
|
398 |
+
)
|
399 |
+
]
|
400 |
+
|
401 |
+
# Initialize the agent
|
402 |
+
agent = initialize_agent(
|
403 |
+
tools=tools,
|
404 |
+
llm=llm,
|
405 |
+
agent="zero-shot-react-description",
|
406 |
+
verbose=True
|
407 |
+
)
|
408 |
+
|
409 |
+
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
410 |
+
conversational_agent = ConversationalRetrievalChain.from_llm(
|
411 |
+
llm=llm,
|
412 |
+
retriever=agent,
|
413 |
+
memory=memory
|
414 |
+
)
|
415 |
+
|
416 |
+
|
417 |
+
#--------------------------------------------------------
|
418 |
+
|
419 |
|
420 |
def fetch_local_news():
|
421 |
api_key = os.environ['SERP_API']
|