ginipick commited on
Commit
dea516f
β€’
1 Parent(s): c8b6371

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -35
app.py CHANGED
@@ -167,38 +167,45 @@ footer {
167
  #chatbot-container .message, #chatbot-data-upload .message {
168
  font-size: 14px;
169
  }
 
 
 
 
 
170
  """
171
 
172
  # Gradio Blocks μΈν„°νŽ˜μ΄μŠ€ μ„€μ •
173
- with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
174
  gr.Markdown("# LLM μ„œλΉ„μŠ€ μΈν„°νŽ˜μ΄μŠ€")
175
 
176
  # 첫 번째 νƒ­: 챗봇
177
  with gr.Tab("챗봇"):
178
  gr.Markdown("### LLMκ³Ό λŒ€ν™”ν•˜κΈ°")
179
  chatbot = gr.Chatbot(label="챗봇", type="messages", elem_id="chatbot-container")
180
- msg = gr.Textbox(label="λ©”μ‹œμ§€ μž…λ ₯", placeholder="여기에 λ©”μ‹œμ§€λ₯Ό μž…λ ₯ν•˜μ„Έμš”...")
181
  send = gr.Button("전솑")
182
 
183
  with gr.Accordion("μ‹œμŠ€ν…œ ν”„λ‘¬ν”„νŠΈ 및 μ˜΅μ…˜ μ„€μ •", open=False):
184
  system_message = gr.Textbox(label="System Message", value="λ„ˆλŠ” AI μ‘°μ–Έμž 역할이닀.")
185
- max_tokens = gr.Slider(minimum=1, maximum=8000, value=4000, label="Max Tokens")
186
  temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature")
187
  top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
188
 
189
  # 챗봇 λ©”μ‹œμ§€ 처리 ν•¨μˆ˜
190
  def handle_message(message, history, system_message, max_tokens, temperature, top_p):
191
  history = history or []
192
- history.append({"role": "user", "content": message})
193
  try:
194
  # 응닡 생성
195
  response_gen = respond(message, history, system_message, max_tokens, temperature, top_p)
196
  response = ""
197
  for partial in response_gen:
198
  response = partial # μ΅œμ’… 응닡
 
 
199
  history.append({"role": "assistant", "content": response})
200
  except Exception as e:
201
  response = f"μΆ”λ‘  쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"
 
202
  history.append({"role": "assistant", "content": response})
203
  return history, ""
204
 
@@ -255,7 +262,35 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
255
  gr.Markdown("### κΈ°μ‘΄ Parquet 파일")
256
  gr.Markdown(f"**test.parquet 파일 λ‚΄μš©:**\n```markdown\n{test_parquet_content}\n```")
257
 
258
- # μ„Έ 번째 νƒ­: 챗봇 데이터 μ—…λ‘œλ“œ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  with gr.Tab("챗봇 데이터 μ—…λ‘œλ“œ"):
260
  gr.Markdown("### Parquet 파일 μ—…λ‘œλ“œ 및 μ§ˆλ¬Έν•˜κΈ°")
261
  with gr.Row():
@@ -286,16 +321,18 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
286
 
287
  def handle_message_data_upload(message: str, history: List[Dict[str, str]], system_message: str, max_tokens: int, temperature: float, top_p: float, parquet_data: Dict):
288
  history = history or []
289
- history.append({"role": "user", "content": message})
290
  try:
291
  # Parquet 데이터λ₯Ό ν™œμš©ν•  수 μžˆλŠ” 둜직 μΆ”κ°€ κ°€λŠ₯
292
  response_gen = respond(message, history, system_message, max_tokens, temperature, top_p)
293
  response = ""
294
  for partial in response_gen:
295
  response = partial
 
 
296
  history.append({"role": "assistant", "content": response})
297
  except Exception as e:
298
  response = f"μΆ”λ‘  쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"
 
299
  history.append({"role": "assistant", "content": response})
300
  return history, ""
301
 
@@ -305,34 +342,6 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
305
  outputs=[chatbot_data_upload, msg_data_upload]
306
  )
307
 
308
- # λ„€ 번째 νƒ­: ν…μŠ€νŠΈ to csv to parquet λ³€ν™˜
309
- with gr.Tab("ν…μŠ€νŠΈ to csv to parquet λ³€ν™˜"):
310
- gr.Markdown("### ν…μŠ€νŠΈλ₯Ό μž…λ ₯ν•˜λ©΄ CSV둜 λ³€ν™˜ ν›„ Parquet으둜 μžλ™ μ „ν™˜λ©λ‹ˆλ‹€.")
311
- with gr.Row():
312
- with gr.Column():
313
- text_input = gr.Textbox(
314
- label="ν…μŠ€νŠΈ μž…λ ₯ (각 행은 `id,text,label,metadata` ν˜•μ‹μœΌλ‘œ μž…λ ₯)",
315
- lines=10,
316
- placeholder="예: 1,Sample Text,Label1,Metadata1\n2,Another Text,Label2,Metadata2"
317
- )
318
- convert_button = gr.Button("λ³€ν™˜ 및 λ‹€μš΄λ‘œλ“œ")
319
- convert_status = gr.Textbox(label="λ³€ν™˜ μƒνƒœ", interactive=False)
320
- parquet_preview_convert = gr.Markdown(label="Parquet 파일 미리보기")
321
- download_parquet_convert = gr.File(label="Parquet 파일 λ‹€μš΄λ‘œλ“œ", interactive=False)
322
-
323
- def handle_text_to_parquet(text: str):
324
- message, parquet_content, parquet_filename = text_to_parquet(text)
325
- if parquet_filename:
326
- return message, parquet_content, parquet_filename
327
- else:
328
- return message, "", None
329
-
330
- convert_button.click(
331
- handle_text_to_parquet,
332
- inputs=text_input,
333
- outputs=[convert_status, parquet_preview_convert, download_parquet_convert]
334
- )
335
-
336
  # 주의 사항
337
  gr.Markdown("## 주의 사항")
338
  gr.Markdown("""
