cdnjs / app.py
play7284's picture
Update app.py
f525dc8 verified
raw
history blame contribute delete
706 Bytes
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)