去除trans_web_demo中无用的parse_text模块
This commit is contained in:
parent
1bd342059d
commit
8dcd196955
|
@ -67,38 +67,6 @@ class StopOnTokens(StoppingCriteria):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def parse_text(text):
|
|
||||||
lines = text.split("\n")
|
|
||||||
lines = [line for line in lines if line != ""]
|
|
||||||
count = 0
|
|
||||||
for i, line in enumerate(lines):
|
|
||||||
if "```" in line:
|
|
||||||
count += 1
|
|
||||||
items = line.split('`')
|
|
||||||
if count % 2 == 1:
|
|
||||||
lines[i] = f'<pre><code class="language-{items[-1]}">'
|
|
||||||
else:
|
|
||||||
lines[i] = f'<br></code></pre>'
|
|
||||||
else:
|
|
||||||
if i > 0:
|
|
||||||
if count % 2 == 1:
|
|
||||||
line = line.replace("`", "\`")
|
|
||||||
line = line.replace("<", "<")
|
|
||||||
line = line.replace(">", ">")
|
|
||||||
line = line.replace(" ", " ")
|
|
||||||
line = line.replace("*", "*")
|
|
||||||
line = line.replace("_", "_")
|
|
||||||
line = line.replace("-", "-")
|
|
||||||
line = line.replace(".", ".")
|
|
||||||
line = line.replace("!", "!")
|
|
||||||
line = line.replace("(", "(")
|
|
||||||
line = line.replace(")", ")")
|
|
||||||
line = line.replace("$", "$")
|
|
||||||
lines[i] = "<br>" + line
|
|
||||||
text = "".join(lines)
|
|
||||||
return text
|
|
||||||
|
|
||||||
|
|
||||||
def predict(history, prompt, max_length, top_p, temperature):
|
def predict(history, prompt, max_length, top_p, temperature):
|
||||||
stop = StopOnTokens()
|
stop = StopOnTokens()
|
||||||
messages = []
|
messages = []
|
||||||
|
@ -160,11 +128,11 @@ with gr.Blocks() as demo:
|
||||||
|
|
||||||
|
|
||||||
def user(query, history):
|
def user(query, history):
|
||||||
return "", history + [[parse_text(query), ""]]
|
return "", history + [[query, ""]]
|
||||||
|
|
||||||
|
|
||||||
def set_prompt(prompt_text):
|
def set_prompt(prompt_text):
|
||||||
return [[parse_text(prompt_text), "成功设置prompt"]]
|
return [[prompt_text, "成功设置prompt"]]
|
||||||
|
|
||||||
|
|
||||||
pBtn.click(set_prompt, inputs=[prompt_input], outputs=chatbot)
|
pBtn.click(set_prompt, inputs=[prompt_input], outputs=chatbot)
|
||||||
|
|
Loading…
Reference in New Issue