yejunliang23 commited on
Commit
23a049d
·
unverified ·
1 Parent(s): 6af08b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
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("<", "&lt;")
95
+ line = line.replace(">", "&gt;")
96
+ line = line.replace(" ", "&nbsp;")
97
+ line = line.replace("*", "&ast;")
98
+ line = line.replace("_", "&lowbar;")
99
+ line = line.replace("-", "&#45;")
100
+ line = line.replace(".", "&#46;")
101
+ line = line.replace("!", "&#33;")
102
+ line = line.replace("(", "&#40;")
103
+ line = line.replace(")", "&#41;")
104
+ line = line.replace("$", "&#36;")
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 []