Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,25 +7,32 @@ data = [
|
|
| 7 |
# Add more rows as needed
|
| 8 |
]
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
def query_data(clue_number):
|
|
|
|
| 11 |
try:
|
| 12 |
clue_number = int(clue_number)
|
| 13 |
row = next((item for item in data if item['蛛絲馬跡'] == clue_number), None)
|
| 14 |
if row:
|
| 15 |
suspect = row['嫌疑犯']
|
| 16 |
direct_evidence = row['直接證據']
|
| 17 |
-
|
| 18 |
-
return f"嫌疑犯: {suspect}\n直接證據: {direct_evidence}",
|
| 19 |
else:
|
| 20 |
-
return "未找到相關資料,請檢查蛛絲馬跡號碼是否正確。",
|
| 21 |
except ValueError:
|
| 22 |
-
return "請輸入有效的數字。",
|
| 23 |
|
| 24 |
-
def show_indirect_evidence(
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
def reset_fields():
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
|
| 30 |
# Create the Gradio interface
|
| 31 |
with gr.Blocks() as demo:
|
|
@@ -42,10 +49,9 @@ with gr.Blocks() as demo:
|
|
| 42 |
reset_button = gr.Button("重新查詢")
|
| 43 |
|
| 44 |
# Bind actions to functions
|
| 45 |
-
query_button.click(query_data, inputs=input_box, outputs=[output_box,
|
| 46 |
-
indirect_button.click(show_indirect_evidence, inputs=
|
| 47 |
-
reset_button.click(reset_fields, inputs=None, outputs=[input_box,
|
| 48 |
|
| 49 |
# Launch the Gradio app
|
| 50 |
demo.launch()
|
| 51 |
-
|
|
|
|
| 7 |
# Add more rows as needed
|
| 8 |
]
|
| 9 |
|
| 10 |
+
# To store the indirect evidence dynamically
|
| 11 |
+
indirect_evidence_store = ""
|
| 12 |
+
|
| 13 |
def query_data(clue_number):
|
| 14 |
+
global indirect_evidence_store
|
| 15 |
try:
|
| 16 |
clue_number = int(clue_number)
|
| 17 |
row = next((item for item in data if item['蛛絲馬跡'] == clue_number), None)
|
| 18 |
if row:
|
| 19 |
suspect = row['嫌疑犯']
|
| 20 |
direct_evidence = row['直接證據']
|
| 21 |
+
indirect_evidence_store = row['間接證據'] if row['間接證據'] else "無間接證據"
|
| 22 |
+
return f"嫌疑犯: {suspect}\n直接證據: {direct_evidence}", gr.update(visible=True), gr.update(value="", visible=False)
|
| 23 |
else:
|
| 24 |
+
return "未找到相關資料,請檢查蛛絲馬跡號碼是否正確。", gr.update(visible=False), gr.update(value="", visible=False)
|
| 25 |
except ValueError:
|
| 26 |
+
return "請輸入有效的數字。", gr.update(visible=False), gr.update(value="", visible=False)
|
| 27 |
|
| 28 |
+
def show_indirect_evidence():
|
| 29 |
+
global indirect_evidence_store
|
| 30 |
+
return gr.update(value=indirect_evidence_store, visible=True)
|
| 31 |
|
| 32 |
def reset_fields():
|
| 33 |
+
global indirect_evidence_store
|
| 34 |
+
indirect_evidence_store = ""
|
| 35 |
+
return "", gr.update(visible=False), gr.update(value="", visible=False)
|
| 36 |
|
| 37 |
# Create the Gradio interface
|
| 38 |
with gr.Blocks() as demo:
|
|
|
|
| 49 |
reset_button = gr.Button("重新查詢")
|
| 50 |
|
| 51 |
# Bind actions to functions
|
| 52 |
+
query_button.click(query_data, inputs=input_box, outputs=[output_box, indirect_button, indirect_output])
|
| 53 |
+
indirect_button.click(show_indirect_evidence, inputs=None, outputs=indirect_output)
|
| 54 |
+
reset_button.click(reset_fields, inputs=None, outputs=[input_box, indirect_button, indirect_output])
|
| 55 |
|
| 56 |
# Launch the Gradio app
|
| 57 |
demo.launch()
|
|
|