Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536import gradio as grimport pandas as pdimport re
def check_spacing(csv_file): # 讀取 CSV 檔案 df = pd.read_csv(csv_file)
# 將所有的內容合併成一個大的字串進行檢查 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 "未發現錯誤"
# 使用 Gradio 來建立介面interface = gr.Interface( fn=check_spacing, inputs=gr.inputs.File(file_type=['text/csv']), outputs="text", title="中文校對系統", descriptioapp.py+36