Liyonghui commited on
Commit
37c76dc
1 Parent(s): 5387022

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +29 -11
  2. logo.jpg +0 -0
app.py CHANGED
@@ -183,6 +183,7 @@ def checklen(text):
183
  return text
184
 
185
  def getanswerByXunFei(t):
 
186
  text.clear()
187
  question = checklen(getText("user", t))
188
  ans = ""
@@ -191,19 +192,36 @@ def getanswerByXunFei(t):
191
  return answer
192
 
193
 
194
- st.markdown("我是讯飞聊天机器人,我可以回答您的任何问题")
 
 
195
  if 'generated' not in st.session_state:
196
  st.session_state['generated'] = []
 
197
  if 'past' not in st.session_state:
198
  st.session_state['past'] = []
199
- user_input=st.text_input("请输入您的问题:",key='input')
200
- if user_input:
201
- output=getanswerByXunFei(user_input)
202
- st.session_state['past'].append(user_input)
203
- st.session_state['generated'].append(output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  if st.session_state['generated']:
205
- for i in range(len(st.session_state['generated'])-1, -1, -1):
206
- message(st.session_state["generated"][i], key=str(i))
207
- message(st.session_state['past'][i],
208
- is_user=True,
209
- key=str(i)+'_user')
 
183
  return text
184
 
185
  def getanswerByXunFei(t):
186
+ st.session_state['prompts'].append(t)
187
  text.clear()
188
  question = checklen(getText("user", t))
189
  ans = ""
 
192
  return answer
193
 
194
 
195
+ if 'prompts' not in st.session_state:
196
+ st.session_state['prompts'] = []
197
+
198
  if 'generated' not in st.session_state:
199
  st.session_state['generated'] = []
200
+
201
  if 'past' not in st.session_state:
202
  st.session_state['past'] = []
203
+
204
+ def end_click():
205
+ st.session_state['prompts'] = []
206
+ st.session_state['past'] = []
207
+ st.session_state['generated'] = []
208
+ st.session_state['user'] = ""
209
+ def chat_click():
210
+ if st.session_state['user'] != '':
211
+ chat_input = st.session_state['user']
212
+ output = getanswerByXunFei(chat_input)
213
+ st.session_state['past'].append(chat_input)
214
+ st.session_state['generated'].append(output)
215
+ st.session_state['prompts'].append(output)
216
+ st.session_state['user'] = ""
217
+ st.image("./logo.jpg", use_column_width='auto')
218
+ st.title("珠宝贝专属聊天机器人")
219
+
220
+ user_input = st.text_input("输入:", key="user")
221
+ chat_button = st.button("发送", on_click=chat_click)
222
+ end_button = st.button("新聊天", on_click=end_click)
223
+
224
  if st.session_state['generated']:
225
+ for i in range(0, len(st.session_state['generated']), 1):
226
+ message(st.session_state['past'][i], is_user=True)
227
+ message(st.session_state['generated'][i], key=str(i))
 
 
logo.jpg ADDED