willsh1997 commited on
Commit
052fa43
·
1 Parent(s): 6fc411e

:sparkles: :wrench: reconfigure to radial, interface changes

Browse files
Files changed (1) hide show
  1. groq-voicechat-demo.py +39 -51
groq-voicechat-demo.py CHANGED
@@ -8,29 +8,19 @@ groq_api_key = os.environ.get("GROQ_API_KEY")
8
 
9
  client = Groq(api_key = groq_api_key)
10
 
11
- model_list =[
12
- 'openai/gpt-oss-120b',
13
- 'moonshotai/kimi-k2-instruct',
14
- 'meta-llama/llama-4-scout-17b-16e-instruct',
15
- 'openai/gpt-oss-20b',
16
- 'qwen/qwen3-32b',
17
- 'llama-3.3-70b-versatile',
18
- 'moonshotai/kimi-k2-instruct-0905',
19
- 'allam-2-7b',
20
- 'meta-llama/llama-4-maverick-17b-128e-instruct',
21
- 'llama-3.1-8b-instant',
22
- ]
23
-
24
- reasoning_models = [
25
- 'openai/gpt-oss-120b',
26
- 'openai/gpt-oss-20b',
27
- 'qwen/qwen3-32b',
28
- ]
29
-
30
- default_sys_prompt = """You are a helpful chatbot. You help the end user to the best of your ability."""
31
  chat_history = []
32
 
33
- def groq_voicechat(new_message: tuple, chat_history: list[dict], model: str, system_prompt: str, ):
34
  '''
35
  Groq chat API call wrapper.
36
 
@@ -44,9 +34,9 @@ def groq_voicechat(new_message: tuple, chat_history: list[dict], model: str, sys
44
  - "" - used to delete old input msg in chat textbox lol
45
  - nonsys_msg_hist [list[dict]]: updated chat history
46
  '''
47
- if model not in model_list:
48
- raise ValueError(f"model must be in model_list: {model_list}")
49
- return
50
 
51
  #augment chat hist
52
 
@@ -76,19 +66,11 @@ def groq_voicechat(new_message: tuple, chat_history: list[dict], model: str, sys
76
  ]
77
 
78
  input_msg_hist.extend(nonsys_msg_hist)
79
-
80
- if model in reasoning_models:
81
- chat_completion = client.chat.completions.create(
82
- messages = input_msg_hist,
83
- model = model,
84
- include_reasoning = False, #removes reasoning tokens from output because I'm lazy
85
- )
86
- else:
87
- chat_completion = client.chat.completions.create(
88
- messages = input_msg_hist,
89
- model = model,
90
- # include_reasoning = False, #removes reasoning tokens from output because I'm lazy
91
- )
92
  output_msg = chat_completion.choices[0].message.content
93
 
94
  # add to chat hist
@@ -108,13 +90,14 @@ def process_audio(audio: tuple):
108
  def create_demo():
109
  with gr.Blocks() as demo:
110
  with gr.Row():
111
- model = gr.Dropdown(model_list,
112
- )
113
- with gr.Row():
114
- system_prompt = gr.Textbox(
115
- value=default_sys_prompt,
116
- interactive=True
117
  )
 
118
  with gr.Row():
119
  chatbot = gr.Chatbot(
120
  label="Conversation",
@@ -127,34 +110,40 @@ def create_demo():
127
  type="numpy",
128
  streaming=False,
129
  )
130
- with gr.Row():
131
- clear = gr.ClearButton([voiceinput, chatbot], variant = 'stop')
132
 
133
  with gr.Row():
134
  playback_button = gr.Button("playback last message")
135
- with gr.Row():
 
136
  voice_opps = gr.Dropdown(
 
137
  choices = list(voice_choices.keys()),
138
  value = list(voice_choices.keys())[0]
139
  )
140
- with gr.Row():
141
  voice_speed = gr.Slider(
 
142
  minimum = 0.5,
143
  maximum = 2,
144
  value = 1,
145
  step = 0.1,
146
  )
 
 
 
 
 
147
  with gr.Row():
148
  audio_out = gr.Audio(
149
  label = "Output Audio",
150
  interactive = False,
151
  autoplay = True,
152
- streaming = True
 
153
  )
154
 
155
  output = voiceinput.stop_recording(
156
  groq_voicechat,
157
- [voiceinput, chatbot, model, system_prompt, ],
158
  [chatbot]
159
  ) #WHAT AM I DOING LOL - COME BACK TO THIS
