JUNGU commited on
Commit
6b774ce
Β·
1 Parent(s): f85fae2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -11
app.py CHANGED
@@ -79,22 +79,39 @@ def generate_response(user_input):
79
  def wrap_text(text, max_length=40):
80
  return '\n'.join(textwrap.wrap(text, max_length))
81
 
 
 
82
 
83
- st.header("[μƒμƒμ§„λ‘œν†΅] μ•½μ‚¬μ˜ κΈΈ \n μ‹€μ œ μ•½μ‚¬μ˜ 인터뷰 λ‚΄μš©μ„ 기반으둜 μ§„λ‘œ 상담을 ν•΄λ³΄μ„Έμš”")
 
 
84
 
85
- with st.form('form', clear_on_submit=True):
86
- user_input = st.text_input('You: ', '', key='input')
87
- submitted = st.form_submit_button('Send')
88
 
89
- if submitted and user_input:
90
- with st.spinner('응닡을 μƒμ„±μ€‘μž…λ‹ˆλ‹€...'):
91
- output = generate_response(user_input)
 
 
92
 
93
- st.session_state.chat_history.append({"User": user_input, "Bot": output})
 
 
 
 
 
 
 
 
 
 
94
 
95
- for idx, chat in enumerate(st.session_state['chat_history'][:-1]):
96
- message(chat['User'], is_user=True, key=str(idx) + '_user')
97
- message(wrap_text("약사: " + chat['Bot']), key=str(idx))
 
98
 
99
  if st.session_state['chat_history']:
100
  last_chat = st.session_state['chat_history'][-1]
@@ -105,3 +122,13 @@ if st.session_state['chat_history']:
105
  for j in range(len(last_chat['Bot'])):
106
  new_placeholder.text(wrap_text(sender_name + last_chat['Bot'][:j+1]))
107
  time.sleep(0.05)
 
 
 
 
 
 
 
 
 
 
 
79
  def wrap_text(text, max_length=40):
80
  return '\n'.join(textwrap.wrap(text, max_length))
81
 
82
+
83
+ # st.header("[μƒμƒμ§„λ‘œν†΅] μ•½μ‚¬μ˜ κΈΈ \n μ‹€μ œ μ•½μ‚¬μ˜ 인터뷰 λ‚΄μš©μ„ 기반으둜 μ§„λ‘œ 상담을 ν•΄λ³΄μ„Έμš”")
84
 
85
+ # with st.form('form', clear_on_submit=True):
86
+ # user_input = st.text_input('You: ', '', key='input')
87
+ # submitted = st.form_submit_button('Send')
88
 
89
+ # if submitted and user_input:
90
+ # with st.spinner('응닡을 μƒμ„±μ€‘μž…λ‹ˆλ‹€...'):
91
+ # output = generate_response(user_input)
92
 
93
+ # st.session_state.chat_history.append({"User": user_input, "Bot": output})
94
+
95
+ # for idx, chat in enumerate(st.session_state['chat_history'][:-1]):
96
+ # message(chat['User'], is_user=True, key=str(idx) + '_user')
97
+ # message(wrap_text("약사: " + chat['Bot']), key=str(idx))
98
 
99
+ # if st.session_state['chat_history']:
100
+ # last_chat = st.session_state['chat_history'][-1]
101
+ # message(last_chat['User'], is_user=True, key=str(len(st.session_state['chat_history'])-1) + '_user')
102
+
103
+ # new_placeholder = st.empty()
104
+ # sender_name = "약사: "
105
+ # for j in range(len(last_chat['Bot'])):
106
+ # new_placeholder.text(wrap_text(sender_name + last_chat['Bot'][:j+1]))
107
+ # time.sleep(0.05)
108
+
109
+ st.header("[μƒμƒμ§„λ‘œν†΅] μ•½μ‚¬μ˜ κΈΈ \n μ‹€μ œ μ•½μ‚¬μ˜ 인터뷰 λ‚΄μš©μ„ 기반으둜 μ§„λ‘œ 상담을 ν•΄λ³΄μ„Έμš”")
110
 
111
+ if st.session_state['chat_history']:
112
+ for idx, chat in enumerate(st.session_state['chat_history'][:-1]):
113
+ message(chat['User'], is_user=True, key=str(idx) + '_user')
114
+ message(wrap_text("약사: " + chat['Bot']), key=str(idx))
115
 
116
  if st.session_state['chat_history']:
117
  last_chat = st.session_state['chat_history'][-1]
 
122
  for j in range(len(last_chat['Bot'])):
123
  new_placeholder.text(wrap_text(sender_name + last_chat['Bot'][:j+1]))
124
  time.sleep(0.05)
125
+
126
+ with st.form('form', clear_on_submit=True):
127
+ user_input = st.text_input('You: ', '', key='input')
128
+ submitted = st.form_submit_button('Send')
129
+
130
+ if submitted and user_input:
131
+ with st.spinner('응닡을 μƒμ„±μ€‘μž…λ‹ˆλ‹€...'):
132
+ output = generate_response(user_input)
133
+
134
+ st.session_state.chat_history.append({"User": user_input, "Bot": output})