File size: 2,249 Bytes
2264bdc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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()