not-lain commited on
Commit
c2115a0
1 Parent(s): 81994ae

update hidden word handling

Browse files
Files changed (1) hide show
  1. app.py +21 -14
app.py CHANGED
@@ -8,6 +8,7 @@ import os
8
  from typing import Optional, List
9
  import string
10
  import random
 
11
 
12
 
13
  def extract_text_from_pptx(file_path):
@@ -122,23 +123,29 @@ def handle_json_output(json_list : list) :
122
  random_string1 = generate_random_string()
123
  random_string2 = generate_random_string()
124
  element = json_list[i]
 
 
125
  element["frontHTML"] = (f'<div id="element-richtextarea-{random_string1}" style="position:absolute;left:100px;top:50px;width:800px;height:300px;text-align:center;display:flex;align-items:center;font-size:40px;\">'
126
- f'<p>{element["frontText"]}</p></div>')
127
  element["backtHTML"] = (f'<div id="element-richtextarea-{random_string2}" style="position:absolute;left:100px;top:50px;width:800px;height:300px;text-align:center;display:flex;align-items:center;font-size:40px;\">'
128
- f'<p>{element["backText"]}</p></div>')
129
- # middle item
130
- if i != n-1 :
131
- element["termType"] = "basic"
132
- # element["frontHTML"] = (f'<div id="element-richtextarea-{random_string1}" style="position:absolute;left:100px;top:50px;width:800px;height:300px;text-align:center;display:flex;align-items:center;font-size:40px;\">'
133
- # f'<p>{element["frontText"]}</p></div>')
134
- # element["backtHTML"] = (f'<div id="element-richtextarea-{random_string2}" style="position:absolute;left:100px;top:50px;width:800px;height:300px;text-align:center;display:flex;align-items:center;font-size:40px;\">'
135
- # f'<p>{element["backText"]}</p></div>')
136
- # # last item on the list
137
- else:
138
  element["termType"] = "cloze"
139
- # element["frontHTML"] = (f'<div id="element-richtextarea-{random_string1}" style="position:absolute;left:100px;top:50px;width:800px;height:300px;text-align:center;display:flex;align-items:center;font-size:40px;\">'
140
- # f'<p>{element["frontText"]}</p> <p><span class="closure" data-index="1" data-hint="">{element["backText"]}</p></div>')
141
- # element["backText"] , element["backHTML"] = "" , ""
 
 
 
 
 
 
 
 
142
  return json_list
143
 
144
 
 
8
  from typing import Optional, List
9
  import string
10
  import random
11
+ import re
12
 
13
 
14
  def extract_text_from_pptx(file_path):
 
123
  random_string1 = generate_random_string()
124
  random_string2 = generate_random_string()
125
  element = json_list[i]
126
+ front = element["frontText"]
127
+ back = element["backText"]
128
  element["frontHTML"] = (f'<div id="element-richtextarea-{random_string1}" style="position:absolute;left:100px;top:50px;width:800px;height:300px;text-align:center;display:flex;align-items:center;font-size:40px;\">'
129
+ f'<p>{front}</p></div>')
130
  element["backtHTML"] = (f'<div id="element-richtextarea-{random_string2}" style="position:absolute;left:100px;top:50px;width:800px;height:300px;text-align:center;display:flex;align-items:center;font-size:40px;\">'
131
+ f'<p>{back}</p></div>')
132
+ element["termType"] = "basic"
133
+ cloze_matches = re.findall(r'_{2,}', front)
134
+ # match only the first one, if there is multiple don't do anything
135
+ if cloze_matches != [] & len(cloze_matches != 2):
136
+ # It's a cloze type card
 
 
 
 
137
  element["termType"] = "cloze"
138
+ # inject the back in a span format into the front
139
+ def replace_cloze(match):
140
+ return f'</p><p><span class="closure">{back}</span></p><p>'
141
+ front = re.sub(r'_{2,}', replace_cloze, front)
142
+ # update
143
+ element["frontHTML"] = (f'<div id="element-richtextarea-{random_string1}" style="position:absolute;left:100px;top:50px;width:800px;height:300px;text-align:center;display:flex;align-items:center;font-size:40px;\">'
144
+ f'<p>{front}</p></div>')
145
+ element["backText"] = ""
146
+ element["backtHTML"] = (f'<div id="element-richtextarea-{random_string2}" style="position:absolute;left:100px;top:50px;width:800px;height:300px;text-align:center;display:flex;align-items:center;font-size:40px;\">'
147
+ f'<p><br></p></div>')
148
+
149
  return json_list
150
 
151