Update app.py
Browse files
app.py
CHANGED
@@ -2,39 +2,43 @@ import gradio as gr
|
|
2 |
import pandas as pd
|
3 |
import re
|
4 |
|
5 |
-
#
|
6 |
def check_spacing_around_dollar(df):
|
7 |
errors = []
|
8 |
for i, row in df.iterrows():
|
9 |
for col in df.columns:
|
10 |
text = str(row[col])
|
11 |
-
|
12 |
-
|
|
|
13 |
errors.append(f"行 {i+1} 列 '{col}': '{text}'")
|
14 |
return errors
|
15 |
|
16 |
-
#
|
17 |
def check_spacing_between_dollars(df):
|
18 |
errors = []
|
19 |
for i, row in df.iterrows():
|
20 |
for col in df.columns:
|
21 |
text = str(row[col])
|
22 |
-
|
|
|
23 |
if text[match.end()] != ' ' and text[match.start() - 1] != ' ':
|
24 |
errors.append(f"行 {i+1} 列 '{col}': '{text}'")
|
25 |
return errors
|
26 |
|
27 |
-
#
|
28 |
def check_numbers_surrounded_by_dollar(df):
|
29 |
errors = []
|
30 |
for i, row in df.iterrows():
|
31 |
for col in df.columns:
|
32 |
text = str(row[col])
|
33 |
-
|
|
|
34 |
if not (text[match.start() - 1] == '$' and text[match.end()] == '$'):
|
35 |
errors.append(f"行 {i+1} 列 '{col}': '{text}'")
|
36 |
return errors
|
37 |
|
|
|
38 |
def process_file(file):
|
39 |
if file.name.endswith('.csv'):
|
40 |
df = pd.read_csv(file.name)
|
|
|
2 |
import pandas as pd
|
3 |
import re
|
4 |
|
5 |
+
# 第一個檢查:檢查$符號前後是否有空格
|
6 |
def check_spacing_around_dollar(df):
|
7 |
errors = []
|
8 |
for i, row in df.iterrows():
|
9 |
for col in df.columns:
|
10 |
text = str(row[col])
|
11 |
+
matches = list(re.finditer(r'(\s?\$\S*?\s?|\s?\S*?\$)', text))
|
12 |
+
for match in matches:
|
13 |
+
if not (text[match.start() - 1] == ' ' and text[match.end()] == ' '):
|
14 |
errors.append(f"行 {i+1} 列 '{col}': '{text}'")
|
15 |
return errors
|
16 |
|
17 |
+
# 第二個檢查:檢查$符號之間是否有空格
|
18 |
def check_spacing_between_dollars(df):
|
19 |
errors = []
|
20 |
for i, row in df.iterrows():
|
21 |
for col in df.columns:
|
22 |
text = str(row[col])
|
23 |
+
matches = list(re.finditer(r'\$\S+?(?=\$)', text))
|
24 |
+
for match in matches:
|
25 |
if text[match.end()] != ' ' and text[match.start() - 1] != ' ':
|
26 |
errors.append(f"行 {i+1} 列 '{col}': '{text}'")
|
27 |
return errors
|
28 |
|
29 |
+
# 第三個檢查:檢查數字前後是否有$
|
30 |
def check_numbers_surrounded_by_dollar(df):
|
31 |
errors = []
|
32 |
for i, row in df.iterrows():
|
33 |
for col in df.columns:
|
34 |
text = str(row[col])
|
35 |
+
matches = list(re.finditer(r'\b\d+\b', text))
|
36 |
+
for match in matches:
|
37 |
if not (text[match.start() - 1] == '$' and text[match.end()] == '$'):
|
38 |
errors.append(f"行 {i+1} 列 '{col}': '{text}'")
|
39 |
return errors
|
40 |
|
41 |
+
# 處理檔案並執行檢查
|
42 |
def process_file(file):
|
43 |
if file.name.endswith('.csv'):
|
44 |
df = pd.read_csv(file.name)
|