Toya0421 commited on
Commit
e6a5809
·
verified ·
1 Parent(s): 36601b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -20
app.py CHANGED
@@ -101,30 +101,65 @@ def load_passage_info(xlsx_path: str) -> pd.DataFrame:
101
 
102
 
103
  # =========================
104
- # プロンプト(★1本固定:元の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
- # ★追加:書き換え前スコア(情報とし渡すだけ。Requirements一切更しない)
110
- original_line = ""
111
- if original_fre is not None:
112
- try:
113
- original_line = f"Original Flesch Reading Ease (before rewriting): {float(original_fre):.2f}\n"
114
- except Exception:
115
- original_line = ""
116
 
117
  return f"""
118
- Rewrite the following text to achieve a Flesch Readability Score of {target_flesch}.
119
- Requirements:
120
- - Rewriting and readability score adjustments should target only the main text;
121
- Other text (e.g., introductions, chapter headings, titles) may be used as contextual aids during rewriting, and should only be included in the output as main text when absolutely necessary for understanding.
122
- - Clearly separate sections such as chapters by inserting blank lines between them.
123
- - Maintain the original meaning faithfully; do not add or remove important information.
124
- - Rewrite texts into clear, modern English by removing archaic expressions and unnatural syntax typical of older texts at all levels.
125
- - Key points to keep in mind when lowering reading comprehension difficulty include keeping sentences short, using familiar vocabulary, prioritizing simple sentence structures, avoiding jargon or providing clear explanations when used, and minimizing figurative language, idioms, and other expressions where meaning cannot be directly inferred from the words themselves.
126
- - Output only the rewritten text. Do not include explanatory notes or other additional text.
127
- {original_line}{text}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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