Improve UI

This commit is contained in:
Baize 2023-04-04 16:20:35 +00:00 committed by huggingface-web
parent e0ec530bf4
commit 137041a824
1 changed files with 6 additions and 6 deletions

12
app.py
View File

@ -26,7 +26,7 @@ def predict(text,
max_length_tokens, max_length_tokens,
max_context_length_tokens,): max_context_length_tokens,):
if text=="": if text=="":
yield chatbot,history,"Empty Context" yield chatbot,history,"Empty context."
return return
try: try:
model model
@ -36,7 +36,7 @@ def predict(text,
inputs = generate_prompt_with_history(text,history,tokenizer,max_length=max_context_length_tokens) inputs = generate_prompt_with_history(text,history,tokenizer,max_length=max_context_length_tokens)
if inputs is None: if inputs is None:
yield chatbot,history,"Too Long Input" yield chatbot,history,"Input too long."
return return
else: else:
prompt,inputs=inputs prompt,inputs=inputs
@ -55,11 +55,11 @@ def predict(text,
x = x[:x.index("[|AI|]")].strip() x = x[:x.index("[|AI|]")].strip()
x = x.strip(" ") x = x.strip(" ")
a, b= [[y[0],convert_to_markdown(y[1])] for y in history]+[[text, convert_to_markdown(x)]],history + [[text,x]] a, b= [[y[0],convert_to_markdown(y[1])] for y in history]+[[text, convert_to_markdown(x)]],history + [[text,x]]
yield a, b, "Generating……" yield a, b, "Generating..."
if shared_state.interrupted: if shared_state.interrupted:
shared_state.recover() shared_state.recover()
try: try:
yield a, b, "Stop Success" yield a, b, "Stop: Success"
return return
except: except:
pass pass
@ -68,7 +68,7 @@ def predict(text,
#print(x) #print(x)
#print("="*80) #print("="*80)
try: try:
yield a,b,"Generate Success" yield a,b,"Generate: Success"
except: except:
pass pass
@ -81,7 +81,7 @@ def retry(
max_length_tokens, max_length_tokens,
max_context_length_tokens, max_context_length_tokens,
): ):
logging.info("Retry……") logging.info("Retry...")
if len(history) == 0: if len(history) == 0:
yield chatbot, history, f"Empty context" yield chatbot, history, f"Empty context"
return return