Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -21,7 +21,7 @@ def respond(message, system_message, max_tokens, temperature, top_p, selected_mo
|
|
21 |
client = get_client(selected_model)
|
22 |
|
23 |
messages = [
|
24 |
-
{"role": "system", "content": system_message},
|
25 |
{"role": "user", "content": message}
|
26 |
]
|
27 |
|
@@ -42,7 +42,7 @@ def respond(message, system_message, max_tokens, temperature, top_p, selected_mo
|
|
42 |
|
43 |
except Exception as e:
|
44 |
yield [(message, f"오류 발생: {str(e)}")]
|
45 |
-
|
46 |
def get_last_response(chatbot):
|
47 |
if chatbot and len(chatbot) > 0:
|
48 |
return chatbot[-1][1]
|
@@ -84,16 +84,23 @@ def stop_generation():
|
|
84 |
with gr.Blocks() as demo:
|
85 |
gr.Markdown("# 프롬프트 최적화 Playground")
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
with gr.Row():
|
88 |
with gr.Column(scale=1):
|
89 |
with gr.Accordion("모델 설정", open=True):
|
90 |
model = gr.Radio(list(models.keys()), value=list(models.keys())[0], label="언어 모델 선택", info="사용할 언어 모델을 선택하세요")
|
91 |
-
max_tokens = gr.Slider(minimum=
|
92 |
-
temperature = gr.Slider(minimum=0, maximum=
|
93 |
-
top_p = gr.Slider(minimum=0, maximum=1.0, value=0.90, step=0.05, label="Top-p")
|
94 |
|
95 |
system_message = gr.Textbox(
|
96 |
-
value="너는 나의 최고의 비서이다.\n내가 요구하는것들을 최대한 자세하고 정확하게 답변하라.\n반드시 한글로
|
97 |
label="시스템 메시지",
|
98 |
lines=5
|
99 |
)
|
@@ -103,7 +110,7 @@ with gr.Blocks() as demo:
|
|
103 |
prompt = gr.Textbox(
|
104 |
label="내용 입력",
|
105 |
lines=3,
|
106 |
-
placeholder="Shift+Enter
|
107 |
)
|
108 |
|
109 |
with gr.Row():
|
@@ -112,23 +119,6 @@ with gr.Blocks() as demo:
|
|
112 |
stop = gr.Button("🛑 생성 중단")
|
113 |
clear = gr.Button("🗑️ 대화 내역 지우기")
|
114 |
|
115 |
-
# JavaScript to handle key events
|
116 |
-
prompt.javascript = """
|
117 |
-
function(textbox) {
|
118 |
-
textbox.addEventListener("keydown", function(e) {
|
119 |
-
if (e.key === "Enter" && !e.shiftKey) {
|
120 |
-
e.preventDefault(); // Prevent default Enter behavior
|
121 |
-
return;
|
122 |
-
}
|
123 |
-
if (e.key === "Enter" && e.shiftKey) {
|
124 |
-
e.preventDefault(); // Prevent new line
|
125 |
-
document.querySelector("button.primary").click(); // Click the send button
|
126 |
-
}
|
127 |
-
});
|
128 |
-
return textbox;
|
129 |
-
}
|
130 |
-
"""
|
131 |
-
|
132 |
# Event handlers
|
133 |
send.click(respond, inputs=[prompt, system_message, max_tokens, temperature, top_p, model], outputs=[chatbot])
|
134 |
prompt.submit(respond, inputs=[prompt, system_message, max_tokens, temperature, top_p, model], outputs=[chatbot])
|
|
|
21 |
client = get_client(selected_model)
|
22 |
|
23 |
messages = [
|
24 |
+
{"role": "system", "content": system_message + "\n주어진 입력에만 정확히 답변하세요. 추가 질문을 만들거나 입력을 확장하지 마세요."},
|
25 |
{"role": "user", "content": message}
|
26 |
]
|
27 |
|
|
|
42 |
|
43 |
except Exception as e:
|
44 |
yield [(message, f"오류 발생: {str(e)}")]
|
45 |
+
|
46 |
def get_last_response(chatbot):
|
47 |
if chatbot and len(chatbot) > 0:
|
48 |
return chatbot[-1][1]
|
|
|
84 |
with gr.Blocks() as demo:
|
85 |
gr.Markdown("# 프롬프트 최적화 Playground")
|
86 |
|
87 |
+
gr.Markdown("""
|
88 |
+
**주의사항:**
|
89 |
+
- '전송' 버튼을 클릭하거나 입력 필드에서 Shift+Enter를 눌러 메시지를 전송할 수 있습니다.
|
90 |
+
- Enter 키는 줄바꿈으로 작동합니다.
|
91 |
+
- 입력한 내용에 대해서만 응답하도록 설정되어 있지만, 모델이 때때로 예상치 못한 방식으로 응답할 수 있습니다.
|
92 |
+
""")
|
93 |
+
|
94 |
with gr.Row():
|
95 |
with gr.Column(scale=1):
|
96 |
with gr.Accordion("모델 설정", open=True):
|
97 |
model = gr.Radio(list(models.keys()), value=list(models.keys())[0], label="언어 모델 선택", info="사용할 언어 모델을 선택하세요")
|
98 |
+
max_tokens = gr.Slider(minimum=1, maximum=2000, value=500, step=100, label="최대 새 토큰 수")
|
99 |
+
temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.05, label="온도")
|
100 |
+
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.90, step=0.05, label="Top-p (핵 샘플링)")
|
101 |
|
102 |
system_message = gr.Textbox(
|
103 |
+
value="너는 나의 최고의 비서이다.\n내가 요구하는것들을 최대한 자세하고 정확하게 답변하라.\n반드시 한글로 답변할것.\n사용자의 입력 내용에만 직접적으로 답변하고, 추가 질문을 만들거나 입력을 확장하지 마라.",
|
104 |
label="시스템 메시지",
|
105 |
lines=5
|
106 |
)
|
|
|
110 |
prompt = gr.Textbox(
|
111 |
label="내용 입력",
|
112 |
lines=3,
|
113 |
+
placeholder="메시지를 입력하세요. 전송 버튼을 클릭하거나 Shift+Enter를 눌러 전송합니다."
|
114 |
)
|
115 |
|
116 |
with gr.Row():
|
|
|
119 |
stop = gr.Button("🛑 생성 중단")
|
120 |
clear = gr.Button("🗑️ 대화 내역 지우기")
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
# Event handlers
|
123 |
send.click(respond, inputs=[prompt, system_message, max_tokens, temperature, top_p, model], outputs=[chatbot])
|
124 |
prompt.submit(respond, inputs=[prompt, system_message, max_tokens, temperature, top_p, model], outputs=[chatbot])
|