Deadmon commited on
Commit
94ab363
·
verified ·
1 Parent(s): cae33ea

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +22 -8
main.py CHANGED
@@ -3,21 +3,26 @@ import os
3
  import sys
4
  import time
5
  import logging
6
- from pipecat.frames import TextFrame, UserStartedSpeakingFrame, UserStoppedSpeakingFrame, TTSStartedFrame, TTSStoppedFrame
 
 
 
7
  from pipecat.pipeline.pipeline import Pipeline
8
  from pipecat.pipeline.runner import PipelineRunner
9
  from pipecat.pipeline.task import PipelineParams
10
  from pipecat.processors.frame_processor import FrameProcessor, FrameDirection
11
- from pipecat.services.elevenlabs.tts import ElevenLabsTTSService
12
- from pipecat.services.deepgram.stt import DeepgramSTTService
13
  from pipecat.transports.services.daily import DailyParams, DailyTransport
14
- from pipecat.audio.vad.silero import SileroVADAnalyzer
15
- from pipecat.services.openai.llm import OpenAILLMService # Use the updated OpenAI service
16
  from elevenlabs import ElevenLabs
17
 
 
18
  logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
19
  logger = logging.getLogger(__name__)
20
 
 
21
  SILENCE_TIMEOUT_SECONDS = float(os.environ.get("SILENCE_TIMEOUT_SECONDS", 10))
22
  MAX_SILENCE_PROMPTS = int(os.environ.get("MAX_SILENCE_PROMPTS", 3))
23
  SILENCE_PROMPT_TEXT = "Are you still there?"
@@ -56,7 +61,7 @@ class SilenceAndCallLogicProcessor(FrameProcessor):
56
  self.last_activity_ts = time.time()
57
  self.silence_prompts_count = 0
58
 
59
- async def process_frame(self, frame, direction):
60
  if isinstance(frame, (UserStartedSpeakingFrame, TextFrame)) and direction == FrameDirection.UPSTREAM:
61
  self._reset_activity_timer()
62
  if isinstance(frame, TTSStartedFrame) and direction == FrameDirection.DOWNSTREAM:
@@ -147,14 +152,16 @@ class PhoneChatbotApp:
147
  return False
148
 
149
  async def run(self):
 
150
  required_keys = [
151
  "deepgram", "elevenlabs", "dailyco", "azure_openai"
152
  ]
153
  missing_keys = [key for key in required_keys if not os.environ.get(key)]
154
  if missing_keys:
155
- logger.error(f"Missing environment variables: {', '.join(missing_keys)}")
156
  sys.exit(1)
157
 
 
158
  voice_id = os.environ.get("ELEVENLABS_VOICE_ID", "cgSgspJ2msm6clMCkdW9")
159
  if not self.validate_voice_id(voice_id):
160
  logger.error(f"Invalid ElevenLabs voice ID: {voice_id}")
@@ -168,7 +175,7 @@ class PhoneChatbotApp:
168
  api_key=os.environ.get("elevenlabs"),
169
  voice_id=voice_id
170
  )
171
- self.llm_service = OpenAILLMService( # Use the updated OpenAI service
172
  preprompt="You are a friendly and helpful phone assistant."
173
  )
174
  self.daily_transport = DailyTransport(
@@ -199,3 +206,10 @@ class PhoneChatbotApp:
199
  await self.pipeline.stop_when_done()
200
  if self.silence_processor:
201
  await self.silence_processor.stop()
 
 
 
 
 
 
 
 
3
  import sys
4
  import time
5
  import logging
6
+ from pipecat.frames.frames import (
7
+ TextFrame, UserStartedSpeakingFrame, UserStoppedSpeakingFrame,
8
+ TTSStartedFrame, TTSStoppedFrame
9
+ )
10
  from pipecat.pipeline.pipeline import Pipeline
11
  from pipecat.pipeline.runner import PipelineRunner
12
  from pipecat.pipeline.task import PipelineParams
13
  from pipecat.processors.frame_processor import FrameProcessor, FrameDirection
14
+ from pipecat.services.elevenlabs import ElevenLabsTTSService
15
+ from pipecat.services.deepgram import DeepgramSTTService
16
  from pipecat.transports.services.daily import DailyParams, DailyTransport
17
+ from pipecat.vad.silero import SileroVADAnalyzer
18
+ from azure_openai import AzureOpenAILLMService
19
  from elevenlabs import ElevenLabs
20
 
21
+ # Configure logging
22
  logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
23
  logger = logging.getLogger(__name__)
24
 
25
+ # Configuration constants
26
  SILENCE_TIMEOUT_SECONDS = float(os.environ.get("SILENCE_TIMEOUT_SECONDS", 10))
27
  MAX_SILENCE_PROMPTS = int(os.environ.get("MAX_SILENCE_PROMPTS", 3))
28
  SILENCE_PROMPT_TEXT = "Are you still there?"
 
61
  self.last_activity_ts = time.time()
62
  self.silence_prompts_count = 0
63
 
64
+ async def process_frame(self, frame, direction: FrameDirection):
65
  if isinstance(frame, (UserStartedSpeakingFrame, TextFrame)) and direction == FrameDirection.UPSTREAM:
66
  self._reset_activity_timer()
67
  if isinstance(frame, TTSStartedFrame) and direction == FrameDirection.DOWNSTREAM:
 
152
  return False
153
 
154
  async def run(self):
155
+ # Validate environment variables (Hugging Face Secrets)
156
  required_keys = [
157
  "deepgram", "elevenlabs", "dailyco", "azure_openai"
158
  ]
159
  missing_keys = [key for key in required_keys if not os.environ.get(key)]
160
  if missing_keys:
161
+ logger.error(f"Missing Hugging Face Secrets: {', '.join(missing_keys)}")
162
  sys.exit(1)
163
 
164
+ # Validate ElevenLabs voice ID
165
  voice_id = os.environ.get("ELEVENLABS_VOICE_ID", "cgSgspJ2msm6clMCkdW9")
166
  if not self.validate_voice_id(voice_id):
167
  logger.error(f"Invalid ElevenLabs voice ID: {voice_id}")
 
175
  api_key=os.environ.get("elevenlabs"),
176
  voice_id=voice_id
177
  )
178
+ self.llm_service = AzureOpenAILLMService(
179
  preprompt="You are a friendly and helpful phone assistant."
180
  )
181
  self.daily_transport = DailyTransport(
 
206
  await self.pipeline.stop_when_done()
207
  if self.silence_processor:
208
  await self.silence_processor.stop()
209
+
210
+ async def main():
211
+ app = PhoneChatbotApp()
212
+ await app.run()
213
+
214
+ if __name__ == "__main__":
215
+ asyncio.run(main())