Spaces:
Sleeping
Sleeping
IliaLarchenko
commited on
Commit
•
82598a2
1
Parent(s):
78654a1
Removed intermediate message object
Browse files- api/audio.py +4 -5
- api/llm.py +6 -5
- app.py +4 -6
api/audio.py
CHANGED
@@ -31,10 +31,8 @@ class STTManager:
|
|
31 |
self.config = config
|
32 |
self.streaming = os.getenv("STREAMING", False)
|
33 |
|
34 |
-
def speech_to_text(self, audio,
|
35 |
-
|
36 |
-
audio = numpy_audio_to_bytes(audio[1])
|
37 |
-
|
38 |
try:
|
39 |
if self.config.stt.type == "OPENAI_API":
|
40 |
data = ("temp.wav", audio, "audio/wav")
|
@@ -54,7 +52,8 @@ class STTManager:
|
|
54 |
except Exception as e:
|
55 |
raise APIError(f"STT Error: Unexpected error: {e}")
|
56 |
|
57 |
-
|
|
|
58 |
|
59 |
|
60 |
class TTSManager:
|
|
|
31 |
self.config = config
|
32 |
self.streaming = os.getenv("STREAMING", False)
|
33 |
|
34 |
+
def speech_to_text(self, audio, chat_display):
|
35 |
+
audio = numpy_audio_to_bytes(audio[1])
|
|
|
|
|
36 |
try:
|
37 |
if self.config.stt.type == "OPENAI_API":
|
38 |
data = ("temp.wav", audio, "audio/wav")
|
|
|
52 |
except Exception as e:
|
53 |
raise APIError(f"STT Error: Unexpected error: {e}")
|
54 |
|
55 |
+
chat_display.append([transcription, None])
|
56 |
+
return chat_display
|
57 |
|
58 |
|
59 |
class TTSManager:
|
api/llm.py
CHANGED
@@ -122,15 +122,16 @@ class LLMManager:
|
|
122 |
messages = self.get_problem_prepare_messages(requirements, difficulty, topic)
|
123 |
yield from self.get_text_stream(messages)
|
124 |
|
125 |
-
def update_chat_history(self, code, previous_code,
|
|
|
126 |
if code != previous_code:
|
127 |
chat_history.append({"role": "user", "content": f"My latest code:\n{code}"})
|
128 |
chat_history.append({"role": "user", "content": message})
|
129 |
|
130 |
return chat_history
|
131 |
|
132 |
-
def send_request_full(self, code, previous_code,
|
133 |
-
chat_history = self.update_chat_history(code, previous_code,
|
134 |
|
135 |
reply = self.get_text(chat_history)
|
136 |
chat_display.append([None, reply])
|
@@ -138,8 +139,8 @@ class LLMManager:
|
|
138 |
|
139 |
return chat_history, chat_display, code
|
140 |
|
141 |
-
def send_request_stream(self, code, previous_code,
|
142 |
-
chat_history = self.update_chat_history(code, previous_code,
|
143 |
|
144 |
chat_display.append([None, ""])
|
145 |
chat_history.append({"role": "assistant", "content": ""})
|
|
|
122 |
messages = self.get_problem_prepare_messages(requirements, difficulty, topic)
|
123 |
yield from self.get_text_stream(messages)
|
124 |
|
125 |
+
def update_chat_history(self, code, previous_code, chat_history, chat_display):
|
126 |
+
message = chat_display[-1][0]
|
127 |
if code != previous_code:
|
128 |
chat_history.append({"role": "user", "content": f"My latest code:\n{code}"})
|
129 |
chat_history.append({"role": "user", "content": message})
|
130 |
|
131 |
return chat_history
|
132 |
|
133 |
+
def send_request_full(self, code, previous_code, chat_history, chat_display):
|
134 |
+
chat_history = self.update_chat_history(code, previous_code, chat_history, chat_display)
|
135 |
|
136 |
reply = self.get_text(chat_history)
|
137 |
chat_display.append([None, reply])
|
|
|
139 |
|
140 |
return chat_history, chat_display, code
|
141 |
|
142 |
+
def send_request_stream(self, code, previous_code, chat_history, chat_display):
|
143 |
+
chat_history = self.update_chat_history(code, previous_code, chat_history, chat_display)
|
144 |
|
145 |
chat_display.append([None, ""])
|
146 |
chat_history.append({"role": "assistant", "content": ""})
|
app.py
CHANGED
@@ -133,7 +133,7 @@ with gr.Blocks(title="AI Interviewer") as demo:
|
|
133 |
end_btn = gr.Button("Finish the interview", interactive=False)
|
134 |
chat = gr.Chatbot(label="Chat", show_label=False, show_share_button=False)
|
135 |
audio_input = gr.Audio(interactive=False, **default_audio_params)
|
136 |
-
message = gr.Textbox(label="Message", lines=3, visible=False)
|
137 |
|
138 |
with gr.Accordion("Feedback", open=True) as feedback_acc:
|
139 |
feedback = gr.Markdown()
|
@@ -166,16 +166,14 @@ with gr.Blocks(title="AI Interviewer") as demo:
|
|
166 |
fn=llm.end_interview, inputs=[description, chat_history], outputs=[feedback]
|
167 |
)
|
168 |
|
169 |
-
audio_input.stop_recording(fn=stt.speech_to_text, inputs=[audio_input], outputs=[
|
170 |
fn=lambda: None, outputs=[audio_input]
|
171 |
-
).then(
|
172 |
fn=llm.send_request,
|
173 |
-
inputs=[code, previous_code,
|
174 |
outputs=[chat_history, chat, previous_code],
|
175 |
).then(
|
176 |
fn=tts.read_last_message, inputs=[chat], outputs=[audio_output]
|
177 |
-
).then(
|
178 |
-
fn=lambda: "", outputs=[message]
|
179 |
)
|
180 |
|
181 |
demo.launch(show_api=False)
|
|
|
133 |
end_btn = gr.Button("Finish the interview", interactive=False)
|
134 |
chat = gr.Chatbot(label="Chat", show_label=False, show_share_button=False)
|
135 |
audio_input = gr.Audio(interactive=False, **default_audio_params)
|
136 |
+
# message = gr.Textbox(label="Message", lines=3, visible=False)
|
137 |
|
138 |
with gr.Accordion("Feedback", open=True) as feedback_acc:
|
139 |
feedback = gr.Markdown()
|
|
|
166 |
fn=llm.end_interview, inputs=[description, chat_history], outputs=[feedback]
|
167 |
)
|
168 |
|
169 |
+
audio_input.stop_recording(fn=stt.speech_to_text, inputs=[audio_input, chat], outputs=[chat]).then(
|
170 |
fn=lambda: None, outputs=[audio_input]
|
171 |
+
).then(
|
172 |
fn=llm.send_request,
|
173 |
+
inputs=[code, previous_code, chat_history, chat],
|
174 |
outputs=[chat_history, chat, previous_code],
|
175 |
).then(
|
176 |
fn=tts.read_last_message, inputs=[chat], outputs=[audio_output]
|
|
|
|
|
177 |
)
|
178 |
|
179 |
demo.launch(show_api=False)
|