File size: 1,566 Bytes
001b227
 
 
 
 
 
 
 
 
 
 
 
 
 
 
00c72d3
001b227
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19396e1
001b227
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from gradio_client import Client
import gradio as gr
import time

def search_web(query):
    try:
        start_time = time.time()
        
        # Initialize client with increased timeout
        client = Client(
            "Ifeanyi/Web-Search-MCP",
        )
        
        # Make the API call (using positional argument as in working examples)
        result = client.predict(
            prompt=query,  # Positional argument
            api_name="/webSearch"
        )
        
        response_time = (time.time() - start_time) * 1000
        
        return (
            {"result": result},
            f"{response_time:.2f} ms",
            "✅ Success"
        )
        
    except Exception as e:
        return (
            {"error": str(e)},
            "0 ms",
            "❌ Failed"
        )

with gr.Blocks() as demo:
    gr.Markdown("## Web Search Interface")
    
    with gr.Row():
        with gr.Column():
            query_input = gr.Textbox(
                label="Enter your search query",
                placeholder="Type your question here...",
                lines=10
            )
            search_btn = gr.Button("Search", variant="primary")
        
        with gr.Column():
            output_json = gr.JSON(label="Search Results")
            response_time = gr.Textbox(label="Response Time")
            status = gr.Textbox(label="Status")

    search_btn.click(
        fn=search_web,
        inputs=query_input,
        outputs=[output_json, response_time, status]
    )

if __name__ == "__main__":
    demo.launch()