Spaces:
Running
Running
FauziIsyrinApridal
commited on
Commit
Β·
71e79b1
1
Parent(s):
e735ca8
update chat.py st.chat_input outside column
Browse files- app/chat.py +12 -18
app/chat.py
CHANGED
@@ -42,21 +42,22 @@ def conversation_chat(query, chain, history):
|
|
42 |
def display_chat_history(chain):
|
43 |
reply_container = st.container()
|
44 |
|
45 |
-
#
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
with col2:
|
49 |
-
# Toggle Text-to-Speech (TTS) using an icon instead of visible checkbox
|
50 |
should_speak = st.session_state.get('should_speak', True)
|
51 |
-
|
52 |
-
# Handle manual icon toggle (using button instead of checkbox)
|
53 |
icon_label = "π" if should_speak else "π"
|
54 |
if st.button(icon_label, key="toggle_tts", help="Aktifkan/Nonaktifkan Text-to-Speech", use_container_width=True):
|
55 |
st.session_state['should_speak'] = not should_speak
|
56 |
|
57 |
-
|
58 |
with col3:
|
59 |
-
# Mic input
|
60 |
stt_text = speech_to_text(
|
61 |
start_prompt="π€",
|
62 |
stop_prompt="π Stop",
|
@@ -65,18 +66,11 @@ def display_chat_history(chain):
|
|
65 |
key='stt_input',
|
66 |
use_container_width=True,
|
67 |
)
|
68 |
-
|
69 |
-
with col1:
|
70 |
-
# Use chat_input so it's pinned and integrated better
|
71 |
-
user_input_obj = st.chat_input(
|
72 |
-
"Masukkan pertanyaan atau Tekan tombol mic untuk berbicara!",
|
73 |
-
key="chat_input_field"
|
74 |
-
)
|
75 |
|
76 |
-
#
|
77 |
if stt_text:
|
78 |
st.session_state.input_text = stt_text
|
79 |
-
st.
|
80 |
|
81 |
user_input = user_input_obj or st.session_state.get("input_text", "")
|
82 |
|
@@ -86,12 +80,11 @@ def display_chat_history(chain):
|
|
86 |
|
87 |
st.session_state['past'].append(user_input)
|
88 |
st.session_state['generated'].append(output)
|
89 |
-
st.session_state.input_text = ""
|
90 |
|
91 |
if st.session_state['should_speak'] and output:
|
92 |
st.markdown(text_to_speech(output), unsafe_allow_html=True)
|
93 |
|
94 |
-
# Tampilkan riwayat chat
|
95 |
if st.session_state['generated']:
|
96 |
with reply_container:
|
97 |
for i in range(len(st.session_state['generated'])):
|
@@ -99,3 +92,4 @@ def display_chat_history(chain):
|
|
99 |
message(st.session_state["generated"][i], key=str(i), avatar_style="no-avatar")
|
100 |
|
101 |
|
|
|
|
42 |
def display_chat_history(chain):
|
43 |
reply_container = st.container()
|
44 |
|
45 |
+
# Pindahkan chat_input ke luar kolom, biar di root level:
|
46 |
+
user_input_obj = st.chat_input(
|
47 |
+
"Masukkan pertanyaan atau Tekan tombol mic untuk berbicara!",
|
48 |
+
key="chat_input_field"
|
49 |
+
)
|
50 |
+
|
51 |
+
# Sekarang baru buat kolom untuk tombol toggle dan mic:
|
52 |
+
col2, col3 = st.columns([1, 1])
|
53 |
|
54 |
with col2:
|
|
|
55 |
should_speak = st.session_state.get('should_speak', True)
|
|
|
|
|
56 |
icon_label = "π" if should_speak else "π"
|
57 |
if st.button(icon_label, key="toggle_tts", help="Aktifkan/Nonaktifkan Text-to-Speech", use_container_width=True):
|
58 |
st.session_state['should_speak'] = not should_speak
|
59 |
|
|
|
60 |
with col3:
|
|
|
61 |
stt_text = speech_to_text(
|
62 |
start_prompt="π€",
|
63 |
stop_prompt="π Stop",
|
|
|
66 |
key='stt_input',
|
67 |
use_container_width=True,
|
68 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
+
# STT handling dan input processing tetap sama
|
71 |
if stt_text:
|
72 |
st.session_state.input_text = stt_text
|
73 |
+
st.experimental_rerun() # pakai rerun yang direkomendasikan
|
74 |
|
75 |
user_input = user_input_obj or st.session_state.get("input_text", "")
|
76 |
|
|
|
80 |
|
81 |
st.session_state['past'].append(user_input)
|
82 |
st.session_state['generated'].append(output)
|
83 |
+
st.session_state.input_text = ""
|
84 |
|
85 |
if st.session_state['should_speak'] and output:
|
86 |
st.markdown(text_to_speech(output), unsafe_allow_html=True)
|
87 |
|
|
|
88 |
if st.session_state['generated']:
|
89 |
with reply_container:
|
90 |
for i in range(len(st.session_state['generated'])):
|
|
|
92 |
message(st.session_state["generated"][i], key=str(i), avatar_style="no-avatar")
|
93 |
|
94 |
|
95 |
+
|