import gradio as gr import requests # Function to perform a web search using Google Custom Search API def search_web(query): """ Job Description: This bot performs a real web search using Google Custom Search API. It uses the given query to search the web and returns the search results. """ api_key = 'AIzaSyCl7sM719Oj2eiVmssmIXo1im5b_EXUKrg' # Replace with your API key cse_id = '01f9f02a1105b4255' # Replace with your Custom Search Engine ID # Perform the search using the API url = f"https://www.googleapis.com/customsearch/v1?q={query}&key={api_key}&cx={cse_id}" try: response = requests.get(url) response.raise_for_status() # Raise an exception for HTTP errors search_results = response.json() # Get the JSON response # Extract search result information if "items" in search_results: results = [] for item in search_results["items"]: title = item.get("title", "No title") snippet = item.get("snippet", "No snippet") link = item.get("link", "No link") results.append(f"Title: {title}\nSnippet: {snippet}\nLink: {link}\n") return "\n".join(results) else: return "No results found." except requests.exceptions.RequestException as e: return f"An error occurred while fetching search results: {e}" # Bot 2: Summary Bot def summary_bot(search_results): """ Job Description: The Summary Bot takes search results and provides a brief summary of the relevant information. This bot will filter out irrelevant information and provide a concise summary. """ if "No results" in search_results: return "No useful search results found." # Extract relevant information (This is a mock-up and should be replaced with NLP or API-based summarization logic) summary = "Summary: The most recent celebrity gossip involves top discussions on Reddit and TMZ." return summary # Bot 3: Review Bot def review_bot(summary): """ Job Description: The Review Bot reviews the summary provided by the Summary Bot and ensures that it makes sense. It gives the final verdict whether the summary is good, or if there are issues with it. """ if "No results" in summary: return "Final Review: No valid results to summarize." # Perform final validation or feedback on the summary final_review = f"Final Overview: The summary captures key points about recent celebrity gossip, including discussions on Reddit and TMZ." return final_review # Bot 4: User Interaction Bot def user_interaction(query): """ Job Description: The User Interaction Bot controls the flow of the input and output between the user and the other bots. It is responsible for taking the user input and providing the final output after all bot tasks are completed. """ search_results = search_web(query) # Call Search Bot (using the real search function) summary = summary_bot(search_results) # Call Summary Bot final_review = review_bot(summary) # Call Review Bot return search_results, summary, final_review # Define Gradio Interface with gr.Blocks() as demo: query_input = gr.Textbox(label="Enter your search query", lines=5) search_output = gr.Textbox(label="Search Results", lines=5, interactive=False) summary_output = gr.Textbox(label="Summary", lines=5, interactive=False) final_output = gr.Textbox(label="Final Review", lines=5, interactive=False) process_button = gr.Button("Process Task") # When the user clicks the "Process Task" button, it triggers the user interaction flow process_button.click(user_interaction, inputs=[query_input], outputs=[search_output, summary_output, final_output]) demo.launch()