File size: 4,524 Bytes
6120cb0 e1d4a58 6120cb0 e1d4a58 e88fc39 e1d4a58 92f8d84 e1d4a58 92f8d84 e1d4a58 92f8d84 e1d4a58 | 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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | import streamlit as st
import base64
import os
# 1. ์ด๋ฏธ์ง ๊ฒฝ๋ก ์ค์ (app.py์ ๊ฐ์ ์์น์ img ํด๋๊ฐ ์์ด์ผ ํจ)
IMG_PATH = "src/img/mic.png"
# 2. ์ด๋ฏธ์ง๋ฅผ Base64 ๋ฌธ์์ด๋ก ๋ณํํ๋ ํจ์
def get_image_base64(path):
if os.path.exists(path):
with open(path, "rb") as f:
data = f.read()
return base64.b64encode(data).decode()
return None
# ์ด๋ฏธ์ง ๋ก๋ ์๋
mic_icon_base64 = get_image_base64(IMG_PATH)
# ์ด๋ฏธ์ง๊ฐ ์์ ๊ฒฝ์ฐ๋ฅผ ๋๋นํ ๋์ฒด ํ
์คํธ ํน์ ๋น ๊ฐ
if mic_icon_base64:
img_src = f"data:image/png;base64,{mic_icon_base64}"
else:
# ์ด๋ฏธ์ง๊ฐ ์์ผ๋ฉด ๊นจ์ง ์ด๋ฏธ์ง ์์ด์ฝ ๋์ ํฌ๋ช
ํ๊ฒ ์ฒ๋ฆฌํ๊ฑฐ๋ ๊ฒฝ๊ณ ํ์
img_src = ""
# ============
# ํ์ด์ง ์ค์
st.set_page_config(
page_title="๊ฑด๊ฐ ๊ด๋ฆฌ ์ฑ",
page_icon="๐ช",
layout="centered",
initial_sidebar_state="collapsed"
)
# CSS ์คํ์ผ๋ง (f-string์ผ๋ก ๋ณ๊ฒฝํ์ฌ ๋ณ์ ์ฃผ์
๊ฐ๋ฅํ๊ฒ ํจ)
st.markdown(f"""
<style>
/* ์ ์ฒด ๋ฐฐ๊ฒฝ */
.stApp {{
background-color: #ffffff;
}}
/* ํค๋ ์์ญ */
.header {{
padding: 20px 0;
text-align: left;
}}
.menu-icon {{
font-size: 32px;
font-weight: 300;
color: #333;
cursor: pointer;
}}
/* ์นด๋ ์ปจํ
์ด๋ - ๊ฐ๋ก ์คํฌ๋กค */
.card-container {{
position: fixed;
bottom: 80px;
left: 0;
right: 0;
display: flex;
flex-direction: row;
gap: 15px;
overflow-x: auto;
overflow-y: hidden;
padding: 0 20px;
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* IE/Edge */
}}
/* ์คํฌ๋กค๋ฐ ์จ๊ธฐ๊ธฐ (Webkit) */
.card-container::-webkit-scrollbar {{
display: none;
}}
/* ๊ฐ๋ณ ์นด๋ */
.card {{
background: #f5f5f5;
padding: 15px 18px;
border-radius: 20px;
cursor: pointer;
transition: all 0.2s;
font-size: 13px;
color: #333;
font-weight: 400;
flex-shrink: 0;
max-width: 140px;
white-space: normal;
}}
.card:hover {{
transform: translateY(-2px);
}}
/* ํ๋จ ์
๋ ฅ ์์ญ */
.input-container {{
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: white;
padding: 15px 20px 15px 20px;
}}
.input-box {{
display: flex;
align-items: center;
background: #f0f0f0;
border-radius: 40px;
padding: 1px 10px;
}}
.plus-btn {{
font-size: 26px;
color: #666;
cursor: pointer;
user-select: none;
}}
.input-text {{
flex: 1;
font-size: 15px;
color: #999;
}}
.voice-btn {{
width: 20px; /* ๋ฒํผ ์ ์ฒด ํฌ๊ธฐ */
height: 20px;
cursor: pointer;
box-sizing: border-box; /* ํจ๋ฉ์ ํฌํจํด์ 40px๋ก ๊ณ ์ */
object-fit: contain; /* ์ด๋ฏธ์ง๊ฐ ์ฐ๊ทธ๋ฌ์ง์ง ์๊ฒ */
}}
/* Streamlit ๊ธฐ๋ณธ ์์ ์จ๊ธฐ๊ธฐ */
#MainMenu {{visibility: hidden;}}
footer {{visibility: hidden;}}
header {{visibility: hidden;}}
/* ์ฌ๋ฐฑ ์กฐ์ */
.block-container {{
padding-top: 2rem;
padding-bottom: 8rem;
}}
</style>
""", unsafe_allow_html=True)
# ํค๋ (ํ๋ฒ๊ฑฐ ๋ฉ๋ด)
st.markdown("""
<div class="header">
<div class="menu-icon">โฐ</div>
</div>
""", unsafe_allow_html=True)
# ์ค๊ฐ ์นด๋ ์์ญ (๊ฐ๋ก ์คํฌ๋กค)
st.markdown("""
<div class="card-container">
<div class="card">์ด๋ฒ์ฃผ์ ๊ฑด๊ฐ ๋ถ์ ๋ฆฌํฌํธ๋ฅผ ์จ์ค</div>
<div class="card">๋์๊ฒ ๋ง๋ ์๋จ ์ถ์ฒํด์ค</div>
<div class="card">์๋กญ๊ฒ ํด๋ณผ๋งํ ์ด๋ ์ถ์ฒํด์ค</div>
</div>
""", unsafe_allow_html=True)
# ํ๋จ ์
๋ ฅ ์์ญ (์ด๋ฏธ์ง ๊ฒฝ๋ก๊ฐ ์ฃผ์
๋จ)
st.markdown(f"""
<div class="input-container">
<div class="input-box">
<div class="plus-btn">๏ผ</div>
<div class="input-text">๋ฌด์์ด๋ ๋ถํํ์ธ์</div>
<img src="{img_src}" class="voice-btn" alt="๋ง์ดํฌ"></div>
</div>
""", unsafe_allow_html=True)
# ๋๋ฒ๊น
์ฉ: ์ด๋ฏธ์ง๊ฐ ๋ก๋๋์ง ์์์ ๋๋ง ์๋ฌ ๋ฉ์์ง ํ์
if not mic_icon_base64:
st.error(f"์ด๋ฏธ์ง๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค. ๊ฒฝ๋ก๋ฅผ ํ์ธํด์ฃผ์ธ์: {os.path.abspath(IMG_PATH)}") |