Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -72,7 +72,7 @@ split_docs = text_splitter.split_documents(documents)
|
|
72 |
print(f"分割後的文件數量:{len(split_docs)}")
|
73 |
|
74 |
embeddings = HuggingFaceEmbeddings(model_name="intfloat/multilingual-e5-large")
|
75 |
-
print(f"\n成功初始化 Microsoft
|
76 |
|
77 |
print(f"\n開始建立向量資料庫")
|
78 |
vectorstore = Chroma.from_documents(split_docs, embeddings, persist_directory="./Knowledge-base")
|
@@ -210,12 +210,42 @@ def fetch_law_summary(tax_law, keywords):
|
|
210 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"
|
211 |
}
|
212 |
gr.Info("檢索法令彙編函釋中......")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
all_results = []
|
214 |
for keyword in keywords:
|
215 |
payload = {
|
216 |
"FunctionID": "FB10001",
|
217 |
"ObjParams[TaxAct]": tax_law,
|
218 |
-
"ObjParams[TaxVer]":
|
219 |
"ObjParams[Chapter]": "請選擇",
|
220 |
"ObjParams[Article]": "請選擇",
|
221 |
"ObjParams[Content]": keyword,
|
@@ -231,15 +261,15 @@ def fetch_law_summary(tax_law, keywords):
|
|
231 |
if data["Code"] == "1" and "Table" in data["Data"]:
|
232 |
all_results.extend(data["Data"]["Table"])
|
233 |
except Exception as e:
|
234 |
-
print(f"
|
235 |
if all_results:
|
236 |
-
summary = "<h3
|
237 |
unique_results = {}
|
238 |
for result in all_results:
|
239 |
tax_sn = result.get('TaxSN', '')
|
240 |
if tax_sn not in unique_results:
|
241 |
unique_results[tax_sn] = result
|
242 |
-
for index, result in enumerate(list(unique_results.values())[:20]): #
|
243 |
summary += f"""
|
244 |
<details>
|
245 |
<summary style="cursor: pointer; color: #0066cc;">{result['Title']}</summary>
|
|
|
72 |
print(f"分割後的文件數量:{len(split_docs)}")
|
73 |
|
74 |
embeddings = HuggingFaceEmbeddings(model_name="intfloat/multilingual-e5-large")
|
75 |
+
print(f"\n成功初始化 Microsoft ���入型")
|
76 |
|
77 |
print(f"\n開始建立向量資料庫")
|
78 |
vectorstore = Chroma.from_documents(split_docs, embeddings, persist_directory="./Knowledge-base")
|
|
|
210 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"
|
211 |
}
|
212 |
gr.Info("檢索法令彙編函釋中......")
|
213 |
+
version_payload = {
|
214 |
+
"FunctionID": "FB10001",
|
215 |
+
"ObjParams[TaxAct]": tax_law,
|
216 |
+
"ObjParams[TaxVer]": "請選擇",
|
217 |
+
"ObjParams[Chapter]": "請選擇",
|
218 |
+
"ObjParams[Article]": "請選擇",
|
219 |
+
"ObjParams[Content]": "",
|
220 |
+
"ObjParams[Operator01]": "0",
|
221 |
+
"ObjParams[Content01]": "",
|
222 |
+
"ObjParams[Operator02]": "0",
|
223 |
+
"ObjParams[Content02]": ""
|
224 |
+
}
|
225 |
+
try:
|
226 |
+
version_response = requests.post(url, data=version_payload, headers=headers)
|
227 |
+
version_response.raise_for_status()
|
228 |
+
version_data = version_response.json()
|
229 |
+
if version_data["Code"] == "1" and "Table1" in version_data["Data"]:
|
230 |
+
latest_version = "請選擇"
|
231 |
+
for item in version_data["Data"]["Table1"]:
|
232 |
+
if item["TaxAct"] == tax_law:
|
233 |
+
latest_version = item["TaxVer"]
|
234 |
+
break
|
235 |
+
if latest_version == "請選擇":
|
236 |
+
print(f"未找到 {tax_law} 的對應版本,使用預設選項。")
|
237 |
+
else:
|
238 |
+
gr.Warning("無法獲取稅法版本資訊,使用預設選項。")
|
239 |
+
latest_version = "請選擇"
|
240 |
+
except Exception as e:
|
241 |
+
print(f"獲取稅法版本時發生錯誤:{str(e)}")
|
242 |
+
latest_version = "請選擇"
|
243 |
all_results = []
|
244 |
for keyword in keywords:
|
245 |
payload = {
|
246 |
"FunctionID": "FB10001",
|
247 |
"ObjParams[TaxAct]": tax_law,
|
248 |
+
"ObjParams[TaxVer]": latest_version,
|
249 |
"ObjParams[Chapter]": "請選擇",
|
250 |
"ObjParams[Article]": "請選擇",
|
251 |
"ObjParams[Content]": keyword,
|
|
|
261 |
if data["Code"] == "1" and "Table" in data["Data"]:
|
262 |
all_results.extend(data["Data"]["Table"])
|
263 |
except Exception as e:
|
264 |
+
print(f"檢索關鍵字 '{keyword}' 的法令彙編函釋時發生錯誤:{str(e)}")
|
265 |
if all_results:
|
266 |
+
summary = f"<h3>相關法令彙編函釋檢索結果({latest_version}):</h3>"
|
267 |
unique_results = {}
|
268 |
for result in all_results:
|
269 |
tax_sn = result.get('TaxSN', '')
|
270 |
if tax_sn not in unique_results:
|
271 |
unique_results[tax_sn] = result
|
272 |
+
for index, result in enumerate(list(unique_results.values())[:20]): # 限制為前20個唯一結果
|
273 |
summary += f"""
|
274 |
<details>
|
275 |
<summary style="cursor: pointer; color: #0066cc;">{result['Title']}</summary>
|