Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -101,30 +101,65 @@ def load_passage_info(xlsx_path: str) -> pd.DataFrame:
|
|
| 101 |
|
| 102 |
|
| 103 |
# =========================
|
| 104 |
-
# プロンプト(★1本固定:
|
| 105 |
# =========================
|
| 106 |
def build_prompt(text: str, target_level: int, original_fre: Optional[float] = None) -> str:
|
| 107 |
target_flesch = target_flesch_from_level(target_level)
|
| 108 |
|
| 109 |
-
#
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
except Exception:
|
| 115 |
-
original_line = ""
|
| 116 |
|
| 117 |
return f"""
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
""".strip()
|
| 129 |
|
| 130 |
|
|
@@ -317,7 +352,7 @@ def run_one(level: int, state: dict):
|
|
| 317 |
|
| 318 |
original_fre = float(state.get("orig_score_map", {}).get(text_id, float("nan")))
|
| 319 |
|
| 320 |
-
# ★変更:original_fre をプロンプトに渡す
|
| 321 |
rewritten, used_prompt = rewrite_level(original, target_level=level, original_fre=original_fre)
|
| 322 |
rewritten_fre, wc = compute_metrics(rewritten)
|
| 323 |
|
|
@@ -387,7 +422,6 @@ def run_all(level: int, state: dict):
|
|
| 387 |
|
| 388 |
original_fre = float(state.get("orig_score_map", {}).get(text_id, float("nan")))
|
| 389 |
|
| 390 |
-
# ★変更:original_fre をプロンプトに渡す(プロンプト文面は維持)
|
| 391 |
rewritten, used_prompt = rewrite_level(original, target_level=level, original_fre=original_fre)
|
| 392 |
rewritten_fre, wc = compute_metrics(rewritten)
|
| 393 |
|
|
|
|
| 101 |
|
| 102 |
|
| 103 |
# =========================
|
| 104 |
+
# プロンプト(★1本固定:置き換え)
|
| 105 |
# =========================
|
| 106 |
def build_prompt(text: str, target_level: int, original_fre: Optional[float] = None) -> str:
|
| 107 |
target_flesch = target_flesch_from_level(target_level)
|
| 108 |
|
| 109 |
+
# original_fre が無い/壊れてる場合のフォールバック(仕様は変えない範囲で安全に)
|
| 110 |
+
try:
|
| 111 |
+
original_fre_val = float(original_fre) if original_fre is not None else float("nan")
|
| 112 |
+
except Exception:
|
| 113 |
+
original_fre_val = float("nan")
|
|
|
|
|
|
|
| 114 |
|
| 115 |
return f"""
|
| 116 |
+
The Flesch Reading Ease score is a numeric measure of text readability,
|
| 117 |
+
where higher scores indicate easier readability and lower scores indicate more difficult text.
|
| 118 |
+
|
| 119 |
+
In this task, we are trying to rewrite a given text into the target Flesch Reading Ease score
|
| 120 |
+
and preserving the original meaning and information.
|
| 121 |
+
|
| 122 |
+
Given the original draft (Flesch Reading Ease = {original_fre_val}):
|
| 123 |
+
|
| 124 |
+
[TEXT START]
|
| 125 |
+
{text}
|
| 126 |
+
[TEXT END]
|
| 127 |
+
|
| 128 |
+
Rewrite the above text to the difficulty level of:
|
| 129 |
+
Flesch Reading Ease = {target_flesch}
|
| 130 |
+
|
| 131 |
+
Follow the instructions below carefully.
|
| 132 |
+
|
| 133 |
+
Content preservation:
|
| 134 |
+
- Maintain the original meaning faithfully.
|
| 135 |
+
- Do not add new information.
|
| 136 |
+
- Do not remove important information.
|
| 137 |
+
- Do not introduce interpretations or opinions that are not present in the original text.
|
| 138 |
+
|
| 139 |
+
Scope of rewriting:
|
| 140 |
+
- Apply rewriting and readability adjustments only to the main text.
|
| 141 |
+
- Use titles, headings, or introductory text only as contextual aids.
|
| 142 |
+
- Include such contextual text in the output only if it is absolutely necessary for understanding.
|
| 143 |
+
|
| 144 |
+
Readability control guidelines:
|
| 145 |
+
- Make sentences shorter.
|
| 146 |
+
- Prefer familiar, high-frequency vocabulary.
|
| 147 |
+
- Use simple and direct sentence structures.
|
| 148 |
+
- Avoid jargon; if technical terms are necessary, explain them clearly in simple language.
|
| 149 |
+
- Minimize figurative language, idioms, and expressions whose meanings are not directly inferable.
|
| 150 |
+
|
| 151 |
+
Language modernization:
|
| 152 |
+
- Rewrite the text in clear, modern English.
|
| 153 |
+
- Remove archaic expressions and unnatural or outdated syntax typical of older texts at all levels..
|
| 154 |
+
|
| 155 |
+
Structure and formatting:
|
| 156 |
+
- Clearly separate sections (e.g., chapters or paragraphs) by inserting blank lines.
|
| 157 |
+
- Preserve the logical structure of the original text.
|
| 158 |
+
|
| 159 |
+
Output constraints:
|
| 160 |
+
- Output only the rewritten text.
|
| 161 |
+
- Do not include explanations, comments, or metadata.
|
| 162 |
+
- Do not include [TEXT START] and [TEXT END] in the output.
|
| 163 |
""".strip()
|
| 164 |
|
| 165 |
|
|
|
|
| 352 |
|
| 353 |
original_fre = float(state.get("orig_score_map", {}).get(text_id, float("nan")))
|
| 354 |
|
| 355 |
+
# ★変更:original_fre をプロンプトに渡す
|
| 356 |
rewritten, used_prompt = rewrite_level(original, target_level=level, original_fre=original_fre)
|
| 357 |
rewritten_fre, wc = compute_metrics(rewritten)
|
| 358 |
|
|
|
|
| 422 |
|
| 423 |
original_fre = float(state.get("orig_score_map", {}).get(text_id, float("nan")))
|
| 424 |
|
|
|
|
| 425 |
rewritten, used_prompt = rewrite_level(original, target_level=level, original_fre=original_fre)
|
| 426 |
rewritten_fre, wc = compute_metrics(rewritten)
|
| 427 |
|