Pijush2023 commited on
Commit
e8ab9ea
·
verified ·
1 Parent(s): d001e3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -1
app.py CHANGED
@@ -302,7 +302,52 @@ def bot(history, choice, tts_choice, retrieval_mode):
302
 
303
  history.append([response, None]) # Ensure the response is added in the correct format
304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306
 
307
 
308
  def add_message(history, message):
@@ -951,7 +996,7 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
951
  # Handle retrieval mode change
952
  retrieval_mode.change(fn=handle_retrieval_mode_change, inputs=retrieval_mode, outputs=[choice, choice])
953
 
954
- with gr.Column():
955
  # weather_output = gr.HTML(value=fetch_local_weather())
956
  # news_output = gr.HTML(value=fetch_local_news())
957
  # events_output = gr.HTML(value=fetch_local_events())
 
302
 
303
  history.append([response, None]) # Ensure the response is added in the correct format
304
 
305
+ import os
306
+ import gradio as gr
307
+ from crewai import Agent
308
+ from langchain.agents import Tool
309
+ from langchain.utilities import GoogleSerperAPIWrapper
310
+
311
+ # Setup API keys
312
+ os.environ["SERP_API"] = "Serp_key
313
+
314
+ # Initialize the Google Serper API Wrapper
315
+ search = GoogleSerperAPIWrapper()
316
+
317
+ # Define a tool specifically for restaurant searches in Birmingham
318
+ def restaurant_search(query):
319
+ birmingham_query = f"{query} in Birmingham, AL"
320
+ return search.run(birmingham_query)
321
+
322
+ # Create and assign the search tool to the agent
323
+ serper_tool = Tool(
324
+ name="Restaurant Search",
325
+ func=restaurant_search,
326
+ description="Search for restaurants in Birmingham, AL",
327
+ )
328
 
329
+ # Create an agent with the search tool
330
+ restaurant_agent = Agent(
331
+ role='Restaurant Search Agent',
332
+ goal='Find and recommend the best restaurants in Birmingham, AL',
333
+ backstory='An expert on local eateries with a focus on Birmingham, AL.',
334
+ tools=[serper_tool]
335
+ )
336
+
337
+ # Function to handle restaurant-related queries
338
+ def restaurant_search_agent(query):
339
+ if "restaurant" in query.lower() or "eatery" in query.lower():
340
+ return restaurant_agent.run(query)
341
+ else:
342
+ return "This agent only handles restaurant queries."
343
+
344
+ # General response function for the chatbot
345
+ def respond_to_query(query):
346
+ if "restaurant" in query.lower() or "eatery" in query.lower():
347
+ return restaurant_search_agent(query)
348
+ else:
349
+ # Handle other queries (existing logic)
350
+ return "Handling other queries here"
351
 
352
 
353
  def add_message(history, message):
 
996
  # Handle retrieval mode change
997
  retrieval_mode.change(fn=handle_retrieval_mode_change, inputs=retrieval_mode, outputs=[choice, choice])
998
 
999
+ # with gr.Column():
1000
  # weather_output = gr.HTML(value=fetch_local_weather())
1001
  # news_output = gr.HTML(value=fetch_local_news())
1002
  # events_output = gr.HTML(value=fetch_local_events())