Spaces:
Sleeping
Sleeping
File size: 5,516 Bytes
236cd6c 4a4ded1 83a90dd 39adf97 48ee50b 7b2398c 4a571e2 d31c393 0277cbe 236cd6c 0277cbe 236cd6c cfecc8f 0277cbe 236cd6c cfecc8f 2ef2340 6a4310a cfecc8f 0277cbe ea8a465 4a6a60c ea8a465 4a6a60c ea8a465 cbd60e4 4a571e2 0277cbe ad67e5c 4a571e2 6a4310a 0277cbe 4a571e2 1c98fbb 39ca4e0 44a914a ea8a465 e675193 e11efe5 e8655b1 7cd21ec e11efe5 4428eed 7cd21ec e11efe5 4428eed 7cd21ec 4428eed 7cd21ec e8655b1 4428eed e8655b1 4428eed e11efe5 53d012a e11efe5 e8655b1 0277cbe 010a7ca | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | # ν¨ν€μ§ λΆλ¬μ€κΈ°
import re
import base64
from io import BytesIO
import streamlit as st
import numpy as np
import pandas as pd
from gtts import gTTS
# assitant μλ°ν μ΄λ―Έμ§ κ²½λ‘
assistant_icon_path = "https://huggingface.co/spaces/randmimc/aitom/resolve/main/chat_icon/assistant.ico"
# μΈμ
μνμμ approval_state λ° messages μ΄κΈ°ν
if "approval_state" not in st.session_state:
st.session_state.approval_state = "require"
if "messages" not in st.session_state:
st.session_state.messages = []
# λλ‘λ€μ΄ λ©λ΄
st.subheader("λ°μ΄ν° μ ν")
options = [
"",
"2024-08-24",
"2024-09-26"
]
selected_text = st.selectbox("λ°μ΄ν°λ₯Ό μ ννμΈμ", options)
# 컀μ€ν
CSS μ½μ
st.markdown("""
<style>
div.stButton > button {
background-color: transparent;
border: none;
color: black;
font-size: 30px;
padding: 0;
}
div.stButton > button:hover {
color: red;
cursor: pointer;
}
</style>
""", unsafe_allow_html=True)
df = pd.read_csv("https://huggingface.co/spaces/randmimc/aitom/resolve/main/chat_icon/test_data.csv")
print(len(df))
chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
# λ°μ΄ν° μν λ° μ‘°μΉ μν© νμ ν¨μ
def display_status_and_action(text):
if text == "":
st.info("λ¨Όμ λ°μ΄ν°λ₯Ό μ νν΄μ£ΌμΈμ.")
elif text == "2024-09-26":
st.line_chart(chart_data)
st.success("β
μ°¨λ μν: μ μ")
st.markdown("**μ‘°μΉ μ¬ν:** μΆκ° μ‘°μΉλ νμνμ§ μμ΅λλ€.")
else:
st.line_chart(chart_data)
text_input = "μμ μ¦μλ€μ΄ λ³΄μΌ κ²½μ°, λ€μκ³Ό κ°μ μ‘°μΉλ₯Ό μ·¨νλ κ²μ΄ νμν©λλ€:\n\n1. **μλμ¬μ μλ**: μ°μ μ μΌλ‘ μΌλ°μ μΈ μλ μ¬μμ μ§ννμ¬ DPF μμ€ν
μ΄ μ μμ μΌλ‘ μλνλμ§ νμΈν©λλ€. μ°¨λ μλλ μ½ 60km/hλ‘ μ μ§νκ³ , 20λΆ μ΄μ μ£Όννμ¬ DPF μμ€ν
μ΄ μ€μ€λ‘ sootλ₯Ό μ κ±°νλλ‘ ν©λλ€.\n\n2. **DPF μλ μ κ±° λ²νΌ νμ©**: λ§μ½ μλμ¬μμ΄ μ΄λ €μ΄ μνλΌλ©΄, DPF μλ μ κ±° λ²νΌμ ν΅ν΄ μ΄μ μκ° κ°μ λ‘ sootλ₯Ό μ κ±°νλ λ°©λ²μ μλν΄ λ΄
λλ€.\n\n3. **μ λΉμ λ°©λ¬Έ**: μλ μ¬μμ΄λ μλ μ κ±° λ²νΌμ ν΅ν΄μλ λ¬Έμ κ° ν΄κ²°λμ§ μμ κ²½μ°, κ°κΉμ΄ μ λΉμλ₯Ό λ°©λ¬Ένμ¬ DPF μμ€ν
μ μ κ² λ°λ κ²μ΄ μ€μν©λλ€. μ΄λ μΌμ λΆλμ΄λ DPF νν° λ¬Έμ λ± λ€λ₯Έ μμΈμ νμ
νλ λ° λμμ΄ λ©λλ€.\n\n4. **λ°°κΈ°κ³ν΅ μ κ²**: ν΄λΉ νμμ΄ μ§μ λ°κ²¬λ κ²½μ° λ§μ½μ λλΉνμ¬ μ°¨λ μ체μ λ°°κΈ°κ³ν΅ μ κ²μ νλ κ²μ΄ μΆμ²λ©λλ€.\n\n**μ μμ μΈ κ²½μ°**: λ§μ½ soot μμΉκ° μ μ ν νμ΄λ°μ μ°μλμ΄ μμ΄μ§κ³ μ 체μ μΌλ‘ λ΄€μ λ μΆμ λμ΄ 40μ μ΄κ³Όνλ ꡬκ°μ΄ μ‘΄μ¬νμ§ μλλ€λ©΄, μ΄λ μ μμ μ΄λ©° λ¬Έμ μμ΅λλ€"
warning = "β οΈ μΌμ μμΉ μ΄μμ Soot μΆμ λμ΄ 2μκ° μ΄μ μ§μλλ νμμ 보μ. \nSoot κ° μΌμ μμΉμ λλ¬νμλ μ μμ μΌλ‘ μ°μλμ§ μκ±°λ, μΌμ λΆλμΌλ‘ μΈν΄ Dosing μ΄ κ³Όνκ² νμ±νλ¨. \nsoot κ° μ¦κ°νλ κ³Όμ μμ λΆκ·μΉμ μΈ μ¦κ° νμμ΄ λ°μν¨. \nν λλ λΉμ ν ννκ° ν¬κ² λνλ¨. \nSoot μ μΆμ λμ΄ 40μ μ΄κ³Όνλ ꡬκ°μ΄ μ‘΄μ¬ν¨."
st.warning(warning)
st.markdown(text_input)
text_input = warning + " " + text_input
cleaned_text = re.sub(r'[\x00-\x1F]+', '', text_input).replace("*", "")
tts = gTTS(text=cleaned_text, lang='ko')
mp3_fp = BytesIO()
tts.write_to_fp(mp3_fp)
# μ€λμ€ μ€νΈλ¦Ό μ¬μ€μ ν μ¬μ
mp3_fp.seek(0)
# Base64 μΈμ½λ©
audio_bytes = mp3_fp.read()
audio_base64 = base64.b64encode(audio_bytes).decode()
# HTML μ€νμΌ λ° μ€λμ€ μΆλ ₯
audio_html = f"""
<style>
.audio-container {{
display: flex;
align-items: center;
gap: 10px;
justify-content: flex-end; /* μ€λ₯Έμͺ½ μ λ ¬ */
margin-top: 10px;
}}
.audio-icon {{
font-size: 30px;
cursor: pointer;
}}
.audio-icon[title]:hover::after {{
content: attr(title);
position: absolute;
background: #333;
color: #fff;
padding: 5px 8px;
border-radius: 5px;
white-space: nowrap;
font-size: 12px;
top: -35px;
right: 0;
z-index: 999;
}}
</style>
<div class="audio-container">
<div class="audio-icon" title="μ λ΄μ©μ μμ±μΌλ‘ λ£κΈ°">π</div>
<audio controls>
<source src="data:audio/mp3;base64,{audio_base64}" type="audio/mp3">
λΈλΌμ°μ κ° μ€λμ€ νκ·Έλ₯Ό μ§μνμ§ μμ΅λλ€.
</audio>
</div>
"""
# HTML λ λλ§
st.markdown(audio_html, unsafe_allow_html=True)
# μν λ° μ‘°μΉ μΆλ ₯
display_status_and_action(selected_text)
|