Spaces:
Sleeping
Sleeping
Commit
·
86e211c
1
Parent(s):
ca50165
feat: add debug tab with connectivity diagnostics using httpx and curl.
Browse files
app.py
CHANGED
|
@@ -79,5 +79,59 @@ with gr.Blocks() as demo:
|
|
| 79 |
outputs=get_output
|
| 80 |
)
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
if __name__ == "__main__":
|
| 83 |
demo.launch(mcp_server=True)
|
|
|
|
| 79 |
outputs=get_output
|
| 80 |
)
|
| 81 |
|
| 82 |
+
with gr.Tab("Debug"):
|
| 83 |
+
gr.Markdown("## Connectivity Test")
|
| 84 |
+
debug_btn = gr.Button("Run Diagnostics")
|
| 85 |
+
debug_output = gr.Textbox(label="Logs", lines=20)
|
| 86 |
+
|
| 87 |
+
async def run_diagnostics():
|
| 88 |
+
import httpx
|
| 89 |
+
import subprocess
|
| 90 |
+
import json
|
| 91 |
+
from npi_mcp_server.config import NPI_API_BASE_URL
|
| 92 |
+
|
| 93 |
+
logs = []
|
| 94 |
+
logs.append(f"Base URL: {NPI_API_BASE_URL}")
|
| 95 |
+
|
| 96 |
+
url = f"{NPI_API_BASE_URL.rstrip('/')}/search_providers"
|
| 97 |
+
payload = {
|
| 98 |
+
"query": "SHELLEY AKEY",
|
| 99 |
+
"state": "AZ",
|
| 100 |
+
"taxonomy": "363LN0000X"
|
| 101 |
+
}
|
| 102 |
+
headers = {
|
| 103 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
# Test 1: Python httpx
|
| 107 |
+
logs.append("\n--- Test 1: Python httpx ---")
|
| 108 |
+
try:
|
| 109 |
+
async with httpx.AsyncClient() as client:
|
| 110 |
+
response = await client.post(url, json=payload, headers=headers, timeout=30.0)
|
| 111 |
+
logs.append(f"Status: {response.status_code}")
|
| 112 |
+
logs.append(f"Response: {response.text}")
|
| 113 |
+
except Exception as e:
|
| 114 |
+
logs.append(f"Error: {e}")
|
| 115 |
+
|
| 116 |
+
# Test 2: System curl
|
| 117 |
+
logs.append("\n--- Test 2: System curl ---")
|
| 118 |
+
try:
|
| 119 |
+
cmd = [
|
| 120 |
+
"curl", "-v", "-X", "POST", url,
|
| 121 |
+
"-H", "Content-Type: application/json",
|
| 122 |
+
"-H", f"User-Agent: {headers['User-Agent']}",
|
| 123 |
+
"-d", json.dumps(payload)
|
| 124 |
+
]
|
| 125 |
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
| 126 |
+
logs.append(f"Return Code: {result.returncode}")
|
| 127 |
+
logs.append(f"Stdout: {result.stdout}")
|
| 128 |
+
logs.append(f"Stderr: {result.stderr}")
|
| 129 |
+
except Exception as e:
|
| 130 |
+
logs.append(f"Curl Error: {e}")
|
| 131 |
+
|
| 132 |
+
return "\n".join(logs)
|
| 133 |
+
|
| 134 |
+
debug_btn.click(fn=run_diagnostics, outputs=debug_output)
|
| 135 |
+
|
| 136 |
if __name__ == "__main__":
|
| 137 |
demo.launch(mcp_server=True)
|