Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import re
|
| 4 |
-
import PyPDF2
|
| 5 |
|
| 6 |
def check_spacing_csv(csv_file):
|
| 7 |
# 讀取 CSV 檔案
|
|
@@ -25,34 +24,14 @@ def check_spacing_csv(csv_file):
|
|
| 25 |
else:
|
| 26 |
return "未發現錯誤"
|
| 27 |
|
| 28 |
-
def check_spacing_pdf(pdf_file):
|
| 29 |
-
reader = PyPDF2.PdfReader(pdf_file.name)
|
| 30 |
-
errors = []
|
| 31 |
-
|
| 32 |
-
# 遍歷每一頁
|
| 33 |
-
for page_number, page in enumerate(reader.pages):
|
| 34 |
-
text = page.extract_text()
|
| 35 |
-
|
| 36 |
-
if text: # 如果有內容,進行檢查
|
| 37 |
-
pattern = r'[\u4e00-\u9fa5]\$[\u4e00-\u9fa5]'
|
| 38 |
-
matches = re.finditer(pattern, text)
|
| 39 |
-
|
| 40 |
-
for match in matches:
|
| 41 |
-
errors.append(f"第 {page_number + 1} 頁,錯誤位置:{match.start()},內容:{match.group()}")
|
| 42 |
-
|
| 43 |
-
if errors:
|
| 44 |
-
return "\n".join(errors)
|
| 45 |
-
else:
|
| 46 |
-
return "未發現錯誤"
|
| 47 |
-
|
| 48 |
# 使用 Gradio 來建立介面
|
| 49 |
interface = gr.Interface(
|
| 50 |
-
fn=
|
| 51 |
-
inputs=gr.File(file_types=['.csv'
|
| 52 |
outputs="text",
|
| 53 |
-
title="CSV
|
| 54 |
-
description="上傳一個
|
| 55 |
)
|
| 56 |
-
|
| 57 |
# 啟動 Gradio 介面
|
| 58 |
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import re
|
|
|
|
| 4 |
|
| 5 |
def check_spacing_csv(csv_file):
|
| 6 |
# 讀取 CSV 檔案
|
|
|
|
| 24 |
else:
|
| 25 |
return "未發現錯誤"
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
# 使用 Gradio 來建立介面
|
| 28 |
interface = gr.Interface(
|
| 29 |
+
fn=check_spacing_csv,
|
| 30 |
+
inputs=gr.File(file_types=['.csv''.xlsx']),
|
| 31 |
outputs="text",
|
| 32 |
+
title="CSV 中文校對系統",
|
| 33 |
+
description="上傳一個CSV檔案,系統會檢查$符號前後的中文字是否有空格"
|
| 34 |
)
|
| 35 |
+
|
| 36 |
# 啟動 Gradio 介面
|
| 37 |
interface.launch()
|