Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pandas as pd | |
import re | |
def check_spacing_csv(csv_file): | |
# 讀取 CSV 檔案 | |
df = pd.read_csv(csv_file.name) | |
errors = [] | |
# 逐行檢查每一行的內容 | |
for index, row in df.iterrows(): | |
row_text = ' '.join(row.astype(str).values.flatten()) | |
# 使用正則表達式來查找$符號兩側的中文字之間沒有空格的地方 | |
pattern = r'[\u4e00-\u9fa5]\$[\u4e00-\u9fa5]' | |
matches = re.finditer(pattern, row_text) | |
for match in matches: | |
errors.append(f"第 {index + 1} 行,錯誤位置:{match.start()},內容:{match.group()}") | |
if errors: | |
return "\n".join(errors) | |
else: | |
return "未發現錯誤" | |
# 使用 Gradio 來建立介面 | |
interface = gr.Interface( | |
fn=check_spacing_csv, | |
inputs=gr.File(file_types=['.csv']), | |
outputs="text", | |
title="CSV 中文校對系統", | |
description="上傳一個CSV檔案,系統會檢查$符號前後的中文字是否有空格" | |
) | |
# 啟動 Gradio 介面 | |
interface.launch() | |