IliaLarchenko commited on
Commit
4518e15
β€’
1 Parent(s): fd17307

Speed up chat display

Browse files
Files changed (3) hide show
  1. app.py +14 -8
  2. llm.py +7 -6
  3. options.py +1 -1
app.py CHANGED
@@ -2,6 +2,7 @@ import os
2
 
3
  import gradio as gr
4
 
 
5
  from llm import end_interview, get_problem, read_last_message, send_request, speech_to_text, test_connection, text_to_speech
6
  from options import fixed_messages, topics_list
7
 
@@ -33,6 +34,11 @@ def add_interviewer_message(message):
33
  return f
34
 
35
 
 
 
 
 
 
36
  def hide_solution():
37
  solution_acc = gr.Accordion("Solution", open=False)
38
  end_btn = gr.Button("Finish the interview", interactive=False)
@@ -76,22 +82,22 @@ with gr.Blocks() as demo:
76
  with gr.Column(scale=1):
77
  try:
78
  audio_test = text_to_speech("Handshake")
79
- gr.Markdown("TTS status: 🟒")
80
  except:
81
- gr.Markdown("TTS status: πŸ”΄")
 
82
  try:
83
  text_test = speech_to_text(audio_test, False)
84
- gr.Markdown("STT status: 🟒")
85
  except:
86
- gr.Markdown("STT status: πŸ”΄")
87
 
88
  try:
89
  test_connection()
90
- gr.Markdown("LLM status: 🟒")
91
  except:
92
- gr.Markdown("LLM status: πŸ”΄")
93
 
94
- pass
95
  with gr.Tab("Coding") as coding_tab:
96
  chat_history = gr.State([])
97
  previous_code = gr.State("")
@@ -164,7 +170,7 @@ with gr.Blocks() as demo:
164
 
