GeminiAi commited on
Commit
2ffffea
·
verified ·
1 Parent(s): a41bd63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -10
app.py CHANGED
@@ -5,7 +5,7 @@ import requests
5
  def search_web(query):
6
  """
7
  Job Description: This bot performs a real web search using Google Custom Search API.
8
- It uses the given query to search the web and returns the search results, formatted with title, snippet, and URL.
9
  """
10
  api_key = 'AIzaSyCl7sM719Oj2eiVmssmIXo1im5b_EXUKrg' # Replace with your API key
11
  cse_id = '01f9f02a1105b4255' # Replace with your Custom Search Engine ID
@@ -25,7 +25,6 @@ def search_web(query):
25
  title = item.get("title", "No title")
26
  snippet = item.get("snippet", "No snippet")
27
  link = item.get("link", "No link")
28
- # Format and add the result to the list
29
  results.append(f"Title: {title}\nSnippet: {snippet}\nLink: {link}\n")
30
  return "\n".join(results)
31
  else:
@@ -34,24 +33,57 @@ def search_web(query):
34
  except requests.exceptions.RequestException as e:
35
  return f"An error occurred while fetching search results: {e}"
36
 
37
- # Bot 2: User Interaction Bot (Main Flow)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  def user_interaction(query):
39
  """
40
- Job Description: This bot takes the user's search query and calls the search_bot to get the search results.
41
- It then directly returns the search results in the specified format.
42
  """
43
  search_results = search_web(query) # Call Search Bot (using the real search function)
44
- return search_results
 
 
 
45
 
46
 
47
  # Define Gradio Interface
48
  with gr.Blocks() as demo:
49
  query_input = gr.Textbox(label="Enter your search query", lines=5)
50
- search_output = gr.Textbox(label="Search Results", lines=15, interactive=False) # Increased lines for better viewing
 
 
51
 
52
- process_button = gr.Button("Search")
53
 
54
- # When the user clicks the "Search" button, it triggers the user interaction flow
55
- process_button.click(user_interaction, inputs=[query_input], outputs=[search_output])
56
 
57
  demo.launch()
 
5
  def search_web(query):
6
  """
7
  Job Description: This bot performs a real web search using Google Custom Search API.
8
+ It uses the given query to search the web and returns the search results.
9
  """
10
  api_key = 'AIzaSyCl7sM719Oj2eiVmssmIXo1im5b_EXUKrg' # Replace with your API key
11
  cse_id = '01f9f02a1105b4255' # Replace with your Custom Search Engine ID
 
25
  title = item.get("title", "No title")
26
  snippet = item.get("snippet", "No snippet")
27
  link = item.get("link", "No link")
 
28
  results.append(f"Title: {title}\nSnippet: {snippet}\nLink: {link}\n")
29
  return "\n".join(results)
30
  else:
 
33
  except requests.exceptions.RequestException as e:
34
  return f"An error occurred while fetching search results: {e}"
35
 
36
+ # Bot 2: Summary Bot
37
+ def summary_bot(search_results):
38
+ """
39
+ Job Description: The Summary Bot takes search results and provides a brief summary of the relevant information.
40
+ This bot will filter out irrelevant information and provide a concise summary.
41
+ """
42
+ if "No results" in search_results:
43
+ return "No useful search results found."
44
+
45
+ # Extract relevant information (This is a mock-up and should be replaced with NLP or API-based summarization logic)
46
+ summary = "Summary: The most recent celebrity gossip involves top discussions on Reddit and TMZ."
47
+
48
+ return summary
49
+
50
+ # Bot 3: Review Bot
51
+ def review_bot(summary):
52
+ """
53
+ Job Description: The Review Bot reviews the summary provided by the Summary Bot and ensures that it makes sense.
54
+ It gives the final verdict whether the summary is good, or if there are issues with it.
55
+ """
56
+ if "No results" in summary:
57
+ return "Final Review: No valid results to summarize."
58
+
59
+ # Perform final validation or feedback on the summary
60
+ final_review = f"Final Overview: The summary captures key points about recent celebrity gossip, including discussions on Reddit and TMZ."
61
+
62
+ return final_review
63
+
64
+ # Bot 4: User Interaction Bot
65
  def user_interaction(query):
66
  """
67
+ Job Description: The User Interaction Bot controls the flow of the input and output between the user and the other bots.
68
+ It is responsible for taking the user input and providing the final output after all bot tasks are completed.
69
  """
70
  search_results = search_web(query) # Call Search Bot (using the real search function)
71
+ summary = summary_bot(search_results) # Call Summary Bot
72
+ final_review = review_bot(summary) # Call Review Bot
73
+
74
+ return search_results, summary, final_review
75
 
76
 
77
  # Define Gradio Interface
78
  with gr.Blocks() as demo:
79
  query_input = gr.Textbox(label="Enter your search query", lines=5)
80
+ search_output = gr.Textbox(label="Search Results", lines=5, interactive=False)
81
+ summary_output = gr.Textbox(label="Summary", lines=5, interactive=False)
82
+ final_output = gr.Textbox(label="Final Review", lines=5, interactive=False)
83
 
84
+ process_button = gr.Button("Process Task")
85
 
86
+ # When the user clicks the "Process Task" button, it triggers the user interaction flow
87
+ process_button.click(user_interaction, inputs=[query_input], outputs=[search_output, summary_output, final_output])
88
 
89
  demo.launch()