Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -83,7 +83,7 @@ def respond_chatgpt_qna(
|
|
| 83 |
|
| 84 |
try:
|
| 85 |
response = openai.ChatCompletion.create(
|
| 86 |
-
model="gpt-4o-mini",
|
| 87 |
messages=messages,
|
| 88 |
max_tokens=max_tokens,
|
| 89 |
temperature=temperature,
|
|
@@ -208,108 +208,118 @@ def respond_o1mini_qna(
|
|
| 208 |
return f"오류가 발생했습니다: {str(e)}"
|
| 209 |
|
| 210 |
#############################
|
| 211 |
-
# [기본코드] UI 부분 - 수정/삭제 불가 (
|
| 212 |
#############################
|
| 213 |
|
| 214 |
with gr.Blocks() as demo:
|
| 215 |
gr.Markdown("# LLM 플레이그라운드")
|
| 216 |
|
| 217 |
#################
|
| 218 |
-
#
|
| 219 |
#################
|
| 220 |
-
with gr.Tab("
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
cohere_answer_output = gr.Textbox(label="결과", lines=5, interactive=False)
|
| 228 |
-
|
| 229 |
-
with gr.Accordion("고급 설정 (Cohere)", open=False):
|
| 230 |
-
cohere_system_message = gr.Textbox(
|
| 231 |
-
value="""반드시 한글로 답변할 것.
|
| 232 |
-
너는 최고의 비서이다.
|
| 233 |
-
내가 요구하는것들을 최대한 자세하고 정확하게 답변하라.
|
| 234 |
-
""",
|
| 235 |
-
label="System Message",
|
| 236 |
-
lines=3
|
| 237 |
-
)
|
| 238 |
-
cohere_max_tokens = gr.Slider(minimum=100, maximum=10000, value=4000, step=100, label="Max Tokens")
|
| 239 |
-
cohere_temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature")
|
| 240 |
-
cohere_top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-P")
|
| 241 |
-
|
| 242 |
-
cohere_submit_button = gr.Button("전송")
|
| 243 |
-
|
| 244 |
-
def merge_and_call_cohere(i1, i2, i3, i4, i5, sys_msg, mt, temp, top_p_):
|
| 245 |
-
question = " ".join([i1, i2, i3, i4, i5])
|
| 246 |
-
return respond_cohere_qna(
|
| 247 |
-
question=question,
|
| 248 |
-
system_message=sys_msg,
|
| 249 |
-
max_tokens=mt,
|
| 250 |
-
temperature=temp,
|
| 251 |
-
top_p=top_p_
|
| 252 |
-
)
|
| 253 |
-
|
| 254 |
-
cohere_submit_button.click(
|
| 255 |
-
fn=merge_and_call_cohere,
|
| 256 |
-
inputs=[
|
| 257 |
-
cohere_input1, cohere_input2, cohere_input3, cohere_input4, cohere_input5,
|
| 258 |
-
cohere_system_message,
|
| 259 |
-
cohere_max_tokens,
|
| 260 |
-
cohere_temperature,
|
| 261 |
-
cohere_top_p
|
| 262 |
-
],
|
| 263 |
-
outputs=cohere_answer_output
|
| 264 |
)
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
with gr.Accordion("고급 설정 (ChatGPT)", open=False):
|
| 279 |
-
chatgpt_system_message = gr.Textbox(
|
| 280 |
-
value="""반드시 한글로 답변할 것.
|
| 281 |
너는 ChatGPT, OpenAI에서 개발한 언어 모델이다.
|
| 282 |
내가 요구하는 것을 최대한 자세하고 정확하게 답변하라.
|
| 283 |
""",
|
| 284 |
-
|
| 285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
)
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
)
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
|
|
|
| 313 |
)
|
| 314 |
|
| 315 |
#################
|
|
@@ -456,111 +466,52 @@ with gr.Blocks() as demo:
|
|
| 456 |
)
|
| 457 |
|
| 458 |
#################
|
| 459 |
-
#
|
| 460 |
#################
|
| 461 |
-
with gr.Tab("
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
with gr.
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
chatgpt_input5_o = gr.Textbox(label="입력5", lines=1)
|
| 476 |
-
chatgpt_answer_output_o = gr.Textbox(label="결과", lines=5, interactive=False)
|
| 477 |
-
with gr.Accordion("고급 설정 (gpt-4o-mini)", open=False):
|
| 478 |
-
chatgpt_system_message_o = gr.Textbox(
|
| 479 |
-
value="""반드시 한글로 답변할 것.
|
| 480 |
-
너는 ChatGPT, OpenAI에서 개발한 언어 모델이다.
|
| 481 |
-
내가 요구하는 것을 최대한 자세하고 정확하게 답변하라.
|
| 482 |
""",
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
)
|
| 486 |
-
chatgpt_max_tokens_o = gr.Slider(minimum=100, maximum=4000, value=2000, step=100, label="Max Tokens")
|
| 487 |
-
chatgpt_temperature_o = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.05, label="Temperature")
|
| 488 |
-
chatgpt_top_p_o = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-P")
|
| 489 |
-
chatgpt_submit_button_o = gr.Button("전송")
|
| 490 |
-
|
| 491 |
-
def merge_and_call_chatgpt_o(i1, i2, i3, i4, i5, sys_msg, mt, temp, top_p_):
|
| 492 |
-
question = " ".join([i1, i2, i3, i4, i5])
|
| 493 |
-
return respond_chatgpt_qna(
|
| 494 |
-
question=question,
|
| 495 |
-
system_message=sys_msg,
|
| 496 |
-
max_tokens=mt,
|
| 497 |
-
temperature=temp,
|
| 498 |
-
top_p=top_p_
|
| 499 |
-
)
|
| 500 |
-
chatgpt_submit_button_o.click(
|
| 501 |
-
fn=merge_and_call_chatgpt_o,
|
| 502 |
-
inputs=[
|
| 503 |
-
chatgpt_input1_o, chatgpt_input2_o, chatgpt_input3_o, chatgpt_input4_o, chatgpt_input5_o,
|
| 504 |
-
chatgpt_system_message_o,
|
| 505 |
-
chatgpt_max_tokens_o,
|
| 506 |
-
chatgpt_temperature_o,
|
| 507 |
-
chatgpt_top_p_o
|
| 508 |
-
],
|
| 509 |
-
outputs=chatgpt_answer_output_o
|
| 510 |
)
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
""",
|
| 526 |
-
label="System Message",
|
| 527 |
-
lines=3
|
| 528 |
-
)
|
| 529 |
-
o1mini_max_tokens_o = gr.Slider(minimum=100, maximum=4000, value=2000, step=100, label="Max Tokens")
|
| 530 |
-
o1mini_temperature_o = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.05, label="Temperature")
|
| 531 |
-
# o1-mini는 top_p 지원이 없으므로 해당 옵션은 UI에서 제외함
|
| 532 |
-
o1mini_submit_button_o = gr.Button("전송")
|
| 533 |
-
|
| 534 |
-
def merge_and_call_o1mini_o(i1, i2, i3, i4, i5, sys_msg, mt, temp):
|
| 535 |
-
question = " ".join([i1, i2, i3, i4, i5])
|
| 536 |
-
return respond_o1mini_qna(
|
| 537 |
-
question=question,
|
| 538 |
-
system_message=sys_msg,
|
| 539 |
-
max_tokens=mt,
|
| 540 |
-
temperature=temp
|
| 541 |
-
)
|
| 542 |
-
o1mini_submit_button_o.click(
|
| 543 |
-
fn=merge_and_call_o1mini_o,
|
| 544 |
-
inputs=[
|
| 545 |
-
o1mini_input1_o, o1mini_input2_o, o1mini_input3_o, o1mini_input4_o, o1mini_input5_o,
|
| 546 |
-
o1mini_system_message_o,
|
| 547 |
-
o1mini_max_tokens_o,
|
| 548 |
-
o1mini_temperature_o
|
| 549 |
-
],
|
| 550 |
-
outputs=o1mini_answer_output_o
|
| 551 |
)
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
outputs=[chatgpt_ui, o1mini_ui]
|
| 564 |
)
|
| 565 |
|
| 566 |
#############################
|
|
|
|
| 83 |
|
| 84 |
try:
|
| 85 |
response = openai.ChatCompletion.create(
|
| 86 |
+
model="gpt-4o-mini",
|
| 87 |
messages=messages,
|
| 88 |
max_tokens=max_tokens,
|
| 89 |
temperature=temperature,
|
|
|
|
| 208 |
return f"오류가 발생했습니다: {str(e)}"
|
| 209 |
|
| 210 |
#############################
|
| 211 |
+
# [기본코드] UI 부분 - 수정/삭제 불가 (탭 순서 변경 및 gpt-4o-mini 탭 제거)
|
| 212 |
#############################
|
| 213 |
|
| 214 |
with gr.Blocks() as demo:
|
| 215 |
gr.Markdown("# LLM 플레이그라운드")
|
| 216 |
|
| 217 |
#################
|
| 218 |
+
# OpenAI 탭 (gpt-4o-mini / o1-mini 통합)
|
| 219 |
#################
|
| 220 |
+
with gr.Tab("OpenAI"):
|
| 221 |
+
# 모델 선택 라디오 버튼 (gpt-4o-mini와 o1-mini)
|
| 222 |
+
openai_model_radio = gr.Radio(
|
| 223 |
+
choices=["gpt-4o-mini", "o1-mini"],
|
| 224 |
+
label="모델 선택",
|
| 225 |
+
value="gpt-4o-mini"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
)
|
| 227 |
+
|
| 228 |
+
# gpt-4o-mini 전용 UI 그룹 (초기 visible)
|
| 229 |
+
with gr.Column(visible=True) as chatgpt_ui:
|
| 230 |
+
chatgpt_input1_o = gr.Textbox(label="입력1", lines=1)
|
| 231 |
+
chatgpt_input2_o = gr.Textbox(label="입력2", lines=1)
|
| 232 |
+
chatgpt_input3_o = gr.Textbox(label="입력3", lines=1)
|
| 233 |
+
chatgpt_input4_o = gr.Textbox(label="입력4", lines=1)
|
| 234 |
+
chatgpt_input5_o = gr.Textbox(label="입력5", lines=1)
|
| 235 |
+
chatgpt_answer_output_o = gr.Textbox(label="결과", lines=5, interactive=False)
|
| 236 |
+
with gr.Accordion("고급 설정 (gpt-4o-mini)", open=False):
|
| 237 |
+
chatgpt_system_message_o = gr.Textbox(
|
| 238 |
+
value="""반드시 한글로 답변할 것.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
너는 ChatGPT, OpenAI에서 개발한 언어 모델이다.
|
| 240 |
내가 요구하는 것을 최대한 자세하고 정확하게 답변하라.
|
| 241 |
""",
|
| 242 |
+
label="System Message",
|
| 243 |
+
lines=3
|
| 244 |
+
)
|
| 245 |
+
chatgpt_max_tokens_o = gr.Slider(minimum=100, maximum=4000, value=2000, step=100, label="Max Tokens")
|
| 246 |
+
chatgpt_temperature_o = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.05, label="Temperature")
|
| 247 |
+
chatgpt_top_p_o = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-P")
|
| 248 |
+
chatgpt_submit_button_o = gr.Button("전송")
|
| 249 |
+
|
| 250 |
+
def merge_and_call_chatgpt_o(i1, i2, i3, i4, i5, sys_msg, mt, temp, top_p_):
|
| 251 |
+
question = " ".join([i1, i2, i3, i4, i5])
|
| 252 |
+
return respond_chatgpt_qna(
|
| 253 |
+
question=question,
|
| 254 |
+
system_message=sys_msg,
|
| 255 |
+
max_tokens=mt,
|
| 256 |
+
temperature=temp,
|
| 257 |
+
top_p=top_p_
|
| 258 |
+
)
|
| 259 |
+
chatgpt_submit_button_o.click(
|
| 260 |
+
fn=merge_and_call_chatgpt_o,
|
| 261 |
+
inputs=[
|
| 262 |
+
chatgpt_input1_o, chatgpt_input2_o, chatgpt_input3_o, chatgpt_input4_o, chatgpt_input5_o,
|
| 263 |
+
chatgpt_system_message_o,
|
| 264 |
+
chatgpt_max_tokens_o,
|
| 265 |
+
chatgpt_temperature_o,
|
| 266 |
+
chatgpt_top_p_o
|
| 267 |
+
],
|
| 268 |
+
outputs=chatgpt_answer_output_o
|
| 269 |
)
|
| 270 |
+
|
| 271 |
+
# o1-mini 전용 UI 그룹 (초기 hidden)
|
| 272 |
+
with gr.Column(visible=False) as o1mini_ui:
|
| 273 |
+
o1mini_input1_o = gr.Textbox(label="입력1", lines=1)
|
| 274 |
+
o1mini_input2_o = gr.Textbox(label="입력2", lines=1)
|
| 275 |
+
o1mini_input3_o = gr.Textbox(label="입력3", lines=1)
|
| 276 |
+
o1mini_input4_o = gr.Textbox(label="입력4", lines=1)
|
| 277 |
+
o1mini_input5_o = gr.Textbox(label="입력5", lines=1)
|
| 278 |
+
o1mini_answer_output_o = gr.Textbox(label="결과", lines=5, interactive=False)
|
| 279 |
+
with gr.Accordion("고급 설정 (o1-mini)", open=False):
|
| 280 |
+
o1mini_system_message_o = gr.Textbox(
|
| 281 |
+
value="""반드시 한글로 답변할 것.
|
| 282 |
+
너는 o1-mini, OpenAI에서 개발한 경량 언어 모델이다.
|
| 283 |
+
내가 요구하는 것을 최대한 자세하고 정확하게 답변하라.
|
| 284 |
+
""",
|
| 285 |
+
label="System Message",
|
| 286 |
+
lines=3
|
| 287 |
+
)
|
| 288 |
+
o1mini_max_tokens_o = gr.Slider(minimum=100, maximum=4000, value=2000, step=100, label="Max Tokens")
|
| 289 |
+
o1mini_temperature_o = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.05, label="Temperature")
|
| 290 |
+
# o1-mini는 top_p 지원이 없으므로 해당 옵션은 UI에서 제외함
|
| 291 |
+
o1mini_submit_button_o = gr.Button("전송")
|
| 292 |
+
|
| 293 |
+
def merge_and_call_o1mini_o(i1, i2, i3, i4, i5, sys_msg, mt, temp):
|
| 294 |
+
question = " ".join([i1, i2, i3, i4, i5])
|
| 295 |
+
return respond_o1mini_qna(
|
| 296 |
+
question=question,
|
| 297 |
+
system_message=sys_msg,
|
| 298 |
+
max_tokens=mt,
|
| 299 |
+
temperature=temp
|
| 300 |
+
)
|
| 301 |
+
o1mini_submit_button_o.click(
|
| 302 |
+
fn=merge_and_call_o1mini_o,
|
| 303 |
+
inputs=[
|
| 304 |
+
o1mini_input1_o, o1mini_input2_o, o1mini_input3_o, o1mini_input4_o, o1mini_input5_o,
|
| 305 |
+
o1mini_system_message_o,
|
| 306 |
+
o1mini_max_tokens_o,
|
| 307 |
+
o1mini_temperature_o
|
| 308 |
+
],
|
| 309 |
+
outputs=o1mini_answer_output_o
|
| 310 |
)
|
| 311 |
+
|
| 312 |
+
# UI 업데이트: 라디오 버튼 선택에 따라 gpt-4o-mini / o1-mini UI 전환
|
| 313 |
+
def update_openai_ui(model_choice):
|
| 314 |
+
if model_choice == "gpt-4o-mini":
|
| 315 |
+
return gr.update(visible=True), gr.update(visible=False)
|
| 316 |
+
else:
|
| 317 |
+
return gr.update(visible=False), gr.update(visible=True)
|
| 318 |
+
|
| 319 |
+
openai_model_radio.change(
|
| 320 |
+
fn=update_openai_ui,
|
| 321 |
+
inputs=openai_model_radio,
|
| 322 |
+
outputs=[chatgpt_ui, o1mini_ui]
|
| 323 |
)
|
| 324 |
|
| 325 |
#################
|
|
|
|
| 466 |
)
|
| 467 |
|
| 468 |
#################
|
| 469 |
+
# Cohere Command R+ 탭
|
| 470 |
#################
|
| 471 |
+
with gr.Tab("Cohere Command R+"):
|
| 472 |
+
cohere_input1 = gr.Textbox(label="입력1", lines=1)
|
| 473 |
+
cohere_input2 = gr.Textbox(label="입력2", lines=1)
|
| 474 |
+
cohere_input3 = gr.Textbox(label="입력3", lines=1)
|
| 475 |
+
cohere_input4 = gr.Textbox(label="입력4", lines=1)
|
| 476 |
+
cohere_input5 = gr.Textbox(label="입력5", lines=1)
|
| 477 |
+
|
| 478 |
+
cohere_answer_output = gr.Textbox(label="결과", lines=5, interactive=False)
|
| 479 |
+
|
| 480 |
+
with gr.Accordion("고급 설정 (Cohere)", open=False):
|
| 481 |
+
cohere_system_message = gr.Textbox(
|
| 482 |
+
value="""반드시 한글로 답변할 것.
|
| 483 |
+
너는 최고의 비서이다.
|
| 484 |
+
내가 요구하는것들을 최대한 자세하고 정확하게 답변하라.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 485 |
""",
|
| 486 |
+
label="System Message",
|
| 487 |
+
lines=3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 488 |
)
|
| 489 |
+
cohere_max_tokens = gr.Slider(minimum=100, maximum=10000, value=4000, step=100, label="Max Tokens")
|
| 490 |
+
cohere_temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature")
|
| 491 |
+
cohere_top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-P")
|
| 492 |
+
|
| 493 |
+
cohere_submit_button = gr.Button("전송")
|
| 494 |
+
|
| 495 |
+
def merge_and_call_cohere(i1, i2, i3, i4, i5, sys_msg, mt, temp, top_p_):
|
| 496 |
+
question = " ".join([i1, i2, i3, i4, i5])
|
| 497 |
+
return respond_cohere_qna(
|
| 498 |
+
question=question,
|
| 499 |
+
system_message=sys_msg,
|
| 500 |
+
max_tokens=mt,
|
| 501 |
+
temperature=temp,
|
| 502 |
+
top_p=top_p_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
)
|
| 504 |
+
|
| 505 |
+
cohere_submit_button.click(
|
| 506 |
+
fn=merge_and_call_cohere,
|
| 507 |
+
inputs=[
|
| 508 |
+
cohere_input1, cohere_input2, cohere_input3, cohere_input4, cohere_input5,
|
| 509 |
+
cohere_system_message,
|
| 510 |
+
cohere_max_tokens,
|
| 511 |
+
cohere_temperature,
|
| 512 |
+
cohere_top_p
|
| 513 |
+
],
|
| 514 |
+
outputs=cohere_answer_output
|
|
|
|
| 515 |
)
|
| 516 |
|
| 517 |
#############################
|