Ozaii commited on
Commit
a785029
·
verified ·
1 Parent(s): 78ac739

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -14
app.py CHANGED
@@ -13,7 +13,7 @@ print("Zephyr is getting ready to charm! 🌟")
13
  model = None
14
  tokenizer = None
15
 
16
- @spaces.GPU(duration=120)
17
  def load_model():
18
  global model, tokenizer
19
  if model is None:
@@ -61,8 +61,10 @@ def chat_with_zephyr(message, history):
61
  # Extract Zephyr's response
62
  zephyr_response = response.split("Zephyr:")[-1].strip()
63
 
64
- # Return the new message pair
65
- return "", zephyr_response
 
 
66
 
67
  css = """
68
  body {
@@ -80,18 +82,12 @@ with gr.Blocks(css=css) as iface:
80
  msg = gr.Textbox(placeholder="Tell Zephyr what's on your mind...", label="Your message")
81
  clear = gr.Button("Clear Chat")
82
 
83
- def user(user_message, history):
84
- return "", history + [[user_message, None]]
 
 
85
 
86
- def bot(history):
87
- user_message = history[-1][0]
88
- bot_response = chat_with_zephyr(user_message, history[:-1])
89
- history[-1][1] = bot_response
90
- return history
91
-
92
- msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
93
- bot, chatbot, chatbot
94
- )
95
  clear.click(lambda: None, None, chatbot, queue=False)
96
 
97
  gr.Markdown("""
 
13
  model = None
14
  tokenizer = None
15
 
16
+ @spaces.GPU
17
  def load_model():
18
  global model, tokenizer
19
  if model is None:
 
61
  # Extract Zephyr's response
62
  zephyr_response = response.split("Zephyr:")[-1].strip()
63
 
64
+ # Append the new exchange to the history
65
+ history.append((message, zephyr_response))
66
+
67
+ return history
68
 
69
  css = """
70
  body {
 
82
  msg = gr.Textbox(placeholder="Tell Zephyr what's on your mind...", label="Your message")
83
  clear = gr.Button("Clear Chat")
84
 
85
+ def respond(message, chat_history):
86
+ bot_message = chat_with_zephyr(message, chat_history)
87
+ chat_history.append((message, bot_message[-1][1]))
88
+ return "", chat_history
89
 
90
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
 
 
 
 
 
 
 
 
91
  clear.click(lambda: None, None, chatbot, queue=False)
92
 
93
  gr.Markdown("""