165
  audio_input.stop_recording(fn=speech_to_text, inputs=[audio_input], outputs=[message]).then(
166
  fn=lambda: None, inputs=None, outputs=[audio_input]
167
- ).then(
168
  fn=send_request,
169
  inputs=[code, previous_code, message, chat_history, chat],
170
  outputs=[chat_history, chat, message, previous_code],
 
2
 
3
  import gradio as gr
4
 
5
+ from config import LLM_NAME, STT_NAME, TTS_NAME
6
  from llm import end_interview, get_problem, read_last_message, send_request, speech_to_text, test_connection, text_to_speech
7
  from options import fixed_messages, topics_list
8
 
 
34
  return f
35
 
36
 
37
+ def add_candidate_message(message, chat):
38
+ chat.append((message, None))
39
+ return chat
40
+
41
+
42
  def hide_solution():
43
  solution_acc = gr.Accordion("Solution", open=False)
44
  end_btn = gr.Button("Finish the interview", interactive=False)
 
82
  with gr.Column(scale=1):
83
  try:
84
  audio_test = text_to_speech("Handshake")
85
+ gr.Markdown(f"TTS status: 🟒. Model: {TTS_NAME}")
86
  except:
87
+ gr.Markdown(f"TTS status: πŸ”΄. Model: {TTS_NAME}")
88
+
89
  try:
90
  text_test = speech_to_text(audio_test, False)
91
+ gr.Markdown(f"STT status: 🟒. Model: {STT_NAME}")
92
  except:
93
+ gr.Markdown(f"STT status: πŸ”΄. Model: {STT_NAME}")
94
 
95
  try:
96
  test_connection()
97
+ gr.Markdown(f"LLM status: 🟒. Model: {LLM_NAME}")
98
  except:
99
+ gr.Markdown(f"LLM status: πŸ”΄. Model: {LLM_NAME}")
100
 
 
101
  with gr.Tab("Coding") as coding_tab:
102
  chat_history = gr.State([])
103
  previous_code = gr.State("")
 
170
 
171
  audio_input.stop_recording(fn=speech_to_text, inputs=[audio_input], outputs=[message]).then(
172
  fn=lambda: None, inputs=None, outputs=[audio_input]
173
+ ).then(fn=add_candidate_message, inputs=[message, chat], outputs=[chat]).then(
174
  fn=send_request,
175
  inputs=[code, previous_code, message, chat_history, chat],
176
  outputs=[chat_history, chat, message, previous_code],
llm.py CHANGED
@@ -89,7 +89,7 @@ def send_request(code, previous_code, message, chat_history, chat_display, clien
89
  reply = response.choices[0].message.content.strip()
90
 
91
  chat_history.append({"role": "assistant", "content": reply})
92
- chat_display.append([message, reply])
93
 
94
  return chat_history, chat_display, "", code
95
 
@@ -117,7 +117,7 @@ def text_to_speech(text):
117
 
118
  if TTS_TYPE == "OPENAI_API":
119
  client = OpenAI(base_url=TTS_URL, api_key=os.getenv(f"{TTS_TYPE}_KEY"))
120
- response = client.audio.speech.create(model=TTS_NAME, voice="alloy", input=text)
121
  elif TTS_TYPE == "HF_API":
122
  headers = {"Authorization": "Bearer " + os.getenv(f"{STT_TYPE}_KEY")}
123
  response = requests.post(TTS_URL, headers=headers)
@@ -127,8 +127,9 @@ def text_to_speech(text):
127
 
128
 
129
  def read_last_message(chat_display):
130
- last_message = chat_display[-1][1]
131
- if last_message is not None:
132
- audio = text_to_speech(last_message)
133
- return audio
 
134
  return None
 
89
  reply = response.choices[0].message.content.strip()
90
 
91
  chat_history.append({"role": "assistant", "content": reply})
92
+ chat_display[-1][1] = reply
93
 
94
  return chat_history, chat_display, "", code
95
 
 
117
 
118
  if TTS_TYPE == "OPENAI_API":
119
  client = OpenAI(base_url=TTS_URL, api_key=os.getenv(f"{TTS_TYPE}_KEY"))
120
+ response = client.audio.speech.create(model=TTS_NAME, voice="alloy", response_format="opus", input=text)
121
  elif TTS_TYPE == "HF_API":
122
  headers = {"Authorization": "Bearer " + os.getenv(f"{STT_TYPE}_KEY")}
123
  response = requests.post(TTS_URL, headers=headers)
 
127
 
128
 
129
  def read_last_message(chat_display):
130
+ if len(chat_display) > 0:
131
+ last_message = chat_display[-1][1]
132
+ if last_message is not None:
133
+ audio = text_to_speech(last_message)
134
+ return audio
135
  return None
options.py CHANGED
@@ -25,7 +25,7 @@ fixed_messages = {
25
  "intro": "Welcome to the coding interview! I am your AI interview assistant. For the start select the difficulty and topic of the problem you would like to solve. Then click on the 'Generate a problem' button. Good luck!",
26
  "start": (
27
  "Please take a moment to read the problem statement. Then you can share you initial thoughts and ask any questions you may have. "
28
- "Please use the record button to communicate with me. Try to think out loud and record all you comments and questions as if it is the real interview."
29
  ),
30
  "end": "The interview has concluded. Thank you for your participation! In a moment I will provide a detailed feedback on your performance.",
31
  "error": "An error occurred. Please try again.",
 
25
  "intro": "Welcome to the coding interview! I am your AI interview assistant. For the start select the difficulty and topic of the problem you would like to solve. Then click on the 'Generate a problem' button. Good luck!",
26
  "start": (
27
  "Please take a moment to read the problem statement. Then you can share you initial thoughts and ask any questions you may have. "
28
+ # "Please use the record button to communicate with me. Try to think out loud and record all you comments and questions as if it is the real interview."
29
  ),
30
  "end": "The interview has concluded. Thank you for your participation! In a moment I will provide a detailed feedback on your performance.",
31
  "error": "An error occurred. Please try again.",