GabrielSchultz commited on
Commit
3433ea2
·
verified ·
1 Parent(s): 3f8ecf2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -6,7 +6,7 @@ import random
6
  api_key = os.getenv("apichatbotacess")
7
 
8
  # Define the API calling function
9
- def api_call(prompt, model_name, chat_history):
10
  url = "https://multimodalcompany-dev--talent-chatbot-beta-dev-dev.modal.run"
11
  headers = {
12
  "key": api_key,
@@ -14,7 +14,7 @@ def api_call(prompt, model_name, chat_history):
14
  }
15
  data = {
16
  "prompt": prompt,
17
- "thread_id": random.randint(1, 10000), # Use a random number for thread_id
18
  "nameM": model_name,
19
  "max_new_tokens": 4096,
20
  "top_p": 0.95,
@@ -42,7 +42,7 @@ with gr.Blocks() as demo:
42
  msg = gr.Textbox(label="Your Message")
43
 
44
  def respond(message, model_name, chat_history):
45
- bot_message = api_call(message, model_name, chat_history)
46
  chat_history.append((message, bot_message))
47
  return "", chat_history
48
 
@@ -50,11 +50,11 @@ with gr.Blocks() as demo:
50
  # Reset the chat history when the model_name changes
51
  global chat_history
52
  chat_history = []
53
- return chat_history, []
54
 
55
  # Link the reset function to the model_name dropdown
56
- model_name.change(reset_chat_history, inputs=model_name, outputs=[chatbot, gr.State(chat_history)])
57
 
58
- msg.submit(respond, [msg, model_name, gr.State(chat_history)], [msg, chatbot])
59
 
60
  demo.launch()
 
6
  api_key = os.getenv("apichatbotacess")
7
 
8
  # Define the API calling function
9
+ def api_call(prompt, thread_id, model_name, chat_history):
10
  url = "https://multimodalcompany-dev--talent-chatbot-beta-dev-dev.modal.run"
11
  headers = {
12
  "key": api_key,
 
14
  }
15
  data = {
16
  "prompt": prompt,
17
+ "thread_id": thread_id, # Use a random number for thread_id
18
  "nameM": model_name,
19
  "max_new_tokens": 4096,
20
  "top_p": 0.95,
 
42
  msg = gr.Textbox(label="Your Message")
43
 
44
  def respond(message, model_name, chat_history):
45
+ bot_message = api_call(message, random.randint(1, 10000), model_name, chat_history)
46
  chat_history.append((message, bot_message))
47
  return "", chat_history
48
 
 
50
  # Reset the chat history when the model_name changes
51
  global chat_history
52
  chat_history = []
53
+ return [], chat_history
54
 
55
  # Link the reset function to the model_name dropdown
56
+ model_name.change(fn=reset_chat_history, inputs=model_name, outputs=[chatbot, gr.State(chat_history)])
57
 
58
+ msg.submit(fn=respond, inputs=[msg, model_name, gr.State(chat_history)], outputs=[msg, chatbot])
59
 
60
  demo.launch()