Spaces:
Running
Running
| import datetime | |
| from urllib.parse import urlparse | |
| import gradio as gr | |
| APP_NAME = "miniapp" | |
| def _is_valid_http_url(url: str) -> bool: | |
| try: | |
| parsed = urlparse(url) | |
| return parsed.scheme in ("http", "https") and bool(parsed.netloc) | |
| except Exception: | |
| return False | |
| def submit(model_name: str, model_api: str, notes: str): | |
| model_name = (model_name or "").strip() | |
| model_api = (model_api or "").strip() | |
| notes = (notes or "").strip() | |
| if not model_name: | |
| return "请填写 **模型名称**。", None | |
| if not model_api: | |
| return "请填写 **模型 API**。", None | |
| if not _is_valid_http_url(model_api): | |
| return "**模型 API** 需要是合法的 `http(s)://...` URL。", None | |
| payload = { | |
| "model_name": model_name, | |
| "model_api": model_api, | |
| "notes": notes, | |
| "submitted_at": datetime.datetime.now().isoformat(timespec="seconds"), | |
| } | |
| return "已收到提交(仅前端回显;未做评测/未写入排行榜)。", payload | |
| with gr.Blocks(title=APP_NAME) as demo: | |
| gr.Markdown( | |
| f"## {APP_NAME}\n\n" | |
| "纯前端信息收集页:填写模型名称与 API 地址,点击提交后回显。\n\n" | |
| "- 不需要 Hugging Face 登录\n" | |
| "- 不依赖 scorer\n" | |
| "- 不读写任何 leaderboard 数据\n" | |
| ) | |
| with gr.Row(): | |
| with gr.Column(scale=2): | |
| model_name = gr.Textbox(label="模型名称(必填)", placeholder="例如:my-agent-v1") | |
| model_api = gr.Textbox( | |
| label="模型 API(必填)", | |
| placeholder="例如:https://api.example.com/v1/chat/completions", | |
| ) | |
| notes = gr.Textbox( | |
| label="备注(可选)", | |
| lines=4, | |
| placeholder="例如:鉴权方式、限流说明、模型简介等", | |
| ) | |
| submit_btn = gr.Button("提交", variant="primary") | |
| with gr.Column(scale=3): | |
| status = gr.Markdown() | |
| submission_json = gr.JSON(label="提交内容(回显)") | |
| submit_btn.click( | |
| submit, | |
| inputs=[model_name, model_api, notes], | |
| outputs=[status, submission_json], | |
| ) | |
| demo.launch() | |