@@ -341,7 +350,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
341
  - **LLM과의 λŒ€ν™”**: λ³€ν™˜λœ Parquet 파일 λ‚΄μš©μ„ 기반으둜 LLM이 응닡을 μƒμ„±ν•©λ‹ˆλ‹€.
342
  - **Parquet λ‹€μš΄λ‘œλ“œ**: λ³€ν™˜λœ Parquet νŒŒμΌμ„ λ‹€μš΄λ‘œλ“œν•˜λ €λ©΄ λ³€ν™˜λœ 파일 μ˜†μ˜ λ‹€μš΄λ‘œλ“œ 링크λ₯Ό ν΄λ¦­ν•˜μ„Έμš”.
343
  - **챗봇 데이터 μ—…λ‘œλ“œ**: 챗봇 데이터 μ—…λ‘œλ“œ νƒ­μ—μ„œ Parquet νŒŒμΌμ„ μ—…λ‘œλ“œν•˜λ©΄ ν•΄λ‹Ή 데이터λ₯Ό 기반으둜 질문과 닡변을 진행할 수 μžˆμŠ΅λ‹ˆλ‹€.
344
- - **ν…μŠ€νŠΈ to csv to parquet**: λ„€ 번째 νƒ­μ—μ„œ ν…μŠ€νŠΈλ₯Ό μž…λ ₯ν•˜λ©΄ μžλ™μœΌλ‘œ CSV둜 λ³€ν™˜λ˜κ³ , λ‹€μ‹œ Parquet 파일둜 μ „ν™˜λ˜μ–΄ λ‹€μš΄λ‘œλ“œν•  수 μžˆμŠ΅λ‹ˆλ‹€.
345
  """)
346
 
347
  gr.Markdown("### Gradio μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ‚¬μš©ν•˜μ—¬ LLM λͺ¨λΈκ³Ό μƒν˜Έμž‘μš©ν•˜μ„Έμš”!")
@@ -349,3 +358,5 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
349
  if __name__ == "__main__":
350
  demo.launch()
351
 
 
 
 
167
  #chatbot-container .message, #chatbot-data-upload .message {
168
  font-size: 14px;
169
  }
170
+ /* μž…λ ₯μ°½ 배경색 및 κΈ€μžμƒ‰ λ³€κ²½ */
171
+ textarea, input[type="text"] {
172
+ background-color: #ffffff; /* 흰색 λ°°κ²½ */
173
+ color: #000000; /* 검정색 κΈ€μž */
174
+ }
175
  """
