kkosmi commited on
Commit
c729869
ยท
verified ยท
1 Parent(s): 3a55ab2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -15
app.py CHANGED
@@ -108,40 +108,95 @@ def process_model(target_word):
108
  return fig, similar_words_text, dissimilar_words_text
109
 
110
 
111
-
112
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ˆ˜์ •
113
- with gr.Blocks(css=".plot-box {width: 70%; height: 500px;}") as iface:
114
- gr.Markdown("# Word Embedding 3D ์‹œ๊ฐํ™”")
115
- gr.Markdown("<Inside Out 2> ๋‹จ์–ด ์˜๋ฏธ ์ง€๋„(์ž„๋ฒ ๋”ฉ ๋ฒกํ„ฐ) 3D ์‹œ๊ฐํ™” ๋„๊ตฌ")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
  with gr.Row():
118
  # ์‚ฌ์šฉ์ž ์ž…๋ ฅ ๋ฐ•์Šค๋ฅผ ๊ฐ•์กฐํ•˜๊ธฐ ์œ„ํ•ด ์Šคํƒ€์ผ์„ ๋ณ€๊ฒฝ
119
  with gr.Column():
120
- word_input = gr.Textbox(label="**๋‹จ์–ด ์ž…๋ ฅ**", elem_id="input-box", placeholder="ex. emotion, puberty, hockey, friend, anxiety, memory, ...", lines=1)
 
 
 
 
 
121
  submit_btn = gr.Button("์ œ์ถœ", elem_id="submit-btn")
122
- bulletin = gr.Textbox(label="์‚ฌ์šฉ๋ฒ• ์•ˆ๋‚ด", interactive=False, lines=4, value="1. ์†Œ์„ค์— ๋‚˜์˜จ ๋‹จ์–ด๋ฅผ ์ž…๋ ฅํ•˜๊ณ  [์ œ์ถœ] ๋ฒ„ํŠผ์ด๋‚˜ [Enter]๋ฅผ ๋ˆ„๋ฅด์„ธ์š” \n2. ์ž…๋ ฅ ๋‹จ์–ด๋Š” ๋นจ๊ฐ„์ƒ‰, ๊ฐ€๊นŒ์šด ๋‹จ์–ด๋“ค์€ ์ฃผํ™ฉ์ƒ‰, ๋จผ ๋‹จ์–ด๋“ค์€ ๋ณด๋ผ์ƒ‰์œผ๋กœ ๊ฐ•์กฐ๋ฉ๋‹ˆ๋‹ค. \n3. <Error>๊ฐ€ ๋‚˜ํƒ€๋‚˜๋Š” ๊ฒฝ์šฐ, ๋‹ค๋ฅธ ๋‹จ์–ด๋ฅผ ์ž…๋ ฅํ•ด๋ณด์„ธ์š”.\n4. ๋งˆ์šฐ์Šค ๋“œ๋ž˜๊ทธ ๋ฐ ์Šคํฌ๋กค์„ ํ™œ์šฉํ•˜์—ฌ 3D ํ™”๋ฉด์„ ์‚ดํŽด๋ณด์„ธ์š”. \n5. ๋‹จ์–ด ์ž…๋ ฅ์ฐฝ์— ๋‹ค๋ฅธ ๋‹จ์–ด๋“ค๋„ ์ž…๋ ฅํ•ด๋ณด์„ธ์š”.")
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
  with gr.Row():
125
  # ์‹œ๊ฐํ™” ํ™”๋ฉด์˜ ํฌ๊ธฐ๋ฅผ CSS๋กœ ์ฆ๊ฐ€
126
  plot_output = gr.Plot(label="Word Embedding 3D ์‹œ๊ฐํ™”", elem_id="plot-box")
127
 
128
  with gr.Column(scale=0.3): # ์ปฌ๋Ÿผ์˜ ๋„ˆ๋น„๋ฅผ ์ค„์ด๊ธฐ ์œ„ํ•ด scale ๊ฐ’์„ ๋‚ฎ์ถค
129
- similar_words_output = gr.Textbox(label="๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๋‹จ์–ด 10๊ฐœ", interactive=False, lines=5)
130
- dissimilar_words_output = gr.Textbox(label="๊ฐ€์žฅ ๋จผ ๋‹จ์–ด 10๊ฐœ", interactive=False, lines=5)
131
- gr.Image(value="https://compote.slate.com/images/8324cd2e-21f5-4b20-84d5-f08ece97ac38.jpeg?crop=1560%2C1040%2Cx0%2Cy0&width=1280", label="URL ์ด๋ฏธ์ง€", interactive=False)
 
 
 
 
 
 
 
 
 
