Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -14,7 +14,6 @@ from fastrtc import (
|
|
| 14 |
AdditionalOutputs,
|
| 15 |
ReplyOnPause,
|
| 16 |
Stream,
|
| 17 |
-
WebRTCError,
|
| 18 |
get_tts_model,
|
| 19 |
get_twilio_turn_credentials,
|
| 20 |
)
|
|
@@ -38,41 +37,36 @@ def response(
|
|
| 38 |
audio: tuple[int, np.ndarray],
|
| 39 |
chatbot: list[dict] | None = None,
|
| 40 |
):
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
yield AdditionalOutputs(chatbot)
|
| 53 |
-
messages.append({"role": "user", "content": prompt})
|
| 54 |
-
response = claude_client.messages.create(
|
| 55 |
-
model="claude-3-5-haiku-20241022",
|
| 56 |
-
max_tokens=512,
|
| 57 |
-
messages=messages, # type: ignore
|
| 58 |
-
)
|
| 59 |
-
response_text = " ".join(
|
| 60 |
-
block.text # type: ignore
|
| 61 |
-
for block in response.content
|
| 62 |
-
if getattr(block, "type", None) == "text"
|
| 63 |
-
)
|
| 64 |
-
chatbot.append({"role": "assistant", "content": response_text})
|
| 65 |
-
|
| 66 |
-
start = time.time()
|
| 67 |
-
|
| 68 |
-
print("starting tts", start)
|
| 69 |
-
for i, chunk in enumerate(tts_model.stream_tts_sync(response_text)):
|
| 70 |
-
print("chunk", i, time.time() - start)
|
| 71 |
-
yield chunk
|
| 72 |
-
print("finished tts", time.time() - start)
|
| 73 |
-
yield AdditionalOutputs(chatbot)
|
| 74 |
-
except Exception as e:
|
| 75 |
-
raise WebRTCError(str(e))
|
| 76 |
|
| 77 |
|
| 78 |
chatbot = gr.Chatbot(type="messages")
|
|
|
|
| 14 |
AdditionalOutputs,
|
| 15 |
ReplyOnPause,
|
| 16 |
Stream,
|
|
|
|
| 17 |
get_tts_model,
|
| 18 |
get_twilio_turn_credentials,
|
| 19 |
)
|
|
|
|
| 37 |
audio: tuple[int, np.ndarray],
|
| 38 |
chatbot: list[dict] | None = None,
|
| 39 |
):
|
| 40 |
+
chatbot = chatbot or []
|
| 41 |
+
messages = [{"role": d["role"], "content": d["content"]} for d in chatbot]
|
| 42 |
+
prompt = groq_client.audio.transcriptions.create(
|
| 43 |
+
file=("audio-file.mp3", audio_to_bytes(audio)),
|
| 44 |
+
model="whisper-large-v3-turbo",
|
| 45 |
+
response_format="verbose_json",
|
| 46 |
+
).text
|
| 47 |
+
chatbot.append({"role": "user", "content": prompt})
|
| 48 |
+
yield AdditionalOutputs(chatbot)
|
| 49 |
+
messages.append({"role": "user", "content": prompt})
|
| 50 |
+
response = claude_client.messages.create(
|
| 51 |
+
model="claude-3-5-haiku-20241022",
|
| 52 |
+
max_tokens=512,
|
| 53 |
+
messages=messages, # type: ignore
|
| 54 |
+
)
|
| 55 |
+
response_text = " ".join(
|
| 56 |
+
block.text # type: ignore
|
| 57 |
+
for block in response.content
|
| 58 |
+
if getattr(block, "type", None) == "text"
|
| 59 |
+
)
|
| 60 |
+
chatbot.append({"role": "assistant", "content": response_text})
|
| 61 |
+
|
| 62 |
+
start = time.time()
|
| 63 |
+
|
| 64 |
+
print("starting tts", start)
|
| 65 |
+
for i, chunk in enumerate(tts_model.stream_tts_sync(response_text)):
|
| 66 |
+
print("chunk", i, time.time() - start)
|
| 67 |
+
yield chunk
|
| 68 |
+
print("finished tts", time.time() - start)
|
| 69 |
yield AdditionalOutputs(chatbot)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
chatbot = gr.Chatbot(type="messages")
|