File size: 7,661 Bytes
90d06cf
095443a
f86354b
23cc3f4
6ef7048
 
 
4fc2f48
 
f86354b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c3af54
095443a
f86354b
029cd97
 
095443a
029cd97
095443a
 
23cc3f4
 
f86354b
 
 
 
23cc3f4
f86354b
a8a2177
f86354b
 
 
 
 
 
a8a2177
f86354b
 
23cc3f4
 
 
f86354b
f27649c
f86354b
f27649c
23cc3f4
095443a
23cc3f4
029cd97
23cc3f4
8e1c706
23cc3f4
029cd97
 
23cc3f4
 
f27649c
f86354b
 
 
23cc3f4
095443a
f86354b
23cc3f4
f86354b
 
4624ee9
23cc3f4
f86354b
23cc3f4
 
44047d7
a8a2177
f86354b
23cc3f4
f86354b
23cc3f4
 
f86354b
23cc3f4
095443a
f86354b
23cc3f4
a8a2177
23cc3f4
 
4624ee9
23cc3f4
 
f86354b
23cc3f4
4624ee9
23cc3f4
 
f86354b
 
4624ee9
095443a
f86354b
 
 
 
 
 
 
23cc3f4
f86354b
23cc3f4
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import gradio as gr

# Replace the CSV data loading with in-memory data
data = [
    {"蛛絲馬跡": 1, "嫌疑犯": "5冰淇淋師傅", "直接證據": "SAS", "間接證據": "RHS SSS", "嫌疑犯圖片": "./5冰淇淋師傅.png"},
    {"蛛絲馬跡": 2, "嫌疑犯": "7候選人", "直接證據": "SSS", "間接證據": "SAS ASA AAS", "嫌疑犯圖片": "./7候選人.png"},
    {"蛛絲馬跡": 3, "嫌疑犯": "8列車長", "直接證據": "SAS", "間接證據": "無", "嫌疑犯圖片": "./8列車長.png"},
    {"蛛絲馬跡": 4, "嫌疑犯": "2農夫", "直接證據": "SSS", "間接證據": "無", "嫌疑犯圖片": "2農夫.png"},
    {"蛛絲馬跡": 5, "嫌疑犯": "1漁夫", "直接證據": "RHS", "間接證據": "SAS SSS", "嫌疑犯圖片": "1漁夫.png"},
    {"蛛絲馬跡": 6, "嫌疑犯": "4廚師", "直接證據": "ASA", "間接證據": "無", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/pSbKqG.png"},
    {"蛛絲馬跡": 7, "嫌疑犯": "3女僕", "直接證據": "RHS", "間接證據": "SAS SSS", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/XGoFYq.png"},
    {"蛛絲馬跡": 8, "嫌疑犯": "6棋士", "直接證據": "AAS", "間接證據": "ASA", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/dMZ4I8.png"},
    {"蛛絲馬跡": 9, "嫌疑犯": "10芭蕾舞者", "直接證據": "SSS", "間接證據": "SAS AAS ASA", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/nFohKW.png"},
    {"蛛絲馬跡": 10, "嫌疑犯": "9 DJ", "直接證據": "SAS", "間接證據": "無", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/5fwCDV.png"},
    {"蛛絲馬跡": 11, "嫌疑犯": "16造型師", "直接證據": "RHS", "間接證據": "SSS", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/zd4iXu.png"},
    {"蛛絲馬跡": 12, "嫌疑犯": "12教宗", "直接證據": "SSS", "間接證據": "無", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/3q4ICp.png"},
    {"蛛絲馬跡": 13, "嫌疑犯": "14音樂家", "直接證據": "ASA AAS", "間接證據": "無", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/CIKmMs.png"},
    {"蛛絲馬跡": 14, "嫌疑犯": "13軍人", "直接證據": "ASA", "間接證據": "無", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/BfGyn5.png"},
    {"蛛絲馬跡": 15, "嫌疑犯": "17和尚", "直接證據": "ASA AAS", "間接證據": "無", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/prwQVq.png"},
    {"蛛絲馬跡": 16, "嫌疑犯": "18歌手", "直接證據": "AAS", "間接證據": "ASA", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/mtBa2p.png"},
    {"蛛絲馬跡": 17, "嫌疑犯": "11醫生", "直接證據": "SAS", "間接證據": "無", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/T8kgnq.png"},
    {"蛛絲馬跡": 18, "嫌疑犯": "15壽司師傅", "直接證據": "SAS", "間接證據": "AAS ASA SSS", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/fWMhki.png"},
    {"蛛絲馬跡": 19, "嫌疑犯": "21郵差", "直接證據": "RHS", "間接證據": "SAS SSS", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/kUuriv.png"},
    {"蛛絲馬跡": 20, "嫌疑犯": "19籃球員", "直接證據": "RHS", "間接證據": "SSS SAS", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/uhman9.png"},
    {"蛛絲馬跡": 21, "嫌疑犯": "22法官", "直接證據": "ASA AAS", "間接證據": "無", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/R1ZipX.png"},
    {"蛛絲馬跡": 22, "嫌疑犯": "20漫畫家", "直接證據": "ASA AAS", "間接證據": "無", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/yaZhP7.png"},
    {"蛛絲馬跡": 23, "嫌疑犯": "25殺手", "直接證據": "ASA AAS", "間接證據": "無", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/5dVfQW.png"},
    {"蛛絲馬跡": 24, "嫌疑犯": "28科學家", "直接證據": "ASA AAS", "間接證據": "無", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/Vj8MfX.png"},
    {"蛛絲馬跡": 25, "嫌疑犯": "27太空人", "直接證據": "SSS", "間接證據": "ASA AAS RHS", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/hdso0N.png"},
    {"蛛絲馬跡": 26, "嫌疑犯": "23酒保", "直接證據": "AAS", "間接證據": "ASA", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/UFJMlD.png"},
    {"蛛絲馬跡": 27, "嫌疑犯": "24魔術師", "直接證據": "ASA", "間接證據": "AAS", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/jEAikS.png"},
    {"蛛絲馬跡": 28, "嫌疑犯": "26保全", "直接證據": "ASA", "間接證據": "AAS", "嫌疑犯圖片": "https://upload.cc/i1/2024/12/24/zh7qco.png"}
]

# To store the indirect evidence dynamically
indirect_evidence_store = ""

def query_data(clue_number):
    global indirect_evidence_store
    try:
        clue_number = int(clue_number)
        row = next((item for item in data if item['蛛絲馬跡'] == clue_number), None)
        if row:
            suspect = row['嫌疑犯']
            direct_evidence = row['直接證據']
            indirect_evidence_store = row['間接證據'] if row['間接證據'] else "無間接證據"
            image_url = row['嫌疑犯圖片'] if row['嫌疑犯圖片'] else None
            return (
                f"嫌疑犯: {suspect}\n直接證據: {direct_evidence}",
                gr.update(visible=True),
                gr.update(value="", visible=False),
                image_url if image_url else None
            )
        else:
            return (
                "未找到相關資料,請檢查蛛絲馬跡號碼是否正確。",
                gr.update(visible=False),
                gr.update(value="", visible=False),
                None
            )
    except ValueError:
        return (
            "請輸入有效的數字。",
            gr.update(visible=False),
            gr.update(value="", visible=False),
            None
        )

def show_indirect_evidence():
    global indirect_evidence_store
    return gr.update(value=indirect_evidence_store, visible=True)

def reset_fields():
    global indirect_evidence_store
    indirect_evidence_store = ""
    return (
        "",
        gr.update(visible=False),
        gr.update(value="", visible=False),
        gr.update(value="", visible=True),
        None
    )

# Create the Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("<h1>嫌疑犯ABC的現身</h1>")
    gr.Markdown("<h3>法官系統</h3>")
    
    with gr.Row():
        input_box = gr.Textbox(label="請輸入蛛絲馬跡號碼", placeholder="例如: 11", lines=1)
        query_button = gr.Button("查詢")
    
    with gr.Row():
        with gr.Column(scale=1):
            output_box = gr.Textbox(label="查詢結果", interactive=False)
        with gr.Column(scale=1):
            image_output = gr.Image(label="嫌疑犯圖片", visible=True, elem_id="suspect-image")
    
    indirect_button = gr.Button("間接證據", visible=False)
    indirect_output = gr.Textbox(label="間接證據內容", interactive=False, visible=False)
    reset_button = gr.Button("重新查詢")

    # Bind actions to functions
    query_button.click(
        query_data,
        inputs=input_box,
        outputs=[output_box, indirect_button, indirect_output, image_output]
    )
    indirect_button.click(
        show_indirect_evidence,
        inputs=None,
        outputs=indirect_output
    )
    reset_button.click(
        reset_fields,
        inputs=None,
        outputs=[input_box, indirect_button, indirect_output, output_box, image_output]
    )

# Add inline CSS to adjust image size
demo.css = """
#suspect-image img {
    max-width: 150px;
    max-height: 150px;
}
"""

# Launch the Gradio app
demo.launch()