Jonas Wiesli commited on
Commit
07fe324
1 Parent(s): 288fcab

add question counter

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -35,6 +35,7 @@ with gr.Blocks() as iface:
35
  msg.append(gr.Textbox())
36
  i += 1
37
 
 
38
 
39
  def user(user_message, history):
40
  return "", history + [[user_message, None]]
@@ -65,7 +66,6 @@ with gr.Blocks() as iface:
65
  history[-1][1] = bot_message
66
  return history
67
 
68
-
69
  def generateAIMessage(history, characterId):
70
  message_history = [
71
  {"role": "system", "content": initText[characterId] + "Stay in character. Use natural language. Don't "
@@ -83,9 +83,16 @@ with gr.Blocks() as iface:
83
  )
84
  return completion.choices[0].message.content
85
 
 
 
 
 
 
86
  # again, ugly workaround
87
  msg[0].submit(user, [msg[0], chatbot[0]], [msg[0], chatbot[0]], queue=False).then(
88
  bot0, chatbot[0], chatbot[0]
 
 
89
  )
90
  msg[1].submit(user, [msg[1], chatbot[1]], [msg[1], chatbot[1]], queue=False).then(
91
  bot1, chatbot[1], chatbot[1]
 
35
  msg.append(gr.Textbox())
36
  i += 1
37
 
38
+ questionCounter = gr.Label(value="Remaining Questions: 24")
39
 
40
  def user(user_message, history):
41
  return "", history + [[user_message, None]]
 
66
  history[-1][1] = bot_message
67
  return history
68
 
 
69
  def generateAIMessage(history, characterId):
70
  message_history = [
71
  {"role": "system", "content": initText[characterId] + "Stay in character. Use natural language. Don't "
 
83
  )
84
  return completion.choices[0].message.content
85
 
86
+ def updateQuestions(prevText):
87
+ remainingQuestions = prevText.split(": ")[1]
88
+ remainingQuestions -= 1
89
+ return "Remaining Questions: " + remainingQuestions
90
+
91
  # again, ugly workaround
92
  msg[0].submit(user, [msg[0], chatbot[0]], [msg[0], chatbot[0]], queue=False).then(
93
  bot0, chatbot[0], chatbot[0]
94
+ ).then(
95
+ updateQuestions, questionCounter, questionCounter
96
  )
97
  msg[1].submit(user, [msg[1], chatbot[1]], [msg[1], chatbot[1]], queue=False).then(
98
  bot1, chatbot[1], chatbot[1]