Add rate limit logging and community resource notice to Gradio interface
Browse files
app.py
CHANGED
@@ -19,6 +19,7 @@ Then connect to: http://localhost:7860/gradio_api/mcp/sse
|
|
19 |
import os
|
20 |
import asyncio
|
21 |
from typing import Optional
|
|
|
22 |
import httpx
|
23 |
import trafilatura
|
24 |
import gradio as gr
|
@@ -96,6 +97,7 @@ async def search_web(
|
|
96 |
try:
|
97 |
# Check rate limit
|
98 |
if not await limiter.hit(rate_limit, "global"):
|
|
|
99 |
return "Error: Rate limit exceeded. Please try again later (limit: 200 requests per hour)."
|
100 |
|
101 |
# Select endpoint based on search type
|
@@ -196,6 +198,16 @@ async def search_web(
|
|
196 |
|
197 |
# Create Gradio interface
|
198 |
with gr.Blocks(title="Web Search MCP Server") as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
gr.Markdown(
|
200 |
"""
|
201 |
# π Web Search MCP Server
|
|
|
19 |
import os
|
20 |
import asyncio
|
21 |
from typing import Optional
|
22 |
+
from datetime import datetime
|
23 |
import httpx
|
24 |
import trafilatura
|
25 |
import gradio as gr
|
|
|
97 |
try:
|
98 |
# Check rate limit
|
99 |
if not await limiter.hit(rate_limit, "global"):
|
100 |
+
print(f"Rate limit exceeded at {datetime.now().isoformat()}")
|
101 |
return "Error: Rate limit exceeded. Please try again later (limit: 200 requests per hour)."
|
102 |
|
103 |
# Select endpoint based on search type
|
|
|
198 |
|
199 |
# Create Gradio interface
|
200 |
with gr.Blocks(title="Web Search MCP Server") as demo:
|
201 |
+
gr.HTML(
|
202 |
+
"""
|
203 |
+
<div style="background-color: rgba(59, 130, 246, 0.1); border: 1px solid rgba(59, 130, 246, 0.3); border-radius: 8px; padding: 12px; margin-bottom: 16px; text-align: center;">
|
204 |
+
<p style="color: rgb(59, 130, 246); margin: 0; font-size: 14px; font-weight: 500;">
|
205 |
+
π€ Community resource β please use responsibly to keep this service available for everyone
|
206 |
+
</p>
|
207 |
+
</div>
|
208 |
+
"""
|
209 |
+
)
|
210 |
+
|
211 |
gr.Markdown(
|
212 |
"""
|
213 |
# π Web Search MCP Server
|