wording: 2 seconds
Browse files
app.py
CHANGED
|
@@ -67,7 +67,7 @@ async def search_web(
|
|
| 67 |
- search_web("machine learning basics") - Get 4 general search results (all defaults)
|
| 68 |
"""
|
| 69 |
start_time = time.time()
|
| 70 |
-
|
| 71 |
if not SERPER_API_KEY:
|
| 72 |
await record_request() # Record even failed requests
|
| 73 |
return "Error: SERPER_API_KEY environment variable is not set. Please set it to use this tool."
|
|
@@ -191,11 +191,11 @@ async def search_web(
|
|
| 191 |
print(
|
| 192 |
f"[{datetime.now().isoformat()}] Extraction complete: {successful_extractions}/{len(results)} successful for query '{query}'"
|
| 193 |
)
|
| 194 |
-
|
| 195 |
# Record successful request with duration
|
| 196 |
duration = time.time() - start_time
|
| 197 |
await record_request(duration)
|
| 198 |
-
|
| 199 |
return summary + result
|
| 200 |
|
| 201 |
except Exception as e:
|
|
@@ -205,7 +205,6 @@ async def search_web(
|
|
| 205 |
return f"Error occurred while searching: {str(e)}. Please try again or check your query."
|
| 206 |
|
| 207 |
|
| 208 |
-
|
| 209 |
# Create Gradio interface
|
| 210 |
with gr.Blocks(title="Web Search MCP Server") as demo:
|
| 211 |
gr.HTML(
|
|
@@ -228,7 +227,7 @@ with gr.Blocks(title="Web Search MCP Server") as demo:
|
|
| 228 |
or specifically search for fresh news articles, extracting the main content from results.
|
| 229 |
|
| 230 |
**⚡ Speed-Focused:** Optimized to complete the entire search process - from query to
|
| 231 |
-
fully extracted web content - in under
|
| 232 |
to see real-time performance metrics.
|
| 233 |
|
| 234 |
**Search Types:**
|
|
@@ -304,12 +303,16 @@ with gr.Blocks(title="Web Search MCP Server") as demo:
|
|
| 304 |
|
| 305 |
with gr.Tab("Analytics"):
|
| 306 |
gr.Markdown("## Community Usage Analytics")
|
| 307 |
-
gr.Markdown(
|
| 308 |
-
|
|
|
|
|
|
|
| 309 |
with gr.Row():
|
| 310 |
with gr.Column():
|
| 311 |
requests_plot = gr.BarPlot(
|
| 312 |
-
value=last_n_days_df(
|
|
|
|
|
|
|
| 313 |
x="date",
|
| 314 |
y="count",
|
| 315 |
title="Daily Request Count",
|
|
@@ -318,7 +321,7 @@ with gr.Blocks(title="Web Search MCP Server") as demo:
|
|
| 318 |
x_label_angle=-45, # Rotate labels to prevent overlap
|
| 319 |
container=False,
|
| 320 |
)
|
| 321 |
-
|
| 322 |
with gr.Column():
|
| 323 |
avg_time_plot = gr.BarPlot(
|
| 324 |
value=last_n_days_avg_time_df(14), # Show only last 14 days
|
|
@@ -340,9 +343,9 @@ with gr.Blocks(title="Web Search MCP Server") as demo:
|
|
| 340 |
|
| 341 |
# Load fresh analytics data when the page loads or Analytics tab is clicked
|
| 342 |
demo.load(
|
| 343 |
-
fn=lambda: (last_n_days_df(14), last_n_days_avg_time_df(14)),
|
| 344 |
-
outputs=[requests_plot, avg_time_plot],
|
| 345 |
-
api_name=False
|
| 346 |
)
|
| 347 |
|
| 348 |
# Expose search_web as the only MCP tool
|
|
|
|
| 67 |
- search_web("machine learning basics") - Get 4 general search results (all defaults)
|
| 68 |
"""
|
| 69 |
start_time = time.time()
|
| 70 |
+
|
| 71 |
if not SERPER_API_KEY:
|
| 72 |
await record_request() # Record even failed requests
|
| 73 |
return "Error: SERPER_API_KEY environment variable is not set. Please set it to use this tool."
|
|
|
|
| 191 |
print(
|
| 192 |
f"[{datetime.now().isoformat()}] Extraction complete: {successful_extractions}/{len(results)} successful for query '{query}'"
|
| 193 |
)
|
| 194 |
+
|
| 195 |
# Record successful request with duration
|
| 196 |
duration = time.time() - start_time
|
| 197 |
await record_request(duration)
|
| 198 |
+
|
| 199 |
return summary + result
|
| 200 |
|
| 201 |
except Exception as e:
|
|
|
|
| 205 |
return f"Error occurred while searching: {str(e)}. Please try again or check your query."
|
| 206 |
|
| 207 |
|
|
|
|
| 208 |
# Create Gradio interface
|
| 209 |
with gr.Blocks(title="Web Search MCP Server") as demo:
|
| 210 |
gr.HTML(
|
|
|
|
| 227 |
or specifically search for fresh news articles, extracting the main content from results.
|
| 228 |
|
| 229 |
**⚡ Speed-Focused:** Optimized to complete the entire search process - from query to
|
| 230 |
+
fully extracted web content - in under 2 seconds. Check out the Analytics tab
|
| 231 |
to see real-time performance metrics.
|
| 232 |
|
| 233 |
**Search Types:**
|
|
|
|
| 303 |
|
| 304 |
with gr.Tab("Analytics"):
|
| 305 |
gr.Markdown("## Community Usage Analytics")
|
| 306 |
+
gr.Markdown(
|
| 307 |
+
"Track daily request counts and average response times from all community users."
|
| 308 |
+
)
|
| 309 |
+
|
| 310 |
with gr.Row():
|
| 311 |
with gr.Column():
|
| 312 |
requests_plot = gr.BarPlot(
|
| 313 |
+
value=last_n_days_df(
|
| 314 |
+
14
|
| 315 |
+
), # Show only last 14 days for better visibility
|
| 316 |
x="date",
|
| 317 |
y="count",
|
| 318 |
title="Daily Request Count",
|
|
|
|
| 321 |
x_label_angle=-45, # Rotate labels to prevent overlap
|
| 322 |
container=False,
|
| 323 |
)
|
| 324 |
+
|
| 325 |
with gr.Column():
|
| 326 |
avg_time_plot = gr.BarPlot(
|
| 327 |
value=last_n_days_avg_time_df(14), # Show only last 14 days
|
|
|
|
| 343 |
|
| 344 |
# Load fresh analytics data when the page loads or Analytics tab is clicked
|
| 345 |
demo.load(
|
| 346 |
+
fn=lambda: (last_n_days_df(14), last_n_days_avg_time_df(14)),
|
| 347 |
+
outputs=[requests_plot, avg_time_plot],
|
| 348 |
+
api_name=False,
|
| 349 |
)
|
| 350 |
|
| 351 |
# Expose search_web as the only MCP tool
|