Spaces:
Paused
Paused
Update utils.py
Browse files
utils.py
CHANGED
@@ -145,3 +145,37 @@ def greedy_search(input_ids: torch.Tensor,
|
|
145 |
del probs_sum
|
146 |
gc.collect()
|
147 |
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
del probs_sum
|
146 |
gc.collect()
|
147 |
return
|
148 |
+
|
149 |
+
def convert_to_markdown(text):
|
150 |
+
text = text.replace("$","$")
|
151 |
+
def replace_leading_tabs_and_spaces(line):
|
152 |
+
new_line = []
|
153 |
+
|
154 |
+
for char in line:
|
155 |
+
if char == "\t":
|
156 |
+
new_line.append("	")
|
157 |
+
elif char == " ":
|
158 |
+
new_line.append(" ")
|
159 |
+
else:
|
160 |
+
break
|
161 |
+
return "".join(new_line) + line[len(new_line):]
|
162 |
+
|
163 |
+
markdown_text = ""
|
164 |
+
lines = text.split("\n")
|
165 |
+
in_code_block = False
|
166 |
+
|
167 |
+
for line in lines:
|
168 |
+
if in_code_block is False and line.startswith("```"):
|
169 |
+
in_code_block = True
|
170 |
+
markdown_text += f"{line}\n"
|
171 |
+
elif in_code_block is True and line.startswith("```"):
|
172 |
+
in_code_block = False
|
173 |
+
markdown_text += f"{line}\n"
|
174 |
+
elif in_code_block:
|
175 |
+
markdown_text += f"{line}\n"
|
176 |
+
else:
|
177 |
+
line = replace_leading_tabs_and_spaces(line)
|
178 |
+
line = re.sub(r"^(#)", r"\\\1", line)
|
179 |
+
markdown_text += f"{line} \n"
|
180 |
+
|
181 |
+
return markdown_text
|