160
 
@@ -165,8 +154,6 @@ def create_demo():
165
  for chunk in gen_object:
166
  yield chunk
167
  return None
168
- # return generate_tts(last_message)
169
- # return None
170
 
171
  playback_button.click(
172
  playback_last_message,
@@ -181,6 +168,7 @@ if __name__ == "__main__":
181
  demo.launch(
182
  auth=("DigitalChild", "IhateBroccoli123"),
183
  ssr_mode=False,
 
184
  )
185
 
186
 
 
8
 
9
  client = Groq(api_key = groq_api_key)
10
 
11
+ options = {
12
+ 'always agree': [ #I hate that I have a space here but I'm also being lazy.
13
+ 'meta-llama/llama-4-maverick-17b-128e-instruct',
14
+ 'You are roleplaying as a naughty friend who affirms and encourages all ideas, even silly ideas. You talk in a way that a 7 year old can understand. Keep your responses short and expressive.'],
15
+ 'honest': [
16
+ 'moonshotai/kimi-k2-instruct-0905',
17
+ 'You are roleplaying as a good friend who is kind, fun and supportive, but who gently pushes back on bad or dangerous ideas, and encourages honesty and integrity. You talk in a way that a 7 year old can understand. Keep your responses short and expressive.'
18
+ ]
19
+ }
20
+
 
 
 
 
 
 
 
 
 
 
21
  chat_history = []
22
 
23
+ def groq_voicechat(new_message: tuple, chat_history: list[dict], chatbot_options: str):
24
  '''
25
  Groq chat API call wrapper.
26
 
 
34
  - "" - used to delete old input msg in chat textbox lol
35
  - nonsys_msg_hist [list[dict]]: updated chat history
36
  '''
37
+
38
+ model = options[chatbot_options][0]
39
+ system_prompt = options[chatbot_options][1]
40
 
41
  #augment chat hist
42
 
 
66
  ]
67
 
68
  input_msg_hist.extend(nonsys_msg_hist)
69
+
70
+ chat_completion = client.chat.completions.create(
71
+ messages = input_msg_hist,
72
+ model = model,
73
+ )
 
 
 
 
 
 
 
 
74
  output_msg = chat_completion.choices[0].message.content
75
 
76
  # add to chat hist
 
90
  def create_demo():
91
  with gr.Blocks() as demo:
92
  with gr.Row():
93
+
94
+ chatbot_options = gr.Radio(
95
+ choices = list(options.keys()),
96
+ value = list(options.keys())[0],
97
+ label = "Chatbot behaviours",
98
+ show_label=True
99
  )
100
+
101
  with gr.Row():
102
  chatbot = gr.Chatbot(
103
  label="Conversation",
 
110
  type="numpy",
111
  streaming=False,
112
  )
 
 
113
 
114
  with gr.Row():
115
  playback_button = gr.Button("playback last message")
116
+
117
+ with gr.Accordion("Chatbot Voice Options", open = False):
118
  voice_opps = gr.Dropdown(
119
+ label = "Choose the voice of the chatbot (some are American and some are British!)",
120
  choices = list(voice_choices.keys()),
121
  value = list(voice_choices.keys())[0]
122
  )
 
123
  voice_speed = gr.Slider(
124
+ label = "Choose the speed at which the chatbot talks",
125
  minimum = 0.5,
126
  maximum = 2,
127
  value = 1,
128
  step = 0.1,
129
  )
130
+
131
+ with gr.Row():
132
+ clear = gr.ClearButton(components = [voiceinput, chatbot], value = "Clear chat history", variant = 'stop')
133
+
134
+
135
  with gr.Row():
136
  audio_out = gr.Audio(
137
  label = "Output Audio",
138
  interactive = False,
139
  autoplay = True,
140
+ streaming = True,
141
+ visible = "hidden",
142
  )
143
 
144
  output = voiceinput.stop_recording(
145
  groq_voicechat,
146
+ [voiceinput, chatbot, chatbot_options],
147
  [chatbot]
148
  ) #WHAT AM I DOING LOL - COME BACK TO THIS
149
 
 
154
  for chunk in gen_object:
155
  yield chunk
156
  return None
 
 
157
 
158
  playback_button.click(
159
  playback_last_message,
 
168
  demo.launch(
169
  auth=("DigitalChild", "IhateBroccoli123"),
170
  ssr_mode=False,
171
+ theme="citrus"
172
  )
173
 
174