File size: 706 Bytes
e92205c
29f986c
 
e92205c
29f986c
f525dc8
 
29f986c
 
e92205c
 
29f986c
 
 
 
f525dc8
29f986c
e92205c
f525dc8
e92205c
29f986c
 
22a67ae
e92205c
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

import gradio as gr
import requests
import json

def cdnjs_search(query):
    url = f'https://api.cdnjs.com/libraries?search={query}&limit=10'
    response = requests.get(url)
    if response.status_code == 200:
        # 直接返回格式化后的原始JSON字符串
        return json.dumps(response.json(), indent=2, ensure_ascii=False)
    else:
        return "接口请求失败。"

iface = gr.Interface(
    fn=cdnjs_search,
    inputs=gr.Textbox(label="请输入搜索关键字"),
    outputs=gr.Textbox(label="API返回原始JSON"),
    title="在cdnjs上进行搜索",
    description="输入关键字,调用cdnjs API并显示返回的原始JSON数据。"
)

iface.launch(mcp_server=True)