| import gradio as gr |
| import pandas as pd |
| import re |
|
|
| def check_spacing(csv_file): |
| |
| df = pd.read_csv(csv_file.name) |
|
|
| |
| text = ' '.join(df.astype(str).values.flatten()) |
| |
| |
| pattern = r'[\u4e00-\u9fa5]\$[\u4e00-\u9fa5]' |
| matches = re.finditer(pattern, text) |
|
|
| |
| errors = [] |
| for match in matches: |
| errors.append((match.start(), match.group())) |
|
|
| |
| if errors: |
| error_list = [] |
| for error in errors: |
| error_list.append(f"錯誤位置:{error[0]},內容:{error[1]}") |
| return "\n".join(error_list) |
| else: |
| return "未發現錯誤" |
|
|
| |
| interface = gr.Interface( |
| fn=check_spacing, |
| inputs=gr.File(file_types=['.csv', '.xls', '.pdf']), |
| outputs="text", |
| title="中文校對系統", |
| description="上傳一個CSV、XLS 或 PDF 檔案,系統會檢查$符號前後的中文字是否有空格" |
| ) |
|
|
| |
| interface.launch() |
|
|