Chad commited on
Commit
04accba
·
1 Parent(s): 2923823

profound mode

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -9,9 +9,13 @@ if not api_key:
9
 
10
  client = Groq(api_key=api_key)
11
 
12
- def generate_reply(user_input, chat_history):
13
  if chat_history is None:
14
  chat_history = []
 
 
 
 
15
 
16
  conversation = [{"role": "system", "content": (
17
  "Determine the language of the user's question and respond in the same language. "
@@ -32,7 +36,7 @@ def generate_reply(user_input, chat_history):
32
  "The following questions are examples of questions that should be rejected"
33
  "Is water wet?"
34
  "Is god real?"
35
-
36
  )}]
37
 
38
  for entry in chat_history:
@@ -45,7 +49,7 @@ def generate_reply(user_input, chat_history):
45
  model="llama3-70b-8192",
46
  messages=conversation,
47
  temperature=0.7,
48
- max_completion_tokens=512,
49
  top_p=0.95,
50
  stream=False,
51
  stop=None,
@@ -58,6 +62,11 @@ def generate_reply(user_input, chat_history):
58
  chat_history.append({"role": "assistant", "content": reply})
59
  return chat_history, chat_history, ""
60
 
 
 
 
 
 
61
  def generate_quiz(subject, num_questions, chat_history, language_state):
62
  """Generate a history quiz with multiple-choice questions and append it to the chat."""
63
  try:
@@ -132,6 +141,7 @@ def user_guide(chat_history, language_state):
132
  return chat_history, chat_history
133
 
134
  with gr.Blocks() as interface:
 
135
  language_state = gr.State("english")
136
  examples = [
137
  "How did the Leaning Tower of Pisa start leaning?",
@@ -146,6 +156,7 @@ with gr.Blocks() as interface:
146
  lang_button = gr.Button("FR")
147
  help_button = gr.Button("User Guide")
148
  chatbot = gr.Chatbot(type="messages")
 
149
  user_input = gr.Textbox(placeholder="Enter your question here...")
150
  send_button = gr.Button("Send")
151
  reset_button = gr.Button("New Conversation")
@@ -181,9 +192,15 @@ with gr.Blocks() as interface:
181
  outputs=[language_state, title, lang_button, user_input, send_button, reset_button, quiz_subject, quiz_num_questions, quiz_button, help_button]
182
  )
183
 
 
 
 
 
 
 
184
  send_button.click(
185
  fn=generate_reply,
186
- inputs=[user_input, state],
187
  outputs=[chatbot, state, user_input]
188
  )
189
 
 
9
 
10
  client = Groq(api_key=api_key)
11
 
12
+ def generate_reply(user_input, chat_history, profound_state):
13
  if chat_history is None:
14
  chat_history = []
15
+
16
+ profound_mode = "Provide a basic explanation"
17
+ if profound_state:
18
+ profound_mode = "Provide a highly detailed and in-depth explanation, including historical context, key figures, and consequences of the event."
19
 
20
  conversation = [{"role": "system", "content": (
21
  "Determine the language of the user's question and respond in the same language. "
 
36
  "The following questions are examples of questions that should be rejected"
37
  "Is water wet?"
38
  "Is god real?"
39
+ f" {profound_mode}"
40
  )}]
41
 
42
  for entry in chat_history:
 
49
  model="llama3-70b-8192",
50
  messages=conversation,
51
  temperature=0.7,
52
+ max_completion_tokens=1024 if profound_state else 512,
53
  top_p=0.95,
54
  stream=False,
55
  stop=None,
 
62
  chat_history.append({"role": "assistant", "content": reply})
63
  return chat_history, chat_history, ""
64
 
65
+ def toggle_profound_mode(current_state):
66
+ new_state = not current_state
67
+ button_label = "Disable Profound Mode" if new_state else "Enable Profound Mode"
68
+ return new_state, button_label
69
+
70
  def generate_quiz(subject, num_questions, chat_history, language_state):
71
  """Generate a history quiz with multiple-choice questions and append it to the chat."""
72
  try:
 
141
  return chat_history, chat_history
142
 
143
  with gr.Blocks() as interface:
144
+ profound_state = gr.State(False)
145
  language_state = gr.State("english")
146
  examples = [
147
  "How did the Leaning Tower of Pisa start leaning?",
 
156
  lang_button = gr.Button("FR")
157
  help_button = gr.Button("User Guide")
158
  chatbot = gr.Chatbot(type="messages")
159
+ profound_button = gr.Button("Enable Profound Mode")
160
  user_input = gr.Textbox(placeholder="Enter your question here...")
161
  send_button = gr.Button("Send")
162
  reset_button = gr.Button("New Conversation")
 
192
  outputs=[language_state, title, lang_button, user_input, send_button, reset_button, quiz_subject, quiz_num_questions, quiz_button, help_button]
193
  )
194
 
195
+ profound_button.click(
196
+ fn=toggle_profound_mode,
197
+ inputs=[profound_state],
198
+ outputs=[profound_state, profound_button]
199
+ )
200
+
201
  send_button.click(
202
  fn=generate_reply,
203
+ inputs=[user_input, state, profound_state],
204
  outputs=[chatbot, state, user_input]
205
  )
206