File size: 5,600 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
c74ae22
50430ba
604d506
 
0277cbe
 
 
 
ad67e5c
c076d4e
 
 
 
6a4310a
0277cbe
 
c076d4e
 
 
 
1c98fbb
39ca4e0
 
44a914a
ea8a465
e675193
 
 
 
 
 
 
 
e11efe5
 
 
 
 
 
 
e8655b1
5c5f73c
e11efe5
 
 
ddd761f
 
7cd21ec
 
ddd761f
4428eed
7cd21ec
6eac4ee
 
 
 
 
 
 
 
 
 
 
ddd761f
6eac4ee
e8655b1
5c5f73c
169bc78
4956e0e
169bc78
4956e0e
 
 
 
e11efe5
53d012a
e11efe5
71a9f95
e8655b1
8fcc9de
 
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
121
122
123
124
125
126
# νŒ¨ν‚€μ§€ 뢈러였기
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/mobility_condition/raw/main/chat_icon/text.csv", on_bad_lines='skip') 

# μ˜€λ””μ˜€ ν”Œλ ˆμ΄μ–΄μš© placeholder λ§Œλ“€κΈ°

# 데이터 μƒνƒœ 및 쑰치 상황 ν‘œμ‹œ ν•¨μˆ˜
def display_status_and_action(text):
    if text == "":
        st.info("λ¨Όμ € 데이터λ₯Ό μ„ νƒν•΄μ£Όμ„Έμš”.")
    elif text == "2024-09-26":
        st.line_chart(
            df,
            y=['ECU_DPFSoot']
        )
        st.success("βœ… μ°¨λŸ‰ μƒνƒœ: 정상")
        st.markdown("**쑰치 사항:** μΆ”κ°€ μ‘°μΉ˜λŠ” ν•„μš”ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.")
    else:
        st.line_chart(
            df,
            y=['ECU_DPFSoot']
        )
        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)

if selected_text:
    display_status_and_action(selected_text)