Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,22 +46,22 @@ def query_data(clue_number):
|
|
| 46 |
indirect_evidence_store = row['間接證據'] if row['間接證據'] else "無間接證據"
|
| 47 |
image_url = row['嫌疑犯圖片'] if row['嫌疑犯圖片'] else None
|
| 48 |
return (
|
| 49 |
-
f"嫌疑犯: {suspect}\n直接證據: {direct_evidence}",
|
| 50 |
-
gr.update(visible=True),
|
| 51 |
gr.update(value="", visible=False),
|
| 52 |
image_url if image_url else None
|
| 53 |
)
|
| 54 |
else:
|
| 55 |
return (
|
| 56 |
-
"未找到相關資料,請檢查蛛絲馬跡號碼是否正確。",
|
| 57 |
-
gr.update(visible=False),
|
| 58 |
gr.update(value="", visible=False),
|
| 59 |
None
|
| 60 |
)
|
| 61 |
except ValueError:
|
| 62 |
return (
|
| 63 |
-
"請輸入有效的數字。",
|
| 64 |
-
gr.update(visible=False),
|
| 65 |
gr.update(value="", visible=False),
|
| 66 |
None
|
| 67 |
)
|
|
@@ -74,9 +74,9 @@ def reset_fields():
|
|
| 74 |
global indirect_evidence_store
|
| 75 |
indirect_evidence_store = ""
|
| 76 |
return (
|
| 77 |
-
"",
|
| 78 |
-
gr.update(visible=False),
|
| 79 |
-
gr.update(value="", visible=False),
|
| 80 |
gr.update(value="", visible=True),
|
| 81 |
None
|
| 82 |
)
|
|
@@ -91,8 +91,10 @@ with gr.Blocks() as demo:
|
|
| 91 |
query_button = gr.Button("查詢")
|
| 92 |
|
| 93 |
with gr.Row():
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
| 96 |
|
| 97 |
indirect_button = gr.Button("間接證據", visible=False)
|
| 98 |
indirect_output = gr.Textbox(label="間接證據內容", interactive=False, visible=False)
|
|
@@ -100,29 +102,28 @@ with gr.Blocks() as demo:
|
|
| 100 |
|
| 101 |
# Bind actions to functions
|
| 102 |
query_button.click(
|
| 103 |
-
query_data,
|
| 104 |
-
inputs=input_box,
|
| 105 |
outputs=[output_box, indirect_button, indirect_output, image_output]
|
| 106 |
)
|
| 107 |
indirect_button.click(
|
| 108 |
-
show_indirect_evidence,
|
| 109 |
-
inputs=None,
|
| 110 |
outputs=indirect_output
|
| 111 |
)
|
| 112 |
reset_button.click(
|
| 113 |
-
reset_fields,
|
| 114 |
-
inputs=None,
|
| 115 |
outputs=[input_box, indirect_button, indirect_output, output_box, image_output]
|
| 116 |
)
|
| 117 |
|
| 118 |
-
# Add
|
| 119 |
-
demo.
|
| 120 |
#suspect-image img {
|
| 121 |
-
max-width:
|
| 122 |
-
max-height:
|
| 123 |
-
object-fit: contain;
|
| 124 |
}
|
| 125 |
-
"""
|
| 126 |
|
| 127 |
# Launch the Gradio app
|
| 128 |
demo.launch()
|
|
|
|
| 46 |
indirect_evidence_store = row['間接證據'] if row['間接證據'] else "無間接證據"
|
| 47 |
image_url = row['嫌疑犯圖片'] if row['嫌疑犯圖片'] else None
|
| 48 |
return (
|
| 49 |
+
f"嫌疑犯: {suspect}\n直接證據: {direct_evidence}",
|
| 50 |
+
gr.update(visible=True),
|
| 51 |
gr.update(value="", visible=False),
|
| 52 |
image_url if image_url else None
|
| 53 |
)
|
| 54 |
else:
|
| 55 |
return (
|
| 56 |
+
"未找到相關資料,請檢查蛛絲馬跡號碼是否正確。",
|
| 57 |
+
gr.update(visible=False),
|
| 58 |
gr.update(value="", visible=False),
|
| 59 |
None
|
| 60 |
)
|
| 61 |
except ValueError:
|
| 62 |
return (
|
| 63 |
+
"請輸入有效的數字。",
|
| 64 |
+
gr.update(visible=False),
|
| 65 |
gr.update(value="", visible=False),
|
| 66 |
None
|
| 67 |
)
|
|
|
|
| 74 |
global indirect_evidence_store
|
| 75 |
indirect_evidence_store = ""
|
| 76 |
return (
|
| 77 |
+
"",
|
| 78 |
+
gr.update(visible=False),
|
| 79 |
+
gr.update(value="", visible=False),
|
| 80 |
gr.update(value="", visible=True),
|
| 81 |
None
|
| 82 |
)
|
|
|
|
| 91 |
query_button = gr.Button("查詢")
|
| 92 |
|
| 93 |
with gr.Row():
|
| 94 |
+
with gr.Column(scale=1):
|
| 95 |
+
output_box = gr.Textbox(label="查詢結果", interactive=False)
|
| 96 |
+
with gr.Column(scale=1):
|
| 97 |
+
image_output = gr.Image(label="嫌疑犯圖片", visible=True, elem_id="suspect-image")
|
| 98 |
|
| 99 |
indirect_button = gr.Button("間接證據", visible=False)
|
| 100 |
indirect_output = gr.Textbox(label="間接證據內容", interactive=False, visible=False)
|
|
|
|
| 102 |
|
| 103 |
# Bind actions to functions
|
| 104 |
query_button.click(
|
| 105 |
+
query_data,
|
| 106 |
+
inputs=input_box,
|
| 107 |
outputs=[output_box, indirect_button, indirect_output, image_output]
|
| 108 |
)
|
| 109 |
indirect_button.click(
|
| 110 |
+
show_indirect_evidence,
|
| 111 |
+
inputs=None,
|
| 112 |
outputs=indirect_output
|
| 113 |
)
|
| 114 |
reset_button.click(
|
| 115 |
+
reset_fields,
|
| 116 |
+
inputs=None,
|
| 117 |
outputs=[input_box, indirect_button, indirect_output, output_box, image_output]
|
| 118 |
)
|
| 119 |
|
| 120 |
+
# Add inline CSS to adjust image size
|
| 121 |
+
demo.css = """
|
| 122 |
#suspect-image img {
|
| 123 |
+
max-width: 150px;
|
| 124 |
+
max-height: 150px;
|
|
|
|
| 125 |
}
|
| 126 |
+
"""
|
| 127 |
|
| 128 |
# Launch the Gradio app
|
| 129 |
demo.launch()
|