Jiangxz commited on
Commit
287273c
·
verified ·
1 Parent(s): 152527f

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -79,8 +79,6 @@ def parse_response(response):
79
 
80
  def generate(message, history, model, system_prompt, thinking_budget, api_key):
81
  """Generates the chatbot response."""
82
- gr.Info("開始思考分析問題,請稍待片刻......")
83
- start_time = time.time()
84
  # 獲取AI回應和思考時間
85
  response, thinking_time = respond(message, history, model, system_prompt, thinking_budget, api_key)
86
  # 如果回應是錯誤資訊,直接返回
@@ -103,8 +101,6 @@ def generate(message, history, model, system_prompt, thinking_budget, api_key):
103
  })
104
  # 新增AI的最終答案
105
  messages.append({"role": "assistant", "content": f"<b>{answer}</b>"})
106
- end_time = time.time()
107
- gr.Info(f"已成功推理回覆,總執行時間: {(end_time - start_time):.2f} 秒。")
108
  # 返回更新後的歷史記錄和空字串(用於清空輸入框)
109
  return history + messages, ""
110
 
@@ -150,10 +146,10 @@ custom_css = """
150
  text-align: center !important;
151
  color: #ff4081;
152
  text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
153
- margin-bottom: -20px !important;
154
  }
155
  .input-background {
156
- background-color: #e3f2fd !important;
157
  padding: 15px !important;
158
  border-radius: 10px !important;
159
  margin: 0 !important;
@@ -167,11 +163,6 @@ custom_css = """
167
  .custom-button {
168
  border-radius: 10px !important;
169
  }
170
- .natural-bg {
171
- background-color: #e8f5e9 !important;
172
- padding: 15px !important;
173
- border-radius: 10px !important;
174
- }
175
  .pink-bg {
176
  background-color: #ff4081 !important;
177
  border-radius: 10px !important;
@@ -199,7 +190,7 @@ custom_css = """
199
  with gr.Blocks(theme=gr.themes.Monochrome(), css=custom_css) as demo:
200
  gr.Markdown("# Multi-Chain Reasoning using Llama-3.1-Instruct. Deployed by 江信宗", elem_classes="center-aligned")
201
 
202
- with gr.Row(elem_classes="natural-bg"):
203
  model = gr.Dropdown(choices=MODELS, label="選擇模型", value=MODELS[0], elem_classes="input-background")
204
  thinking_budget = gr.Slider(minimum=1, maximum=100, value=20, step=1, label="思維規劃", info="模型所能進行的最大思考次數", elem_classes="input-background")
205
  api_key = gr.Textbox(label="API Key", type="password", placeholder="API authentication key for large language models", elem_classes="api-background")
@@ -218,7 +209,11 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css=custom_css) as demo:
218
  )
219
  msg = gr.Textbox(label="請輸入您的問題:", placeholder="輸入完成後直接按 Enter 開始執行......", elem_classes="pink-bg", max_lines=10)
220
  clear_button = gr.Button("清除聊天記錄", elem_classes="custom-button")
221
- clear_button.click(lambda: ([], ""), inputs=None, outputs=[chatbot, msg])
 
 
 
 
222
  system_prompt = gr.Textbox(label="System Prompt", value=DEFAULT_SYSTEM_PROMPT, visible=False)
223
  msg.submit(generate, inputs=[msg, chatbot, model, system_prompt, thinking_budget, api_key], outputs=[chatbot, msg])
224
 
 
79
 
80
  def generate(message, history, model, system_prompt, thinking_budget, api_key):
81
  """Generates the chatbot response."""
 
 
82
  # 獲取AI回應和思考時間
83
  response, thinking_time = respond(message, history, model, system_prompt, thinking_budget, api_key)
84
  # 如果回應是錯誤資訊,直接返回
 
101
  })
102
  # 新增AI的最終答案
103
  messages.append({"role": "assistant", "content": f"<b>{answer}</b>"})
 
 
104
  # 返回更新後的歷史記錄和空字串(用於清空輸入框)
105
  return history + messages, ""
106
 
 
146
  text-align: center !important;
147
  color: #ff4081;
148
  text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
149
+ margin-bottom: -10px !important;
150
  }
151
  .input-background {
152
+ background-color: #FFF4B5 !important;
153
  padding: 15px !important;
154
  border-radius: 10px !important;
155
  margin: 0 !important;
 
163
  .custom-button {
164
  border-radius: 10px !important;
165
  }
 
 
 
 
 
166
  .pink-bg {
167
  background-color: #ff4081 !important;
168
  border-radius: 10px !important;
 
190
  with gr.Blocks(theme=gr.themes.Monochrome(), css=custom_css) as demo:
191
  gr.Markdown("# Multi-Chain Reasoning using Llama-3.1-Instruct. Deployed by 江信宗", elem_classes="center-aligned")
192
 
193
+ with gr.Row():
194
  model = gr.Dropdown(choices=MODELS, label="選擇模型", value=MODELS[0], elem_classes="input-background")
195
  thinking_budget = gr.Slider(minimum=1, maximum=100, value=20, step=1, label="思維規劃", info="模型所能進行的最大思考次數", elem_classes="input-background")
196
  api_key = gr.Textbox(label="API Key", type="password", placeholder="API authentication key for large language models", elem_classes="api-background")
 
209
  )
210
  msg = gr.Textbox(label="請輸入您的問題:", placeholder="輸入完成後直接按 Enter 開始執行......", elem_classes="pink-bg", max_lines=10)
211
  clear_button = gr.Button("清除聊天記錄", elem_classes="custom-button")
212
+ clear_button.click(
213
+ lambda: ([], "", gr.Info("已成功清除聊天記錄,請繼續提問......")),
214
+ inputs=None,
215
+ outputs=[chatbot, msg]
216
+ )
217
  system_prompt = gr.Textbox(label="System Prompt", value=DEFAULT_SYSTEM_PROMPT, visible=False)
218
  msg.submit(generate, inputs=[msg, chatbot, model, system_prompt, thinking_budget, api_key], outputs=[chatbot, msg])
219