Spaces:
Sleeping
Sleeping
Update sami
Browse files
sami
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import re
|
| 4 |
+
|
| 5 |
+
def check_spacing(csv_file):
|
| 6 |
+
# 讀取 CSV 檔案
|
| 7 |
+
df = pd.read_csv(csv_file.name)
|
| 8 |
+
|
| 9 |
+
# 將所有的內容合併成一個大的字串進行檢查
|
| 10 |
+
text = ' '.join(df.astype(str).values.flatten())
|
| 11 |
+
|
| 12 |
+
# 使用正則表達式來查找$符號兩側的中文字之間沒有空格的地方
|
| 13 |
+
pattern = r'[\u4e00-\u9fa5]\$[\u4e00-\u9fa5]'
|
| 14 |
+
matches = re.finditer(pattern, text)
|
| 15 |
+
|
| 16 |
+
# 收集所有錯誤的地方
|
| 17 |
+
errors = []
|
| 18 |
+
for match in matches:
|
| 19 |
+
errors.append((match.start(), match.group()))
|
| 20 |
+
|
| 21 |
+
# 如果有錯誤,列出所有錯誤
|
| 22 |
+
if errors:
|
| 23 |
+
error_list = []
|
| 24 |
+
for error in errors:
|
| 25 |
+
error_list.append(f"錯誤位置:{error[0]},內容:{error[1]}")
|
| 26 |
+
return "\n".join(error_list)
|
| 27 |
+
else:
|
| 28 |
+
return "未發現錯誤"
|
| 29 |
+
|
| 30 |
+
# 使用 Gradio 來建立介面
|
| 31 |
+
interface = gr.Interface(
|
| 32 |
+
fn=check_spacing,
|
| 33 |
+
inputs=gr.File(file_types=['.csv', '.xls', '.pdf']),
|
| 34 |
+
outputs="text",
|
| 35 |
+
title="中文校對系統",
|
| 36 |
+
description="上傳一個CSV、XLS 或 PDF 檔案,系統會檢查$符號前後的中文字是否有空格"
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
# 啟動 Gradio 介面
|
| 40 |
+
interface.launch()
|