IliaLarchenko commited on
Commit
755dbb1
·
1 Parent(s): 3b598e6

Improved comments and docstrings

Browse files
Files changed (1) hide show
  1. app.py +32 -3
app.py CHANGED
@@ -11,31 +11,60 @@ from utils.params import default_audio_params
11
 
12
 
13
  def initialize_services():
14
- """Initialize configuration, LLM, TTS, and STT services."""
 
 
 
 
 
15
  config = Config()
16
  llm = LLMManager(config, prompts)
17
  tts = TTSManager(config)
18
  stt = STTManager(config)
 
 
19
  default_audio_params["streaming"] = stt.streaming
 
 
20
  if os.getenv("SILENT", False):
21
  tts.read_last_message = lambda x: None
 
22
  return config, llm, tts, stt
23
 
24
 
25
  def create_interface(llm, tts, stt, audio_params):
26
- """Create and configure the Gradio interface."""
 
 
 
 
 
 
 
 
 
 
 
27
  with gr.Blocks(title="AI Interviewer", theme=gr.themes.Default()) as demo:
 
28
  audio_output = gr.Audio(label="Play audio", autoplay=True, visible=os.environ.get("DEBUG", False), streaming=tts.streaming)
 
 
29
  get_problem_solving_ui(llm, tts, stt, audio_params, audio_output).render()
30
  get_instructions_ui(llm, tts, stt, audio_params).render()
 
31
  return demo
32
 
33
 
34
  def main():
35
- """Main function to initialize services and launch the Gradio interface."""
 
 
36
  config, llm, tts, stt = initialize_services()
37
  demo = create_interface(llm, tts, stt, default_audio_params)
38
  demo.config["dependencies"][0]["show_progress"] = "hidden"
 
 
39
  demo.launch(show_api=False)
40
 
41
 
 
11
 
12
 
13
  def initialize_services():
14
+ """
15
+ Initialize configuration, LLM, TTS, and STT services.
16
+
17
+ Returns:
18
+ tuple: Containing Config, LLMManager, TTSManager, and STTManager instances.
19
+ """
20
  config = Config()
21
  llm = LLMManager(config, prompts)
22
  tts = TTSManager(config)
23
  stt = STTManager(config)
24
+
25
+ # Update default audio parameters with STT streaming setting
26
  default_audio_params["streaming"] = stt.streaming
27
+
28
+ # Disable TTS in silent mode
29
  if os.getenv("SILENT", False):
30
  tts.read_last_message = lambda x: None
31
+
32
  return config, llm, tts, stt
33
 
34
 
35
  def create_interface(llm, tts, stt, audio_params):
36
+ """
37
+ Create and configure the Gradio interface.
38
+
39
+ Args:
40
+ llm (LLMManager): Language model manager instance.
41
+ tts (TTSManager): Text-to-speech manager instance.
42
+ stt (STTManager): Speech-to-text manager instance.
43
+ audio_params (dict): Audio parameters for the interface.
44
+
45
+ Returns:
46
+ gr.Blocks: Configured Gradio interface.
47
+ """
48
  with gr.Blocks(title="AI Interviewer", theme=gr.themes.Default()) as demo:
49
+ # Create audio output component (visible only in debug mode)
50
  audio_output = gr.Audio(label="Play audio", autoplay=True, visible=os.environ.get("DEBUG", False), streaming=tts.streaming)
51
+
52
+ # Render problem-solving and instructions UI components
53
  get_problem_solving_ui(llm, tts, stt, audio_params, audio_output).render()
54
  get_instructions_ui(llm, tts, stt, audio_params).render()
55
+
56
  return demo
57
 
58
 
59
  def main():
60
+ """
61
+ Main function to initialize services and launch the Gradio interface.
62
+ """
63
  config, llm, tts, stt = initialize_services()
64
  demo = create_interface(llm, tts, stt, default_audio_params)
65
  demo.config["dependencies"][0]["show_progress"] = "hidden"
66
+
67
+ # Launch the Gradio interface
68
  demo.launch(show_api=False)
69
 
70