GGLS commited on
Commit
2dafff9
·
verified ·
1 Parent(s): f6048e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -65,26 +65,28 @@ for message in st.session_state.messages:
65
  def set_query(query):
66
  st.session_state.messages.append({"role": "user", "content": query})
67
  # Create a list of candidate questions
68
- candidate_questions = ["Is boiling water (100°C) an obtuse angle (larger than 90 degrees)?", "Write a quicksort code in Python.", "笼子里有好几只鸡和兔子。笼子里有72个头,200只腿。里面有多少只鸡和兔子"]
69
  # Display the chat interface with a list of clickable question buttons
70
  for question in candidate_questions:
71
  st.sidebar.button(label=question, on_click=set_query, args=[question])
72
 
73
  def clear_chat_history():
74
- st.session_state.messages = [{"role": "assistant", "content": "How may I assist you today?"}]
 
75
  st.sidebar.button('Clear Chat History', on_click=clear_chat_history)
76
 
77
-
78
  def generate_fusechat_response():
79
  conversations=[]
80
  conversations.append({"role": "system", "content": "You are FuseChat-3.0, created by Sun Yat-sen University. You are a helpful assistant."})
81
  for dict_message in st.session_state.messages:
82
  if dict_message["role"] == "user":
83
- conversations.append({"role": "user", "content": dict_message["content"]})
84
  else:
85
- conversations.append({"role": "assistant", "content": dict_message["content"]})
86
- string_dialogue = tokenizer.apply_chat_template(conversations, tokenize=False, add_generation_prompt=True)
87
- input_ids = tokenizer(string_dialogue, return_tensors="pt").input_ids.to('cuda')
 
88
  streamer = TextIteratorStreamer(tokenizer, timeout=10.0, skip_prompt=True, skip_special_tokens=True)
89
  generate_kwargs = dict(
90
  {"input_ids": input_ids},
 
65
  def set_query(query):
66
  st.session_state.messages.append({"role": "user", "content": query})
67
  # Create a list of candidate questions
68
+ candidate_questions = ["Is boiling water (100 degrees) an obtuse angle (larger than 90 degrees)?", "Write a quicksort code in Python.", "笼子里有好几只鸡和兔子。笼子里有72个头,200只腿。里面有多少只鸡和兔子"]
69
  # Display the chat interface with a list of clickable question buttons
70
  for question in candidate_questions:
71
  st.sidebar.button(label=question, on_click=set_query, args=[question])
72
 
73
  def clear_chat_history():
74
+ st.session_state.messages = []
75
+ # st.session_state.messages = [{"role": "assistant", "content": "How may I assist you today?"}]
76
  st.sidebar.button('Clear Chat History', on_click=clear_chat_history)
77
 
78
+ @torch.no_grad()
79
  def generate_fusechat_response():
80
  conversations=[]
81
  conversations.append({"role": "system", "content": "You are FuseChat-3.0, created by Sun Yat-sen University. You are a helpful assistant."})
82
  for dict_message in st.session_state.messages:
83
  if dict_message["role"] == "user":
84
+ conversations.append({"role":"user", "content":dict_message["content"]})
85
  else:
86
+ conversations.append({"role":"assistant", "content":dict_message["content"]})
87
+ string_dialogue = tokenizer.apply_chat_template(conversations,tokenize=False,add_generation_prompt=True)
88
+ input_ids = tokenizer(string_dialogue,
89
+ return_tensors="pt").input_ids.to('cuda')
90
  streamer = TextIteratorStreamer(tokenizer, timeout=10.0, skip_prompt=True, skip_special_tokens=True)
91
  generate_kwargs = dict(
92
  {"input_ids": input_ids},