Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Upload folder using huggingface_hub
Browse files- app.py +23 -3
- index.html +12 -6
- requirements.txt +0 -1
app.py
CHANGED
@@ -50,12 +50,32 @@ class OpenAIHandler(AsyncStreamHandler):
|
|
50 |
model="gpt-4o-mini-realtime-preview-2024-12-17"
|
51 |
) as conn:
|
52 |
await conn.session.update(
|
53 |
-
session={
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
)
|
55 |
self.connection = conn
|
56 |
async for event in self.connection:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
if event.type == "response.audio_transcript.done":
|
58 |
-
await self.output_queue.put(
|
|
|
|
|
|
|
|
|
59 |
if event.type == "response.audio.delta":
|
60 |
await self.output_queue.put(
|
61 |
(
|
@@ -121,7 +141,7 @@ def _(webrtc_id: str):
|
|
121 |
import json
|
122 |
|
123 |
async for output in stream.output_stream(webrtc_id):
|
124 |
-
s = json.dumps(
|
125 |
yield f"event: output\ndata: {s}\n\n"
|
126 |
|
127 |
return StreamingResponse(output_stream(), media_type="text/event-stream")
|
|
|
50 |
model="gpt-4o-mini-realtime-preview-2024-12-17"
|
51 |
) as conn:
|
52 |
await conn.session.update(
|
53 |
+
session={
|
54 |
+
"turn_detection": {"type": "server_vad"},
|
55 |
+
"input_audio_transcription": {
|
56 |
+
"model": "whisper-1",
|
57 |
+
"language": "en",
|
58 |
+
},
|
59 |
+
}
|
60 |
)
|
61 |
self.connection = conn
|
62 |
async for event in self.connection:
|
63 |
+
# Handle interruptions
|
64 |
+
if event.type == "input_audio_buffer.speech_started":
|
65 |
+
self.clear_queue()
|
66 |
+
if (
|
67 |
+
event.type
|
68 |
+
== "conversation.item.input_audio_transcription.completed"
|
69 |
+
):
|
70 |
+
await self.output_queue.put(
|
71 |
+
AdditionalOutputs({"role": "user", "content": event.transcript})
|
72 |
+
)
|
73 |
if event.type == "response.audio_transcript.done":
|
74 |
+
await self.output_queue.put(
|
75 |
+
AdditionalOutputs(
|
76 |
+
{"role": "assistant", "content": event.transcript}
|
77 |
+
)
|
78 |
+
)
|
79 |
if event.type == "response.audio.delta":
|
80 |
await self.output_queue.put(
|
81 |
(
|
|
|
141 |
import json
|
142 |
|
143 |
async for output in stream.output_stream(webrtc_id):
|
144 |
+
s = json.dumps(output.args[0])
|
145 |
yield f"event: output\ndata: {s}\n\n"
|
146 |
|
147 |
return StreamingResponse(output_stream(), media_type="text/event-stream")
|
index.html
CHANGED
@@ -45,20 +45,26 @@
|
|
45 |
|
46 |
.message {
|
47 |
margin-bottom: 20px;
|
48 |
-
padding: 12px;
|
49 |
-
border-radius:
|
50 |
font-size: 16px;
|
51 |
line-height: 1.5;
|
|
|
|
|
52 |
}
|
53 |
|
54 |
.message.user {
|
55 |
-
background-color: #
|
56 |
-
|
|
|
|
|
57 |
}
|
58 |
|
59 |
.message.assistant {
|
60 |
background-color: #262626;
|
61 |
-
|
|
|
|
|
62 |
}
|
63 |
|
64 |
.controls {
|
@@ -435,7 +441,7 @@
|
|
435 |
const eventSource = new EventSource('/outputs?webrtc_id=' + webrtc_id);
|
436 |
eventSource.addEventListener("output", (event) => {
|
437 |
const eventJson = JSON.parse(event.data);
|
438 |
-
addMessage(
|
439 |
|
440 |
});
|
441 |
} catch (err) {
|
|
|
45 |
|
46 |
.message {
|
47 |
margin-bottom: 20px;
|
48 |
+
padding: 12px 16px;
|
49 |
+
border-radius: 8px;
|
50 |
font-size: 16px;
|
51 |
line-height: 1.5;
|
52 |
+
max-width: 70%;
|
53 |
+
clear: both;
|
54 |
}
|
55 |
|
56 |
.message.user {
|
57 |
+
background-color: #2c2c2c;
|
58 |
+
float: right;
|
59 |
+
border-bottom-right-radius: 2px;
|
60 |
+
border: 1px solid #404040;
|
61 |
}
|
62 |
|
63 |
.message.assistant {
|
64 |
background-color: #262626;
|
65 |
+
float: left;
|
66 |
+
border-bottom-left-radius: 2px;
|
67 |
+
border: 1px solid #333;
|
68 |
}
|
69 |
|
70 |
.controls {
|
|
|
441 |
const eventSource = new EventSource('/outputs?webrtc_id=' + webrtc_id);
|
442 |
eventSource.addEventListener("output", (event) => {
|
443 |
const eventJson = JSON.parse(event.data);
|
444 |
+
addMessage(eventJson.role, eventJson.content);
|
445 |
|
446 |
});
|
447 |
} catch (err) {
|
requirements.txt
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
fastrtc[vad]==0.0.20.rc2
|
2 |
-
pydantic==2.11.3
|
3 |
openai
|
4 |
twilio
|
5 |
python-dotenv
|
|
|
1 |
fastrtc[vad]==0.0.20.rc2
|
|
|
2 |
openai
|
3 |
twilio
|
4 |
python-dotenv
|