File size: 2,066 Bytes
408c946
 
 
 
 
d57c387
 
 
 
 
 
 
 
b30bb82
 
 
 
 
 
 
 
 
 
 
3d6667d
d57c387
408c946
 
d57c387
408c946
 
 
 
d57c387
3d6667d
408c946
d57c387
 
 
 
408c946
5ee51d1
408c946
 
ed54077
d57c387
408c946
 
3d6667d
b30bb82
 
 
 
 
 
 
 
 
 
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
# SPDX-License-Identifier: Apache-2.0
from src.processor.message_processor import process_user_request
from config import DESCRIPTION
import gradio as gr

QUICK_PROMPTS = [
    "#news AI earthquake early warning [條列] depth:3",
    "#papers PLUM method for EEW [表格]",
    "#compare Gemini 1.5 Pro vs GPT-4.1 [簡報] creative!",
    "#earthquakes 6.0 2024-04-01 2024-04-07 [講義]",
    "#howto Run SearXNG on Debian [落地實作]",
]

with gr.Blocks(
    fill_height=True,
    fill_width=True,
    theme=gr.themes.Soft(),
    css="""
/* 確保行動版底部按鈕列不被遮到 */
@media (max-width: 640px){
  .gradio-container .gr-chat-interface .gr-form{ padding-bottom: 72px; }
}
"""
) as app:
    # ChatInterface 使用舊版支援的參數
    chat = gr.ChatInterface(
        fn=process_user_request,
        chatbot=gr.Chatbot(
            label="SearchGPT | Gemini 1.5",
            type="messages",
            show_copy_button=True,
            scale=1
        ),
        type="messages",
        submit_btn="Send",  # 舊版只支援 submit_btn
        examples=[
            ["#news Open-source LLM trends [條列] depth:2"],
            ["#papers P-wave picking with AI [表格]"],
            ["#compare MiniCPM vs Phi-4 [簡報]"],
            ["#timeline Taiwan EEW milestones [條列]"],
            ["https://wikipedia.org/wiki/Artificial_intelligence Read and summarize that"],
            ["https://huggingface.co/spaces?sort=trending What are the trending Spaces?"],
        ],
        cache_examples=False,
        show_api=False,
        concurrency_limit=5,
    )

    # 側欄:說明 + 一鍵示例
    with gr.Sidebar():
        gr.HTML(DESCRIPTION)
        gr.Markdown("### ⚡ 一鍵範例")
        for i, p in enumerate(QUICK_PROMPTS, 1):
            gr.Button(f"示例 {i}", size="sm").click(
                fn=lambda x=p: x, inputs=None, outputs=chat.textbox
            )
        gr.Markdown("> 點示例 → 文字填入輸入框 → 按 **Send** 或 **Enter** 送出。")

app.launch(server_name="0.0.0.0", pwa=True)