Spaces:
Runtime error
Runtime error
updates
Browse files
app.py
CHANGED
@@ -116,16 +116,16 @@ with st.sidebar:
|
|
116 |
|
117 |
for i in range(5):
|
118 |
st.write("\n")
|
119 |
-
st.caption("""
|
120 |
-
- 双击页面可直接定位输入栏
|
121 |
-
- Ctrl + Enter 可快捷提交问题
|
122 |
-
""")
|
123 |
|
124 |
st.markdown("OpenAI API Key")
|
125 |
st.text_input("OpenAI API Key", type='password', key='apikey_input', label_visibility='collapsed')
|
126 |
st.caption(
|
127 |
"此Key仅在当前网页有效,且优先级高于Secrets中的配置,仅自己可用,他人无法共享。[官网获取](https://platform.openai.com/account/api-keys)")
|
128 |
|
|
|
|
|
|
|
|
|
129 |
|
130 |
# 加载数据
|
131 |
if ("history" + current_chat not in st.session_state) or (st.session_state['if_chat_change']):
|
@@ -220,38 +220,45 @@ with tap_set:
|
|
220 |
on_change=write_data, key='frequency_penalty' + current_chat)
|
221 |
st.caption("[官网参数说明](https://platform.openai.com/docs/api-reference/completions/create)")
|
222 |
|
|
|
223 |
with tap_input:
|
224 |
def input_callback():
|
225 |
if st.session_state['user_input_area'] != "":
|
226 |
# 修改窗口名称
|
227 |
user_input_content = st.session_state['user_input_area']
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
|
|
|
|
|
|
|
|
|
|
237 |
|
238 |
|
239 |
with st.form("input_form", clear_on_submit=True):
|
240 |
user_input = st.text_area("**输入:**", key="user_input_area")
|
241 |
-
|
242 |
-
wav_audio_data = st_audiorec()
|
243 |
-
if wav_audio_data is not None:
|
244 |
-
st.audio(wav_audio_data, format='audio/wav')
|
245 |
-
bytes_to_wav(wav_audio_data, output_wav_file='output.wav', sample_rate=16000)
|
246 |
-
user_input = WHISPER_MODEL.transcribe('output.wav', language=WHISPER_LANG)['text']
|
247 |
-
st.session_state['user_input_area'] = user_input
|
248 |
-
|
249 |
submitted = st.form_submit_button("确认提交", use_container_width=True, on_click=input_callback)
|
250 |
-
|
251 |
if submitted:
|
252 |
-
st.write("User input: ", user_input)
|
253 |
st.session_state['user_input_content'] = user_input
|
254 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
|
256 |
if st.session_state['user_input_content'] != '':
|
257 |
if 'r' in st.session_state:
|
|
|
116 |
|
117 |
for i in range(5):
|
118 |
st.write("\n")
|
|
|
|
|
|
|
|
|
119 |
|
120 |
st.markdown("OpenAI API Key")
|
121 |
st.text_input("OpenAI API Key", type='password', key='apikey_input', label_visibility='collapsed')
|
122 |
st.caption(
|
123 |
"此Key仅在当前网页有效,且优先级高于Secrets中的配置,仅自己可用,他人无法共享。[官网获取](https://platform.openai.com/account/api-keys)")
|
124 |
|
125 |
+
st.caption("""
|
126 |
+
- 双击页面可直接定位输入栏
|
127 |
+
- Ctrl + Enter 可快捷提交问题
|
128 |
+
""")
|
129 |
|
130 |
# 加载数据
|
131 |
if ("history" + current_chat not in st.session_state) or (st.session_state['if_chat_change']):
|
|
|
220 |
on_change=write_data, key='frequency_penalty' + current_chat)
|
221 |
st.caption("[官网参数说明](https://platform.openai.com/docs/api-reference/completions/create)")
|
222 |
|
223 |
+
|
224 |
with tap_input:
|
225 |
def input_callback():
|
226 |
if st.session_state['user_input_area'] != "":
|
227 |
# 修改窗口名称
|
228 |
user_input_content = st.session_state['user_input_area']
|
229 |
+
elif st.session_state['audio_input'] != "":
|
230 |
+
user_input_content = st.session_state['audio_input']
|
231 |
+
else:
|
232 |
+
return
|
233 |
+
|
234 |
+
df_history = pd.DataFrame(st.session_state["history" + current_chat])
|
235 |
+
if len(df_history.query('role!="system"')) == 0:
|
236 |
+
remove_data(st.session_state["path"], current_chat)
|
237 |
+
current_chat_index = st.session_state['history_chats'].index(current_chat)
|
238 |
+
new_name = extract_chars(user_input_content, 18) + '_' + str(uuid.uuid4())
|
239 |
+
st.session_state['history_chats'][current_chat_index] = new_name
|
240 |
+
st.session_state["current_chat_index"] = current_chat_index
|
241 |
+
# 写入新文件
|
242 |
+
write_data(new_name)
|
243 |
|
244 |
|
245 |
with st.form("input_form", clear_on_submit=True):
|
246 |
user_input = st.text_area("**输入:**", key="user_input_area")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
submitted = st.form_submit_button("确认提交", use_container_width=True, on_click=input_callback)
|
|
|
248 |
if submitted:
|
|
|
249 |
st.session_state['user_input_content'] = user_input
|
250 |
|
251 |
+
wav_audio_data = st_audiorec()
|
252 |
+
if wav_audio_data is not None:
|
253 |
+
st.audio(wav_audio_data, format='audio/wav')
|
254 |
+
bytes_to_wav(wav_audio_data, output_wav_file='output.wav', sample_rate=16000)
|
255 |
+
user_input = WHISPER_MODEL.transcribe('output.wav', language=WHISPER_LANG)['text']
|
256 |
+
st.session_state['audio_input'] = user_input
|
257 |
+
st.session_state['user_input_content'] = user_input
|
258 |
+
input_callback()
|
259 |
+
|
260 |
+
if submitted or wav_audio_data is not None:
|
261 |
+
st.write("User input: ", user_input)
|
262 |
|
263 |
if st.session_state['user_input_content'] != '':
|
264 |
if 'r' in st.session_state:
|