copy from https://github.com/GaiZhenbiao/ChuanhuChatGPT/
(text)
| 80 | |
| 81 | |
| 82 | def parse_text(text): |
| 83 | """copy from https://github.com/GaiZhenbiao/ChuanhuChatGPT/""" |
| 84 | lines = text.split("\n") |
| 85 | lines = [line for line in lines if line != ""] |
| 86 | count = 0 |
| 87 | for i, line in enumerate(lines): |
| 88 | if "```" in line: |
| 89 | count += 1 |
| 90 | items = line.split('`') |
| 91 | if count % 2 == 1: |
| 92 | lines[i] = f'<pre><code class="language-{items[-1]}">' |
| 93 | else: |
| 94 | lines[i] = f'<br></code></pre>' |
| 95 | else: |
| 96 | if i > 0: |
| 97 | if count % 2 == 1: |
| 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 | line = line.replace(".", ".") |
| 106 | line = line.replace("!", "!") |
| 107 | line = line.replace("(", "(") |
| 108 | line = line.replace(")", ")") |
| 109 | line = line.replace("$", "$") |
| 110 | lines[i] = "<br>"+line |
| 111 | text = "".join(lines) |
| 112 | return text |
| 113 | |
| 114 | |
| 115 | def predict(input, chatbot, max_length, top_p, temperature, history): |