Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -75,6 +75,37 @@ def regenerate(_chatbot, task_history):
|
|
| 75 |
for _chatbot in _chatbot_gen:
|
| 76 |
yield _chatbot
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
def add_text(history, task_history, text):
|
| 79 |
task_text = text
|
| 80 |
history = history if history is not None else []
|
|
|
|
| 75 |
for _chatbot in _chatbot_gen:
|
| 76 |
yield _chatbot
|
| 77 |
|
| 78 |
+
def _parse_text(text):
|
| 79 |
+
lines = text.split("\n")
|
| 80 |
+
lines = [line for line in lines if line != ""]
|
| 81 |
+
count = 0
|
| 82 |
+
for i, line in enumerate(lines):
|
| 83 |
+
if "```" in line:
|
| 84 |
+
count += 1
|
| 85 |
+
items = line.split("`")
|
| 86 |
+
if count % 2 == 1:
|
| 87 |
+
lines[i] = f'<pre><code class="language-{items[-1]}">'
|
| 88 |
+
else:
|
| 89 |
+
lines[i] = f"<br></code></pre>"
|
| 90 |
+
else:
|
| 91 |
+
if i > 0:
|
| 92 |
+
if count % 2 == 1:
|
| 93 |
+
line = line.replace("`", r"\`")
|
| 94 |
+
line = line.replace("<", "<")
|
| 95 |
+
line = line.replace(">", ">")
|
| 96 |
+
line = line.replace(" ", " ")
|
| 97 |
+
line = line.replace("*", "*")
|
| 98 |
+
line = line.replace("_", "_")
|
| 99 |
+
line = line.replace("-", "-")
|
| 100 |
+
line = line.replace(".", ".")
|
| 101 |
+
line = line.replace("!", "!")
|
| 102 |
+
line = line.replace("(", "(")
|
| 103 |
+
line = line.replace(")", ")")
|
| 104 |
+
line = line.replace("$", "$")
|
| 105 |
+
lines[i] = "<br>" + line
|
| 106 |
+
text = "".join(lines)
|
| 107 |
+
return text
|
| 108 |
+
|
| 109 |
def add_text(history, task_history, text):
|
| 110 |
task_text = text
|
| 111 |
history = history if history is not None else []
|