seawolf2357 commited on
Commit
f297463
Β·
verified Β·
1 Parent(s): e9aa9e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -18,6 +18,7 @@ from fastrtc import (
18
  )
19
  from gradio.utils import get_space
20
  from openai.types.beta.realtime import ResponseAudioTranscriptDoneEvent
 
21
 
22
  load_dotenv()
23
 
@@ -49,7 +50,7 @@ class OpenAIHandler(AsyncStreamHandler):
49
  # μ‹œμŠ€ν…œ ν”„λ‘¬ν”„νŠΈ μΆ”κ°€ 및 turn_detection μ„€μ •
50
  await conn.session.update(
51
  session={
52
- "system_prompt": "λ„ˆμ˜ 이름은 'λΉ„λ“œλž˜ν”„νŠΈ'μž…λ‹ˆλ‹€. 당신은 도움이 λ˜λŠ” 정보λ₯Ό μ œκ³΅ν•˜λŠ” μ‘°μˆ˜μž…λ‹ˆλ‹€. 항상 μ •ν™•ν•˜κ³  μΉœμ ˆν•˜κ²Œ μ‘λ‹΅ν•˜μ„Έμš”.",
53
  "turn_detection": {"type": "server_vad"},
54
  }
55
  )
@@ -73,7 +74,11 @@ class OpenAIHandler(AsyncStreamHandler):
73
  _, array = frame
74
  array = array.squeeze()
75
  audio_message = base64.b64encode(array.tobytes()).decode("utf-8")
76
- await self.connection.input_audio_buffer.append(audio=audio_message) # type: ignore
 
 
 
 
77
 
78
  async def emit(self) -> tuple[int, np.ndarray] | AdditionalOutputs | None:
79
  return await wait_for_item(self.output_queue)
 
18
  )
19
  from gradio.utils import get_space
20
  from openai.types.beta.realtime import ResponseAudioTranscriptDoneEvent
21
+ from websockets.exceptions import ConnectionClosedOK
22
 
23
  load_dotenv()
24
 
 
50
  # μ‹œμŠ€ν…œ ν”„λ‘¬ν”„νŠΈ μΆ”κ°€ 및 turn_detection μ„€μ •
51
  await conn.session.update(
52
  session={
53
+ "system_prompt": "λ„ˆμ˜ 이름은 'λΉ„λ“œλž˜ν”„νŠΈ'이닀. 당신은 도움이 λ˜λŠ” 정보λ₯Ό μ œκ³΅ν•˜λŠ” μ‘°μˆ˜μž…λ‹ˆλ‹€. 항상 μ •ν™•ν•˜κ³  μΉœμ ˆν•˜κ²Œ μ‘λ‹΅ν•˜μ„Έμš”.",
54
  "turn_detection": {"type": "server_vad"},
55
  }
56
  )
 
74
  _, array = frame
75
  array = array.squeeze()
76
  audio_message = base64.b64encode(array.tobytes()).decode("utf-8")
77
+ try:
78
+ await self.connection.input_audio_buffer.append(audio=audio_message) # type: ignore
79
+ except ConnectionClosedOK:
80
+ # 연결이 μ •μƒμ μœΌλ‘œ μ’…λ£Œλœ 경우 μ˜ˆμ™Έλ₯Ό λ¬΄μ‹œν•©λ‹ˆλ‹€.
81
+ pass
82
 
83
  async def emit(self) -> tuple[int, np.ndarray] | AdditionalOutputs | None:
84
  return await wait_for_item(self.output_queue)