132
 
133
  submit_btn.click(
134
  fn=process_text,
135
- # word_input = word_input.lower(),
136
  inputs=[word_input],
137
- outputs=[plot_output, similar_words_output, dissimilar_words_output],
138
- # preprocess=lambda word: word.lower() if word else "" # None ์ฒดํฌ ํ›„ ์†Œ๋ฌธ์ž ๋ณ€ํ™˜
139
- )
140
 
141
- # "Enter" ํ‚ค ์ž…๋ ฅ ์‹œ ๋™์ž‘ ์„ค์ •
142
  word_input.submit(
143
  fn=process_text,
144
- # word_input = word_input.lower(),
145
  inputs=[word_input],
146
  outputs=[plot_output, similar_words_output, dissimilar_words_output],
147
  preprocess=lambda word: word.lower() if word else "" # None ์ฒดํฌ ํ›„ ์†Œ๋ฌธ์ž ๋ณ€ํ™˜
 
108
  return fig, similar_words_text, dissimilar_words_text
109
 
110
 
 
111
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ˆ˜์ •
112
+ with gr.Blocks(css="""
113
+ #input-box {
114
+ background-color: #ffeef3; /* ์—ฐํ•œ ํŒŒ์Šคํ…” ํ•‘ํฌ */
115
+ border: 2px solid #ffccd5; /* ์—ฐํ•œ ํ•‘ํฌ ํ…Œ๋‘๋ฆฌ */
116
+ color: #000; /* ํ…์ŠคํŠธ ์ƒ‰์ƒ */
117
+ border-radius: 8px; /* ๋‘ฅ๊ทผ ํ…Œ๋‘๋ฆฌ */
118
+ }
119
+ #submit-btn {
120
+ background-color: #ebfbea; /* ์—ฐํ•œ ํŒŒ์Šคํ…” ์—ฐ๋‘์ƒ‰ */
121
+ border: 2px solid #d6f5d6; /* ์—ฐํ•œ ์—ฐ๋‘์ƒ‰ ํ…Œ๋‘๋ฆฌ */
122
+ color: #000; /* ํ…์ŠคํŠธ ์ƒ‰์ƒ */
123
+ border-radius: 8px; /* ๋‘ฅ๊ทผ ํ…Œ๋‘๋ฆฌ */
124
+ }
125
+ #bulletin {
126
+ background-color: #eaf9ff; /* ์—ฐํ•œ ํŒŒ์Šคํ…” ํ•˜๋Š˜์ƒ‰ */
127
+ border: 2px solid #d3f0f7; /* ์—ฐํ•œ ํ•˜๋Š˜์ƒ‰ ํ…Œ๋‘๋ฆฌ */
128
+ color: #000; /* ํ…์ŠคํŠธ ์ƒ‰์ƒ */
129
+ border-radius: 8px; /* ๋‘ฅ๊ทผ ํ…Œ๋‘๋ฆฌ */
130
+ }
131
+ #similar-words {
132
+ background-color: #fff0e6; /* ์—ฐํ•œ ํŒŒ์Šคํ…” ์ฃผํ™ฉ์ƒ‰ */
133
+ border: 2px solid #ffe3cc; /* ์—ฐํ•œ ์ฃผํ™ฉ ํ…Œ๋‘๋ฆฌ */
134
+ color: #000; /* ํ…์ŠคํŠธ ์ƒ‰์ƒ */
135
+ border-radius: 8px; /* ๋‘ฅ๊ทผ ํ…Œ๋‘๋ฆฌ */
136
+ }
137
+ #dissimilar-words {
138
+ background-color: #f2e6ff; /* ์—ฐํ•œ ํŒŒ์Šคํ…” ๋ณด๋ผ์ƒ‰ */
139
+ border: 2px solid #e0ccff; /* ์—ฐํ•œ ๋ณด๋ผ ํ…Œ๋‘๋ฆฌ */
140
+ color: #000; /* ํ…์ŠคํŠธ ์ƒ‰์ƒ */
141
+ border-radius: 8px; /* ๋‘ฅ๊ทผ ํ…Œ๋‘๋ฆฌ */
142
+ }
143
+ label {
144
+ font-weight: bold; /* ์ œ๋ชฉ ๋ณผ๋“œ์ฒด */
145
+ }
146
+ """) as iface:
147
+ gr.Markdown("# <Inside Out 2> ๋‹จ์–ด ์˜๋ฏธ ์ง€๋„ 3D ์‹œ๊ฐํ™”")
148
+ # gr.Markdown("<Inside Out 2> ๋‹จ์–ด ์˜๋ฏธ ์ง€๋„(์ž„๋ฒ ๋”ฉ ๋ฒกํ„ฐ) 3D ์‹œ๊ฐํ™” ๋„๊ตฌ")
149
 
150
  with gr.Row():
151
  # ์‚ฌ์šฉ์ž ์ž…๋ ฅ ๋ฐ•์Šค๋ฅผ ๊ฐ•์กฐํ•˜๊ธฐ ์œ„ํ•ด ์Šคํƒ€์ผ์„ ๋ณ€๊ฒฝ
152
  with gr.Column():
153
+ word_input = gr.Textbox(
154
+ label="**๋‹จ์–ด ์ž…๋ ฅ**",
155
+ elem_id="input-box",
156
+ placeholder="ex. emotion, puberty, hockey, friend, anxiety, memory, ...",
157
+ lines=1
158
+ )
159
  submit_btn = gr.Button("์ œ์ถœ", elem_id="submit-btn")
160
+ bulletin = gr.Textbox(
161
+ label="์‚ฌ์šฉ๋ฒ• ์•ˆ๋‚ด",
162
+ interactive=False,
163
+ lines=4,
164
+ value=(
165
+ "1. ์†Œ์„ค์— ๋‚˜์˜จ ๋‹จ์–ด๋ฅผ ์ž…๋ ฅํ•˜๊ณ  [์ œ์ถœ]์ด๋‚˜ [Enter]๋ฅผ ๋ˆ„๋ฅด์„ธ์š”\n"
166
+ "2. ์ž…๋ ฅ ๋‹จ์–ด๋Š” ๋นจ๊ฐ„์ƒ‰, ๊ฐ€๊นŒ์šด ๋‹จ์–ด๋“ค์€ ์ฃผํ™ฉ์ƒ‰, ๋จผ ๋‹จ์–ด๋“ค์€ ๋ณด๋ผ์ƒ‰์œผ๋กœ ๊ฐ•์กฐ๋ฉ๋‹ˆ๋‹ค.\n"
167
+ "3. <Error>๊ฐ€ ๋‚˜ํƒ€๋‚˜๋Š” ๊ฒฝ์šฐ, ๋‹ค๋ฅธ ๋‹จ์–ด๋ฅผ ์ž…๋ ฅํ•ด๋ณด์„ธ์š”.\n"
168
+ "4. ๋งˆ์šฐ์Šค ๋“œ๋ž˜๊ทธ ๋ฐ ์Šคํฌ๋กค์„ ํ™œ์šฉํ•˜์—ฌ 3D ํ™”๋ฉด์„ ์‚ดํŽด๋ณด์„ธ์š”.\n"
169
+ "5. ๋‹จ์–ด ์ž…๋ ฅ์ฐฝ์— ๋‹ค๋ฅธ ๋‹จ์–ด๋“ค๋„ ์ž…๋ ฅํ•ด๋ณด์„ธ์š”."
170
+ ),
171
+ elem_id="bulletin"
172
+ )
173
 
174
  with gr.Row():
175
  # ์‹œ๊ฐํ™” ํ™”๋ฉด์˜ ํฌ๊ธฐ๋ฅผ CSS๋กœ ์ฆ๊ฐ€
176
  plot_output = gr.Plot(label="Word Embedding 3D ์‹œ๊ฐํ™”", elem_id="plot-box")
177
 
178
  with gr.Column(scale=0.3): # ์ปฌ๋Ÿผ์˜ ๋„ˆ๋น„๋ฅผ ์ค„์ด๊ธฐ ์œ„ํ•ด scale ๊ฐ’์„ ๋‚ฎ์ถค
179
+ similar_words_output = gr.Textbox(
180
+ label="๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๋‹จ์–ด 10๊ฐœ",
181
+ interactive=False,
182
+ lines=5,
183
+ elem_id="similar-words"
184
+ )
185
+ dissimilar_words_output = gr.Textbox(
186
+ label="๊ฐ€์žฅ ๋จผ ๋‹จ์–ด 10๊ฐœ",
187
+ interactive=False,
188
+ lines=5,
189
+ elem_id="dissimilar-words"
190
+ )
191
 
192
  submit_btn.click(
193
  fn=process_text,
 
194
  inputs=[word_input],
195
+ outputs=[plot_output, similar_words_output, dissimilar_words_output]
196
+ )
 
197
 
 
198
  word_input.submit(
199
  fn=process_text,
 
200
  inputs=[word_input],
201
  outputs=[plot_output, similar_words_output, dissimilar_words_output],
202
  preprocess=lambda word: word.lower() if word else "" # None ์ฒดํฌ ํ›„ ์†Œ๋ฌธ์ž ๋ณ€ํ™˜