176
 
177
  # Gradio Blocks μΈν„°νŽ˜μ΄μŠ€ μ„€μ •
178
+ with gr.Blocks(css=css) as demo:
179
  gr.Markdown("# LLM μ„œλΉ„μŠ€ μΈν„°νŽ˜μ΄μŠ€")
180
 
181
  # 첫 번째 νƒ­: 챗봇
182
  with gr.Tab("챗봇"):
183
  gr.Markdown("### LLMκ³Ό λŒ€ν™”ν•˜κΈ°")
184
  chatbot = gr.Chatbot(label="챗봇", type="messages", elem_id="chatbot-container")
185
+ msg = gr.Textbox(label="λ©”μ‹œμ§€ μž…λ ₯", placeholder="여기에 λ©”μ‹œμ§€λ₯Ό μž…λ ₯ν•˜μ„Έμš”...", elem_id="input-text")
186
  send = gr.Button("전솑")
187
 
188
  with gr.Accordion("μ‹œμŠ€ν…œ ν”„λ‘¬ν”„νŠΈ 및 μ˜΅μ…˜ μ„€μ •", open=False):
189
  system_message = gr.Textbox(label="System Message", value="λ„ˆλŠ” AI μ‘°μ–Έμž 역할이닀.")
190
+ max_tokens = gr.Slider(minimum=1, maximum=8000, value=1000, label="Max Tokens")
191
  temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature")
192
  top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
193
 
194
  # 챗봇 λ©”μ‹œμ§€ 처리 ν•¨μˆ˜
195
  def handle_message(message, history, system_message, max_tokens, temperature, top_p):
196
  history = history or []
 
197
  try:
198
  # 응닡 생성
199
  response_gen = respond(message, history, system_message, max_tokens, temperature, top_p)
200
  response = ""
201
  for partial in response_gen:
202
  response = partial # μ΅œμ’… 응닡
203
+ # μ‚¬μš©μžμ˜ λ©”μ‹œμ§€μ™€ μ–΄μ‹œμŠ€ν„΄νŠΈμ˜ 응닡을 νžˆμŠ€ν† λ¦¬μ— μΆ”κ°€
204
+ history.append({"role": "user", "content": message})
205
  history.append({"role": "assistant", "content": response})
206
  except Exception as e:
207
  response = f"μΆ”λ‘  쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"
208
+ history.append({"role": "user", "content": message})
209
  history.append({"role": "assistant", "content": response})
210
  return history, ""
211
 
 
262
  gr.Markdown("### κΈ°μ‘΄ Parquet 파일")
263
  gr.Markdown(f"**test.parquet 파일 λ‚΄μš©:**\n```markdown\n{test_parquet_content}\n```")
264
 
265
+ # μ„Έ 번째 νƒ­: ν…μŠ€νŠΈ to csv to parquet λ³€ν™˜
266
+ with gr.Tab("ν…μŠ€νŠΈ to csv to parquet λ³€ν™˜"):
267
+ gr.Markdown("### ν…μŠ€νŠΈλ₯Ό μž…λ ₯ν•˜λ©΄ CSV둜 λ³€ν™˜ ν›„ Parquet으둜 μžλ™ μ „ν™˜λ©λ‹ˆλ‹€.")
268
+ with gr.Row():
269
+ with gr.Column():
270
+ text_input = gr.Textbox(
271
+ label="ν…μŠ€νŠΈ μž…λ ₯ (각 행은 `id,text,label,metadata` ν˜•μ‹μœΌλ‘œ μž…λ ₯)",
272
+ lines=10,
273
+ placeholder="예: 1,Sample Text,Label1,Metadata1\n2,Another Text,Label2,Metadata2"
274
+ )
275
+ convert_button = gr.Button("λ³€ν™˜ 및 λ‹€μš΄λ‘œλ“œ")
276
+ convert_status = gr.Textbox(label="λ³€ν™˜ μƒνƒœ", interactive=False)
277
+ parquet_preview_convert = gr.Markdown(label="Parquet 파일 미리보기")
278
+ download_parquet_convert = gr.File(label="Parquet 파일 λ‹€μš΄λ‘œλ“œ", interactive=False)
279
+
280
+ def handle_text_to_parquet(text: str):
281
+ message, parquet_content, parquet_filename = text_to_parquet(text)
282
+ if parquet_filename:
283
+ return message, parquet_content, parquet_filename
284
+ else:
285
+ return message, "", None
286
+
287
+ convert_button.click(
288
+ handle_text_to_parquet,
289
+ inputs=text_input,
290
+ outputs=[convert_status, parquet_preview_convert, download_parquet_convert]
291
+ )
292
+
293
+ # λ„€ 번째 νƒ­: 챗봇 데이터 μ—…λ‘œλ“œ
294
  with gr.Tab("챗봇 데이터 μ—…λ‘œλ“œ"):
