Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -49,6 +49,28 @@ def stop_generation():
|
|
49 |
stop_event.set()
|
50 |
return "생성이 중단되었습니다."
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
models = {
|
53 |
"deepseek-ai/DeepSeek-Coder-V2-Instruct": "(한국회사)DeepSeek-Coder-V2-Instruct",
|
54 |
"meta-llama/Meta-Llama-3.1-8B-Instruct": "Meta-Llama-3.1-8B-Instruct",
|
@@ -66,7 +88,10 @@ with gr.Blocks() as demo:
|
|
66 |
lines=3,
|
67 |
placeholder="메시지를 입력하세요. 엔터 키로 줄바꿈, Shift+Enter로 전송"
|
68 |
)
|
|
|
|
|
69 |
send = gr.Button("전송", scale=1)
|
|
|
70 |
|
71 |
with gr.Row():
|
72 |
regenerate = gr.Button("🔄 재생성")
|
@@ -99,8 +124,9 @@ with gr.Blocks() as demo:
|
|
99 |
"""
|
100 |
|
101 |
# 이벤트 핸들러 설정
|
102 |
-
msg.submit(
|
103 |
send.click(respond, inputs=[msg, chatbot, system_message, max_tokens, temperature, top_p, model], outputs=[msg, chatbot])
|
|
|
104 |
regenerate.click(lambda h, s, m, t, p, mod: respond(h[-1][0] if h else "", h[:-1], s, m, t, p, mod), inputs=[chatbot, system_message, max_tokens, temperature, top_p, model], outputs=[msg, chatbot])
|
105 |
stop.click(stop_generation, inputs=[], outputs=[msg])
|
106 |
clear.click(lambda: (None, None), outputs=[msg, chatbot])
|
|
|
49 |
stop_event.set()
|
50 |
return "생성이 중단되었습니다."
|
51 |
|
52 |
+
def continue_writing(history, system_message, max_tokens, temperature, top_p, model):
|
53 |
+
if not history:
|
54 |
+
return history
|
55 |
+
last_user_message = history[-1][0]
|
56 |
+
last_assistant_message = history[-1][1]
|
57 |
+
|
58 |
+
prompt = f"이전 대화를 계속 이어서 작성해주세요. 이전 응답: {last_assistant_message}"
|
59 |
+
|
60 |
+
try:
|
61 |
+
client = InferenceClient(model=model, token=hf_token)
|
62 |
+
messages = [{"role": "system", "content": system_message}]
|
63 |
+
messages.extend([{"role": "user" if i % 2 == 0 else "assistant", "content": m} for h in history for i, m in enumerate(h)])
|
64 |
+
messages.append({"role": "user", "content": prompt})
|
65 |
+
|
66 |
+
response = get_model_response(client, messages, max_tokens, temperature, top_p)
|
67 |
+
continued_response = last_assistant_message + " " + next(response)
|
68 |
+
|
69 |
+
new_history = history[:-1] + [(last_user_message, continued_response)]
|
70 |
+
return new_history
|
71 |
+
except Exception as e:
|
72 |
+
return history + [("시스템", f"계속 작성 중 오류 발생: {str(e)}")]
|
73 |
+
|
74 |
models = {
|
75 |
"deepseek-ai/DeepSeek-Coder-V2-Instruct": "(한국회사)DeepSeek-Coder-V2-Instruct",
|
76 |
"meta-llama/Meta-Llama-3.1-8B-Instruct": "Meta-Llama-3.1-8B-Instruct",
|
|
|
88 |
lines=3,
|
89 |
placeholder="메시지를 입력하세요. 엔터 키로 줄바꿈, Shift+Enter로 전송"
|
90 |
)
|
91 |
+
|
92 |
+
with gr.Row():
|
93 |
send = gr.Button("전송", scale=1)
|
94 |
+
continue_btn = gr.Button("계속 작성", scale=1)
|
95 |
|
96 |
with gr.Row():
|
97 |
regenerate = gr.Button("🔄 재생성")
|
|
|
124 |
"""
|
125 |
|
126 |
# 이벤트 핸들러 설정
|
127 |
+
msg.submit(lambda x: "", inputs=msg, outputs=msg) # 엔터 키 입력 시 아무 동작 안 함
|
128 |
send.click(respond, inputs=[msg, chatbot, system_message, max_tokens, temperature, top_p, model], outputs=[msg, chatbot])
|
129 |
+
continue_btn.click(continue_writing, inputs=[chatbot, system_message, max_tokens, temperature, top_p, model], outputs=[chatbot])
|
130 |
regenerate.click(lambda h, s, m, t, p, mod: respond(h[-1][0] if h else "", h[:-1], s, m, t, p, mod), inputs=[chatbot, system_message, max_tokens, temperature, top_p, model], outputs=[msg, chatbot])
|
131 |
stop.click(stop_generation, inputs=[], outputs=[msg])
|
132 |
clear.click(lambda: (None, None), outputs=[msg, chatbot])
|