HakshaySundar commited on
Commit
c97edc1
1 Parent(s): 9c37f19

Update text_converter.py

Browse files

Closing up some loose ends

Files changed (1) hide show
  1. text_converter.py +20 -10
text_converter.py CHANGED
@@ -22,20 +22,20 @@ def generate_user_prompt(prompt_type, base_text):
22
 
23
  return prompts[prompt_type].format(base_text=base_text)
24
 
25
-
26
- def user_input_readability_level(input_text):
27
- reading_levels = {
28
  "5th Grade (90-100)": (90, 100),
29
  "6th Grade (80-90)": (80, 90),
30
  "7th Grade (70-80)": (70, 80),
31
  "8th - 9th Grade (60-70)": (60, 70),
32
  "10th - 12th Grade (50-60)": (50, 60),
33
  "College (30-50)": (30, 50),
34
- "College Graduate + Professionals (0-30)": (0, 30)
 
35
  }
36
 
37
- inverse_reading_levels = {v: k for k, v in reading_levels.items()}
38
-
 
39
  current_score = flesch_reading_ease(input_text)
40
  print(f'Reading score for user input is: {current_score}')
41
  current_level = ''
@@ -54,6 +54,7 @@ def generate_similar_sentence(input_text, min_reading_level, max_reading_level,
54
  similarity = 0
55
  reading_level = 0
56
  generated_texts = []
 
57
  result_index = -1
58
  closeness = float('inf')
59
 
@@ -78,12 +79,15 @@ def generate_similar_sentence(input_text, min_reading_level, max_reading_level,
78
 
79
  response = get_gpt_response(user_prompt, system_prompt)
80
 
81
- # First we add the generated text to the list of generated texts.
82
  generated_texts.append(response)
83
 
84
  similarity = get_similarity(response, input_text)
85
  reading_level = flesch_reading_ease(response)
86
 
 
 
 
87
  # Determine the closeness of the reading level to the target reading level and store.
88
  if similarity >= min_entailment and min_reading_level <= reading_level <= max_reading_level:
89
  result_index = i
@@ -100,10 +104,16 @@ def generate_similar_sentence(input_text, min_reading_level, max_reading_level,
100
 
101
  # Printing all generated texts to the console.
102
  for index, text in enumerate(generated_texts):
103
- print(f"Generated text {index}: {text}")
 
 
 
 
 
 
104
 
105
  # Returning the final result.
106
  if completed:
107
- return generated_texts[result_index], similarity, reading_level, "Success! Please see the converted text at your target reading level."
108
  else:
109
- return generated_texts[result_index], similarity, reading_level, "Failed. We could not reach the target reading level while maintaining the text meaning."
 
22
 
23
  return prompts[prompt_type].format(base_text=base_text)
24
 
25
+ reading_levels = {
 
 
26
  "5th Grade (90-100)": (90, 100),
27
  "6th Grade (80-90)": (80, 90),
28
  "7th Grade (70-80)": (70, 80),
29
  "8th - 9th Grade (60-70)": (60, 70),
30
  "10th - 12th Grade (50-60)": (50, 60),
31
  "College (30-50)": (30, 50),
32
+ "College Graduate + Professionals (0-30)": (0, 30),
33
+ "Research + Nobel laureate ((-infinity)-(-1))": (-float('inf'), -1)
34
  }
35
 
36
+ inverse_reading_levels = {v: k for k, v in reading_levels.items()}
37
+
38
+ def user_input_readability_level(input_text):
39
  current_score = flesch_reading_ease(input_text)
40
  print(f'Reading score for user input is: {current_score}')
41
  current_level = ''
 
54
  similarity = 0
55
  reading_level = 0
56
  generated_texts = []
57
+ generated_text_scores = []
58
  result_index = -1
59
  closeness = float('inf')
60
 
 
79
 
80
  response = get_gpt_response(user_prompt, system_prompt)
81
 
82
+ # We add the generated text to the list of generated texts.
83
  generated_texts.append(response)
84
 
85
  similarity = get_similarity(response, input_text)
86
  reading_level = flesch_reading_ease(response)
87
 
88
+ # We add the generated text's reading level to the list.
89
+ generated_text_scores.append((similarity, reading_level))
90
+
91
  # Determine the closeness of the reading level to the target reading level and store.
92
  if similarity >= min_entailment and min_reading_level <= reading_level <= max_reading_level:
93
  result_index = i
 
104
 
105
  # Printing all generated texts to the console.
106
  for index, text in enumerate(generated_texts):
107
+ print(f"Generated text {index + 1}: {text}")
108
+
109
+ # Printing the selected index and text.
110
+ print(f"Selected Iteration: {result_index + 1}")
111
+ print(f"Selected Result: {generated_texts[result_index]}")
112
+ print(f"Selected Result's Similarity score: {generated_text_complexities[result_index][0]}")
113
+ print(f"Selected Result's Readability score: {generated_text_complexities[result_index][1]}")
114
 
115
  # Returning the final result.
116
  if completed:
117
+ return generated_texts[result_index], generated_text_complexities[result_index][0], generated_text_complexities[result_index][1], "Success! Please see the converted text at your target reading level."
118
  else:
119
+ return generated_texts[result_index], generated_text_complexities[result_index][0], generated_text_complexities[result_index][1], "Failed. We could not reach the target reading level while maintaining the text meaning."