Update app.py
Browse files
app.py
CHANGED
|
@@ -147,13 +147,13 @@ def compute_features(text):
|
|
| 147 |
punctuation_ratio = punctuation_count / (len(text) + 1e-6)
|
| 148 |
avg_word_length = sum(len(w) for w in words) / (word_count if word_count else 1)
|
| 149 |
|
| 150 |
-
return
|
| 151 |
|
| 152 |
# ---------------- 使用 scaler ----------------
|
| 153 |
def transform_features(feat):
|
| 154 |
if scaler is None:
|
| 155 |
return feat # 如果 scaler 沒載入,就直接回傳原始特徵
|
| 156 |
-
return scaler.transform(feat)
|
| 157 |
|
| 158 |
# ---------------- 生成解釋 ----------------
|
| 159 |
def explain_prediction(text):
|
|
@@ -169,7 +169,7 @@ def explain_prediction(text):
|
|
| 169 |
seq = vectorized_layer([text])
|
| 170 |
seq = tf.keras.utils.pad_sequences(seq, maxlen=50, padding='pre')
|
| 171 |
|
| 172 |
-
# 轉成
|
| 173 |
seq = tf.convert_to_tensor(seq)
|
| 174 |
feat = tf.convert_to_tensor(feat, dtype=tf.float32)
|
| 175 |
|
|
@@ -202,4 +202,4 @@ iface = gr.Interface(
|
|
| 202 |
description="輸入文章,模型會判斷是 AI 或人類撰寫,並給出機率與判斷依據"
|
| 203 |
)
|
| 204 |
|
| 205 |
-
iface.launch()
|
|
|
|
| 147 |
punctuation_ratio = punctuation_count / (len(text) + 1e-6)
|
| 148 |
avg_word_length = sum(len(w) for w in words) / (word_count if word_count else 1)
|
| 149 |
|
| 150 |
+
return [[word_count, unique_word_ratio, repeat_rate, punctuation_ratio, avg_word_length]]
|
| 151 |
|
| 152 |
# ---------------- 使用 scaler ----------------
|
| 153 |
def transform_features(feat):
|
| 154 |
if scaler is None:
|
| 155 |
return feat # 如果 scaler 沒載入,就直接回傳原始特徵
|
| 156 |
+
return scaler.transform(feat).tolist() # 轉成 list,避免使用 NumPy
|
| 157 |
|
| 158 |
# ---------------- 生成解釋 ----------------
|
| 159 |
def explain_prediction(text):
|
|
|
|
| 169 |
seq = vectorized_layer([text])
|
| 170 |
seq = tf.keras.utils.pad_sequences(seq, maxlen=50, padding='pre')
|
| 171 |
|
| 172 |
+
# 轉成 TensorFlow tensor
|
| 173 |
seq = tf.convert_to_tensor(seq)
|
| 174 |
feat = tf.convert_to_tensor(feat, dtype=tf.float32)
|
| 175 |
|
|
|
|
| 202 |
description="輸入文章,模型會判斷是 AI 或人類撰寫,並給出機率與判斷依據"
|
| 203 |
)
|
| 204 |
|
| 205 |
+
iface.launch()
|