File size: 3,869 Bytes
2fac9d0
d6473ae
2fac9d0
a8f506b
f955f1f
0520f56
 
2ffffea
0520f56
 
 
 
 
 
d6473ae
0520f56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d6473ae
0520f56
 
2fac9d0
2ffffea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0520f56
 
2ffffea
 
0520f56
 
2ffffea
 
 
 
527ad82
0520f56
 
527ad82
0520f56
2ffffea
 
 
0b84ca5
2ffffea
0b84ca5
2ffffea
 
2fac9d0
f955f1f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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()