Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Load the CSV file (adjust the file path as necessary)
|
| 5 |
+
data = pd.read_csv("桌遊答案CSV檔.csv")
|
| 6 |
+
|
| 7 |
+
def query_data(clue_number):
|
| 8 |
+
try:
|
| 9 |
+
clue_number = int(clue_number)
|
| 10 |
+
row = data[data['蛛絲馬跡'] == clue_number]
|
| 11 |
+
if not row.empty:
|
| 12 |
+
suspect = row['嫌疑犯'].values[0]
|
| 13 |
+
direct_evidence = row['直接證據'].values[0]
|
| 14 |
+
indirect_evidence = row['間接證據'].values[0] if not pd.isna(row['間接證據'].values[0]) else "無間接證據"
|
| 15 |
+
return f"嫌疑犯: {suspect}\n直接證據: {direct_evidence}", indirect_evidence, gr.update(visible=True)
|
| 16 |
+
else:
|
| 17 |
+
return "未找到相關資料,請檢查蛛絲馬跡號碼是否正確。", "", gr.update(visible=False)
|
| 18 |
+
except ValueError:
|
| 19 |
+
return "請輸入有效的數字。", "", gr.update(visible=False)
|
| 20 |
+
|
| 21 |
+
def reset_fields():
|
| 22 |
+
return "", "", gr.update(visible=False)
|
| 23 |
+
|
| 24 |
+
# Create the Gradio interface
|
| 25 |
+
with gr.Blocks() as demo:
|
| 26 |
+
gr.Markdown("<h1>嫌疑犯ABC的現身</h1>")
|
| 27 |
+
gr.Markdown("<h3>法官系統</h3>")
|
| 28 |
+
|
| 29 |
+
with gr.Row():
|
| 30 |
+
input_box = gr.Textbox(label="請輸入蛛絲馬跡號碼", placeholder="例如: 11", lines=1)
|
| 31 |
+
query_button = gr.Button("查詢")
|
| 32 |
+
|
| 33 |
+
output_box = gr.Textbox(label="查詢結果", interactive=False)
|
| 34 |
+
indirect_button = gr.Button("間接證據", visible=False)
|
| 35 |
+
indirect_output = gr.Textbox(label="間接證據內容", interactive=False, visible=False)
|
| 36 |
+
reset_button = gr.Button("重新查詢")
|
| 37 |
+
|
| 38 |
+
# Bind actions to functions
|
| 39 |
+
query_button.click(query_data, inputs=input_box, outputs=[output_box, indirect_output, indirect_button])
|
| 40 |
+
indirect_button.click(lambda evidence: evidence, inputs=indirect_output, outputs=indirect_output)
|
| 41 |
+
reset_button.click(reset_fields, inputs=None, outputs=[input_box, output_box, indirect_button])
|
| 42 |
+
|
| 43 |
+
# Save this script as a Python file and run it to launch the app
|