AIRider commited on
Commit
960780c
·
verified ·
1 Parent(s): b8376a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -73,6 +73,14 @@ def stop_generation():
73
  stop_event.set()
74
  return "생성이 중단되었습니다."
75
 
 
 
 
 
 
 
 
 
76
  models = {
77
  "deepseek-ai/DeepSeek-Coder-V2-Instruct": "(한국회사)DeepSeek-Coder-V2-Instruct",
78
  "meta-llama/Meta-Llama-3.1-8B-Instruct": "Meta-Llama-3.1-8B-Instruct",
@@ -96,7 +104,7 @@ with gr.Blocks() as demo:
96
  continue_btn = gr.Button("계속 작성", scale=1)
97
 
98
  with gr.Row():
99
- regenerate = gr.Button("🔄 재생성")
100
  stop = gr.Button("🛑 생성 중단")
101
  clear = gr.Button("🗑️ 대화 내역 지우기")
102
 
@@ -112,16 +120,15 @@ with gr.Blocks() as demo:
112
  model = gr.Radio(list(models.keys()), value=list(models.keys())[0], label="언어 모델 선택", info="사용할 언어 모델을 선택하세요")
113
 
114
  msg.javascript = """
115
- (x) => {
116
- const textbox = document.querySelector("#component-3");
 
 
117
  textbox.addEventListener("keydown", function(e) {
118
  if (e.key === 'Enter' && !e.shiftKey) {
119
  e.preventDefault();
120
- return;
121
- }
122
- if (e.key === 'Enter' && e.shiftKey) {
123
- e.preventDefault();
124
- document.querySelector("#component-5").click();
125
  }
126
  });
127
  return x;
@@ -131,11 +138,11 @@ with gr.Blocks() as demo:
131
  send.click(respond, inputs=[msg, chatbot, system_message, max_tokens, temperature, top_p, model], outputs=[msg, chatbot])
132
  msg.submit(respond, inputs=[msg, chatbot, system_message, max_tokens, temperature, top_p, model], outputs=[msg, chatbot])
133
  continue_btn.click(continue_writing, inputs=[chatbot, system_message, max_tokens, temperature, top_p, model], outputs=[msg, chatbot])
134
- 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])
135
  stop.click(stop_generation, inputs=[], outputs=[msg])
136
  clear.click(lambda: (None, None), outputs=[msg, chatbot])
137
 
138
  if __name__ == "__main__":
139
  if not hf_token:
140
  print("경고: HF_TOKEN 환경 변수가 설정되지 않았습니다. 일부 모델에 접근할 수 없을 수 있습니다.")
141
- demo.launch(share=True)
 
73
  stop_event.set()
74
  return "생성이 중단되었습니다."
75
 
76
+ def regenerate(history, system_message, max_tokens, temperature, top_p, model):
77
+ if not history:
78
+ return "", []
79
+ last_user_message = history[-1][0]
80
+ new_history = history[:-1]
81
+ for _, updated_history in respond(last_user_message, new_history, system_message, max_tokens, temperature, top_p, model):
82
+ yield "", updated_history
83
+
84
  models = {
85
  "deepseek-ai/DeepSeek-Coder-V2-Instruct": "(한국회사)DeepSeek-Coder-V2-Instruct",
86
  "meta-llama/Meta-Llama-3.1-8B-Instruct": "Meta-Llama-3.1-8B-Instruct",
 
104
  continue_btn = gr.Button("계속 작성", scale=1)
105
 
106
  with gr.Row():
107
+ regenerate_btn = gr.Button("🔄 재생성")
108
  stop = gr.Button("🛑 생성 중단")
109
  clear = gr.Button("🗑️ 대화 내역 지우기")
110
 
 
120
  model = gr.Radio(list(models.keys()), value=list(models.keys())[0], label="언어 모델 선택", info="사용할 언어 모델을 선택하세요")
121
 
122
  msg.javascript = """
123
+ function(x) {
124
+ const textbox = document.getElementById('component-3');
125
+ if (!textbox) return x;
126
+
127
  textbox.addEventListener("keydown", function(e) {
128
  if (e.key === 'Enter' && !e.shiftKey) {
129
  e.preventDefault();
130
+ const sendButton = document.getElementById('component-5');
131
+ if (sendButton) sendButton.click();
 
 
 
132
  }
133
  });
134
  return x;
 
138
  send.click(respond, inputs=[msg, chatbot, system_message, max_tokens, temperature, top_p, model], outputs=[msg, chatbot])
139
  msg.submit(respond, inputs=[msg, chatbot, system_message, max_tokens, temperature, top_p, model], outputs=[msg, chatbot])
140
  continue_btn.click(continue_writing, inputs=[chatbot, system_message, max_tokens, temperature, top_p, model], outputs=[msg, chatbot])
141
+ regenerate_btn.click(regenerate, inputs=[chatbot, system_message, max_tokens, temperature, top_p, model], outputs=[msg, chatbot])
142
  stop.click(stop_generation, inputs=[], outputs=[msg])
143
  clear.click(lambda: (None, None), outputs=[msg, chatbot])
144
 
145
  if __name__ == "__main__":
146
  if not hf_token:
147
  print("경고: HF_TOKEN 환경 변수가 설정되지 않았습니다. 일부 모델에 접근할 수 없을 수 있습니다.")
148
+ demo.launch()