artificialguybr commited on
Commit
d5f5631
·
verified ·
1 Parent(s): 8919bea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -99,28 +99,31 @@ with gr.Blocks() as demo:
99
  top_p = gr.Slider(0.0, 1.0, label="Top P", step=0.05, value=0.7, interactive=True)
100
  chat_history_state = gr.State([])
101
 
102
- def update_chatbot(message, chat_history, system_message): # Remova o valor padrão aqui
 
103
  print("Updating chatbot...")
104
  if not chat_history or (chat_history and chat_history[-1]["role"] != "user"):
105
  chat_history = user(message, chat_history, system_message if not chat_history else None)
106
  else:
107
  chat_history = user(message, chat_history)
108
- chat_history, _ = chat(chat_history, system_message, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
109
 
110
  formatted_chat_history = []
111
  for user_msg, assistant_msg in zip([msg["content"].strip() for msg in chat_history if msg["role"] == "user"],
112
  [msg["content"].strip() for msg in chat_history if msg["role"] == "assistant"]):
113
- if user_msg or assistant_msg: # Verify if either message is not empty
114
  formatted_chat_history.append([user_msg, assistant_msg])
115
 
116
  return formatted_chat_history, chat_history, ""
117
-
 
118
  submit.click(
119
  fn=update_chatbot,
120
- inputs=[message, chat_history_state, system_msg],
121
  outputs=[chatbot, chat_history_state, message]
122
  )
123
 
 
124
  clear.click(
125
  fn=clear_chat,
126
  inputs=[chat_history_state, message],
 
99
  top_p = gr.Slider(0.0, 1.0, label="Top P", step=0.05, value=0.7, interactive=True)
100
  chat_history_state = gr.State([])
101
 
102
+ # Ajuste na definição da função update_chatbot para aceitar os valores atualizados
103
+ def update_chatbot(message, chat_history, system_message, max_tokens, temperature, top_p): # Inclua os novos parâmetros aqui
104
  print("Updating chatbot...")
105
  if not chat_history or (chat_history and chat_history[-1]["role"] != "user"):
106
  chat_history = user(message, chat_history, system_message if not chat_history else None)
107
  else:
108
  chat_history = user(message, chat_history)
109
+ chat_history, _ = chat(chat_history, system_message, max_tokens, temperature, top_p, 40, 1.1) # Use os parâmetros atualizados aqui
110
 
111
  formatted_chat_history = []
112
  for user_msg, assistant_msg in zip([msg["content"].strip() for msg in chat_history if msg["role"] == "user"],
113
  [msg["content"].strip() for msg in chat_history if msg["role"] == "assistant"]):
114
+ if user_msg or assistant_msg:
115
  formatted_chat_history.append([user_msg, assistant_msg])
116
 
117
  return formatted_chat_history, chat_history, ""
118
+
119
+ # Ajuste na chamada do botão submit para incluir os novos inputs
120
  submit.click(
121
  fn=update_chatbot,
122
+ inputs=[message, chat_history_state, system_msg, max_tokens, temperature, top_p], # Inclua os novos inputs aqui
123
  outputs=[chatbot, chat_history_state, message]
124
  )
125
 
126
+
127
  clear.click(
128
  fn=clear_chat,
129
  inputs=[chat_history_state, message],