Spaces:
Running
Running
Commit
·
1ffee4a
1
Parent(s):
62ab1b1
- app.py +84 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
# Function to fetch data from the API
|
5 |
+
def fetch_tenders(date, category, type_, unit_name, unit_id, job_number, name):
|
6 |
+
base_url = "https://pcc.mlwmlw.org/api/date/award/"
|
7 |
+
if not date:
|
8 |
+
date = "today" # Use today's date by default
|
9 |
+
url = f"{base_url}{date}"
|
10 |
+
|
11 |
+
try:
|
12 |
+
response = requests.get(url)
|
13 |
+
response.raise_for_status()
|
14 |
+
data = response.json()
|
15 |
+
|
16 |
+
# Filter data based on inputs
|
17 |
+
filtered_data = [
|
18 |
+
{
|
19 |
+
"標案名稱": item.get("name"),
|
20 |
+
"機關名稱": item.get("unit"),
|
21 |
+
"類別": item.get("category"),
|
22 |
+
"招標方式": item.get("type"),
|
23 |
+
"價格": item.get("price"),
|
24 |
+
"連結": item.get("url")
|
25 |
+
}
|
26 |
+
for item in data
|
27 |
+
if (
|
28 |
+
(category == "不限" or item.get("category") == category) and
|
29 |
+
(type_ == "不限" or item.get("type") == type_) and
|
30 |
+
(not unit_name or unit_name in item.get("unit", "")) and
|
31 |
+
(not unit_id or unit_id in item.get("unit_id", "")) and
|
32 |
+
(not job_number or job_number in item.get("job_number", "")) and
|
33 |
+
(not name or name in item.get("name", ""))
|
34 |
+
)
|
35 |
+
]
|
36 |
+
return filtered_data
|
37 |
+
|
38 |
+
except requests.exceptions.RequestException as e:
|
39 |
+
return [{"Error": f"無法取得資料: {str(e)}"}]
|
40 |
+
|
41 |
+
|
42 |
+
# Gradio Interface
|
43 |
+
def create_interface():
|
44 |
+
date_input = gr.Text(label="查詢日期 (YYYY-MM-DD)", placeholder="默認為今天")
|
45 |
+
category_dropdown = gr.Dropdown(
|
46 |
+
choices=["不限", "工程", "財物", "勞務"],
|
47 |
+
label="採購性質",
|
48 |
+
value="不限"
|
49 |
+
)
|
50 |
+
type_dropdown = gr.Dropdown(
|
51 |
+
choices=[
|
52 |
+
"不限", "各式招標公告", "公開招標", "公開取得電子報價單", "公開取得報價單或企劃書",
|
53 |
+
"經公開評選或公開徵求之限制性招標", "選擇性招標 (建立合格廠商名單)",
|
54 |
+
"選擇性招標 (建立合格廠商名單後續邀標)", "選擇性招標 (個案)", "電子競價",
|
55 |
+
"限制性招標 (未經公開評選或公開徵求)"
|
56 |
+
],
|
57 |
+
label="招標方式",
|
58 |
+
value="不限"
|
59 |
+
)
|
60 |
+
unit_name_input = gr.Text(label="機關名稱", placeholder="輸入機關名稱")
|
61 |
+
unit_id_input = gr.Text(label="機關代碼", placeholder="輸入機關代碼")
|
62 |
+
job_number_input = gr.Text(label="標案案號", placeholder="輸入標案案號")
|
63 |
+
name_input = gr.Text(label="標案名稱", placeholder="輸入標案名稱")
|
64 |
+
|
65 |
+
# Output for displaying results
|
66 |
+
output = gr.Dataframe(
|
67 |
+
headers=["標案名稱", "機關名稱", "類別", "招標方式", "價格", "連結"],
|
68 |
+
label="查詢結果"
|
69 |
+
)
|
70 |
+
|
71 |
+
# Create Gradio interface
|
72 |
+
gr.Interface(
|
73 |
+
fn=lambda date, category, type_, unit_name, unit_id, job_number, name: fetch_tenders(
|
74 |
+
date, category, type_, unit_name, unit_id, job_number, name
|
75 |
+
),
|
76 |
+
inputs=[date_input, category_dropdown, type_dropdown,
|
77 |
+
unit_name_input, unit_id_input, job_number_input, name_input],
|
78 |
+
outputs=output,
|
79 |
+
title="政府招標查詢工具",
|
80 |
+
description="通過日期、採購性質、招標方式以及其他關鍵字篩選政府招標公告。"
|
81 |
+
).launch()
|
82 |
+
|
83 |
+
if __name__ == "__main__":
|
84 |
+
create_interface()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
requests
|