Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +24 -46
src/streamlit_app.py
CHANGED
|
@@ -37,53 +37,31 @@ def display_status_and_action(text):
|
|
| 37 |
st.warning(warning)
|
| 38 |
st.markdown(text_input)
|
| 39 |
# ์ค๋ฅธ์ชฝ ์ ๋ ฌ์ ์ํ ์ปฌ๋ผ ์ค์
|
| 40 |
-
|
| 41 |
-
# ํ
์คํธ๋ฅผ ์์ฑ์ผ๋ก ๋ณํ
|
| 42 |
-
cleaned_text = re.sub(r'[\x00-\x1F]+', '', tts_text).replace("*", "")
|
| 43 |
-
tts = gTTS(text=cleaned_text, lang='ko')
|
| 44 |
-
mp3_fp = BytesIO()
|
| 45 |
-
tts.write_to_fp(mp3_fp)
|
| 46 |
-
mp3_fp.seek(0)
|
| 47 |
-
audio_bytes = mp3_fp.read()
|
| 48 |
-
b64_audio = base64.b64encode(audio_bytes).decode()
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
.icon-button {
|
| 64 |
-
background-color: transparent;
|
| 65 |
-
border: none;
|
| 66 |
-
cursor: pointer;
|
| 67 |
-
font-size: 28px;
|
| 68 |
-
padding: 0;
|
| 69 |
-
margin: 0;
|
| 70 |
-
}
|
| 71 |
-
</style>
|
| 72 |
-
<form action="#" method="post">
|
| 73 |
-
<button class="icon-button" name="play_audio" type="submit">๐ค</button>
|
| 74 |
-
</form>
|
| 75 |
-
"""
|
| 76 |
-
st.markdown(button_html, unsafe_allow_html=True)
|
| 77 |
-
|
| 78 |
-
# ๋ฒํผ์ด ํด๋ฆญ๋๋์ง ๊ฐ์ง (์ธ์
์ํ๋ก)
|
| 79 |
-
if st.session_state.get("audio_played") is None:
|
| 80 |
-
st.session_state.audio_played = False
|
| 81 |
-
|
| 82 |
-
# ๋ฒํผ ํด๋ฆญ์ ๊ฐ์ง (Streamlit์ form submit ๊ฐ์ง๋ฅผ ๋ชปํ๋ฏ๋ก ์ฐํ ๋ฐฉ๋ฒ ํ์ ์ JS ์ด์ฉ)
|
| 83 |
-
# ์์๋ก ์๋์์ ์กฐ๊ฑด์ ์ผ๋ก ์ฌ์๋ง ํ์ฉ
|
| 84 |
-
if st.query_params.get("play") == "true" or st.session_state.audio_played:
|
| 85 |
-
render_voice_button_and_play_audio(warning + " " + text_input)
|
| 86 |
-
st.session_state.audio_played = False
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
# ์ํ ๋ฐ ์กฐ์น ์ถ๋ ฅ
|
| 89 |
display_status_and_action(selected_text)
|
|
|
|
|
|
| 37 |
st.warning(warning)
|
| 38 |
st.markdown(text_input)
|
| 39 |
# ์ค๋ฅธ์ชฝ ์ ๋ ฌ์ ์ํ ์ปฌ๋ผ ์ค์
|
| 40 |
+
col1, col2, col3 = st.columns([6, 1, 1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
with col3:
|
| 43 |
+
if st.button("๐ค", help="์์ฑ์ผ๋ก ๋ฃ๊ธฐ"):
|
| 44 |
+
text_input = warning + " " + text_input
|
| 45 |
+
cleaned_text = re.sub(r'[\x00-\x1F]+', '', text_input).replace("*", "")
|
| 46 |
+
tts = gTTS(text=cleaned_text, lang='ko')
|
| 47 |
+
mp3_fp = BytesIO()
|
| 48 |
+
tts.write_to_fp(mp3_fp)
|
| 49 |
+
mp3_fp.seek(0)
|
| 50 |
+
|
| 51 |
+
# base64 ์ธ์ฝ๋ฉ
|
| 52 |
+
import base64
|
| 53 |
+
audio_bytes = mp3_fp.read()
|
| 54 |
+
b64_audio = base64.b64encode(audio_bytes).decode()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
# HTML ์ค๋์ค ํ๋ ์ด์ด (์ ์ฒด ๋๋น)
|
| 57 |
+
audio_html = f"""
|
| 58 |
+
<audio controls style="width: 100%;">
|
| 59 |
+
<source src="data:audio/mp3;base64,{b64_audio}" type="audio/mp3">
|
| 60 |
+
๋ธ๋ผ์ฐ์ ๊ฐ ์ค๋์ค๋ฅผ ์ง์ํ์ง ์์ต๋๋ค.
|
| 61 |
+
</audio>
|
| 62 |
+
"""
|
| 63 |
+
st.markdown(audio_html, unsafe_allow_html=True)
|
| 64 |
+
|
| 65 |
# ์ํ ๋ฐ ์กฐ์น ์ถ๋ ฅ
|
| 66 |
display_status_and_action(selected_text)
|
| 67 |
+
|