Juna190825 commited on
Commit
001b227
·
verified ·
1 Parent(s): 5baad92

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from gradio_client import Client
2
+ import gradio as gr
3
+ import time
4
+
5
+ def search_web(query):
6
+ try:
7
+ start_time = time.time()
8
+
9
+ # Initialize client with increased timeout
10
+ client = Client(
11
+ "Ifeanyi/Web-Search-MCP",
12
+ timeout=60
13
+ )
14
+
15
+ # Make the API call (using positional argument as in working examples)
16
+ result = client.predict(
17
+ query, # Positional argument
18
+ api_name="/webSearch"
19
+ )
20
+
21
+ response_time = (time.time() - start_time) * 1000
22
+
23
+ return (
24
+ {"result": result},
25
+ f"{response_time:.2f} ms",
26
+ "✅ Success"
27
+ )
28
+
29
+ except Exception as e:
30
+ return (
31
+ {"error": str(e)},
32
+ "0 ms",
33
+ "❌ Failed"
34
+ )
35
+
36
+ with gr.Blocks() as demo:
37
+ gr.Markdown("## Web Search Interface")
38
+
39
+ with gr.Row():
40
+ with gr.Column():
41
+ query_input = gr.Textbox(
42
+ label="Enter your search query",
43
+ placeholder="Type your question here...",
44
+ lines=3
45
+ )
46
+ search_btn = gr.Button("Search", variant="primary")
47
+
48
+ with gr.Column():
49
+ output_json = gr.JSON(label="Search Results")
50
+ response_time = gr.Textbox(label="Response Time")
51
+ status = gr.Textbox(label="Status")
52
+
53
+ search_btn.click(
54
+ fn=search_web,
55
+ inputs=query_input,
56
+ outputs=[output_json, response_time, status]
57
+ )
58
+
59
+ if __name__ == "__main__":
60
+ demo.launch()