295
  gr.Markdown("### Parquet 파일 μ—…λ‘œλ“œ 및 μ§ˆλ¬Έν•˜κΈ°")
296
  with gr.Row():
 
321
 
322
  def handle_message_data_upload(message: str, history: List[Dict[str, str]], system_message: str, max_tokens: int, temperature: float, top_p: float, parquet_data: Dict):
323
  history = history or []
 
324
  try:
325
  # Parquet 데이터λ₯Ό ν™œμš©ν•  수 μžˆλŠ” 둜직 μΆ”κ°€ κ°€λŠ₯
326
  response_gen = respond(message, history, system_message, max_tokens, temperature, top_p)
327
  response = ""
328
  for partial in response_gen:
329
  response = partial
330
+ # μ‚¬μš©μžμ˜ λ©”μ‹œμ§€μ™€ μ–΄μ‹œμŠ€ν„΄νŠΈμ˜ 응닡을 νžˆμŠ€ν† λ¦¬μ— μΆ”κ°€
331
+ history.append({"role": "user", "content": message})
332
  history.append({"role": "assistant", "content": response})
333
  except Exception as e:
334
  response = f"μΆ”λ‘  쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"
335
+ history.append({"role": "user", "content": message})
336
  history.append({"role": "assistant", "content": response})
337
  return history, ""
338
 
 
342
  outputs=[chatbot_data_upload, msg_data_upload]
343
  )
344
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
345
  # 주의 사항
346
  gr.Markdown("## 주의 사항")
347
  gr.Markdown("""
 
350
  - **LLM과의 λŒ€ν™”**: λ³€ν™˜λœ Parquet 파일 λ‚΄μš©μ„ 기반으둜 LLM이 응닡을 μƒμ„±ν•©λ‹ˆλ‹€.
351
  - **Parquet λ‹€μš΄λ‘œλ“œ**: λ³€ν™˜λœ Parquet νŒŒμΌμ„ λ‹€μš΄λ‘œλ“œν•˜λ €λ©΄ λ³€ν™˜λœ 파일 μ˜†μ˜ λ‹€μš΄λ‘œλ“œ 링크λ₯Ό ν΄λ¦­ν•˜μ„Έμš”.
352
  - **챗봇 데이터 μ—…λ‘œλ“œ**: 챗봇 데이터 μ—…λ‘œλ“œ νƒ­μ—μ„œ Parquet νŒŒμΌμ„ μ—…λ‘œλ“œν•˜λ©΄ ν•΄λ‹Ή 데이터λ₯Ό 기반으둜 질문과 닡변을 진행할 수 μžˆμŠ΅λ‹ˆλ‹€.
353
+ - **ν…μŠ€νŠΈ to csv to parquet**: μ„Έ 번째 νƒ­μ—μ„œ ν…μŠ€νŠΈλ₯Ό μž…λ ₯ν•˜λ©΄ μžλ™μœΌλ‘œ CSV둜 λ³€ν™˜λ˜κ³ , λ‹€μ‹œ Parquet 파일둜 μ „ν™˜λ˜μ–΄ λ‹€μš΄λ‘œλ“œν•  수 μžˆμŠ΅λ‹ˆλ‹€.
354
  """)
355
 
356
  gr.Markdown("### Gradio μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ‚¬μš©ν•˜μ—¬ LLM λͺ¨λΈκ³Ό μƒν˜Έμž‘μš©ν•˜μ„Έμš”!")
 
358
  if __name__ == "__main__":
359
  demo.launch()
360
 
361
+
362
+