randmimc commited on
Commit
d953f41
ยท
verified ยท
1 Parent(s): 4a8b73c

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +6 -42
src/streamlit_app.py CHANGED
@@ -33,8 +33,7 @@ def tts_engine(text):
33
  # Base64 ์ธ์ฝ”๋”ฉ
34
  audio_bytes = mp3_fp.read()
35
  audio_base64 = base64.b64encode(audio_bytes).decode()
36
- return audio_base64
37
-
38
 
39
  def none_temp():
40
  st.info("๋จผ์ € ๋ฐ์ดํ„ฐ๋ฅผ ์„ ํƒํ•ด ์ฃผ์„ธ์š”")
@@ -44,48 +43,14 @@ def normal(df, col_name):
44
  st.success("โœ… ์ฐจ๋Ÿ‰ ์ƒํƒœ: ์ •์ƒ")
45
  st.markdown("**์กฐ์น˜ ์‚ฌํ•ญ:** ์ถ”๊ฐ€ ์กฐ์น˜๋Š” ํ•„์š”ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.")
46
 
47
- def anormal(df, col_name, warning, text_input, audio_base64):
48
  # custom style
49
- audio_html = f"""
50
- <style>
51
- .audio-container {{
52
- display: flex;
53
- align-items: center;
54
- gap: 10px;
55
- justify-content: flex-end; /* ์˜ค๋ฅธ์ชฝ ์ •๋ ฌ */
56
- margin-top: 10px;
57
- }}
58
- .audio-icon {{
59
- font-size: 30px;
60
- cursor: pointer;
61
- }}
62
- .audio-icon[title]:hover::after {{
63
- content: attr(title);
64
- position: absolute;
65
- background: #333;
66
- color: #fff;
67
- padding: 5px 8px;
68
- border-radius: 5px;
69
- white-space: nowrap;
70
- font-size: 12px;
71
- top: -35px;
72
- right: 0;
73
- z-index: 999;
74
- }}
75
- </style>
76
-
77
- <div class="audio-container">
78
- <div class="audio-icon" title="์œ„ ๋‚ด์šฉ์„ ์Œ์„ฑ์œผ๋กœ ๋“ฃ๊ธฐ">๐Ÿ”Š</div>
79
- <audio controls>
80
- <source src="data:audio/mp3;base64,{audio_base64}" type="audio/mp3">
81
- ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์˜ค๋””์˜ค ํƒœ๊ทธ๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
82
- </audio>
83
- </div>
84
- """
85
  chart_generate(df, col_name)
86
  st.warning(warning)
87
  st.markdown(text_input)
88
- st.markdown(audio_html, unsafe_allow_html=True)
 
89
 
90
  # ์„œ๋น„์Šค ์‹คํ–‰
91
  # 1. session_state ์ดˆ๊ธฐํ™” (์•ฑ์ด ์ฒ˜์Œ ์‹คํ–‰๋  ๋•Œ๋งŒ ์ž‘๋™)
@@ -101,7 +66,6 @@ if st.session_state.selection == "":
101
  none_temp()
102
  elif st.session_state.selection == "2024-09-26":
103
  normal(df, "ECU_DPFSoot")
104
- else: # "2024-08-24"
105
- audio_base64 = tts_engine(warning+" "+text_input)
106
  anormal(df, "ECU_DPFSoot", warning, text_input, audio_base64)
107
 
 
33
  # Base64 ์ธ์ฝ”๋”ฉ
34
  audio_bytes = mp3_fp.read()
35
  audio_base64 = base64.b64encode(audio_bytes).decode()
36
+ return mp3_fp, audio_base64
 
37
 
38
  def none_temp():
39
  st.info("๋จผ์ € ๋ฐ์ดํ„ฐ๋ฅผ ์„ ํƒํ•ด ์ฃผ์„ธ์š”")
 
43
  st.success("โœ… ์ฐจ๋Ÿ‰ ์ƒํƒœ: ์ •์ƒ")
44
  st.markdown("**์กฐ์น˜ ์‚ฌํ•ญ:** ์ถ”๊ฐ€ ์กฐ์น˜๋Š” ํ•„์š”ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.")
45
 
46
+ def anormal(df, col_name, warning, text_input):
47
  # custom style
48
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  chart_generate(df, col_name)
50
  st.warning(warning)
51
  st.markdown(text_input)
52
+ mp3_fp, audio_base64 = tts_engine(warning+" "+text_input)
53
+ st.audio(mp3_fp, format="audio/mp3")
54
 
55
  # ์„œ๋น„์Šค ์‹คํ–‰
56
  # 1. session_state ์ดˆ๊ธฐํ™” (์•ฑ์ด ์ฒ˜์Œ ์‹คํ–‰๋  ๋•Œ๋งŒ ์ž‘๋™)
 
66
  none_temp()
67
  elif st.session_state.selection == "2024-09-26":
68
  normal(df, "ECU_DPFSoot")
69
+ else:
 
70
  anormal(df, "ECU_DPFSoot", warning, text_input, audio_base64)
71