Celestat commited on
Commit
b580aa3
β€’
1 Parent(s): ab10969

Update run.py

Browse files
Files changed (1) hide show
  1. run.py +1 -27
run.py CHANGED
@@ -1,5 +1,5 @@
1
  import os
2
- from modules import chat_model, TTS, whisper_api, log_handler
3
  from requests.exceptions import ReadTimeout
4
  import sys
5
  import io
@@ -10,9 +10,6 @@ from config import HF_API_KEY, BOT_SYSTEM_INSTRUCTION, SYSTEM_REFRESH, BARK_SMAL
10
  au_model = TTS('./assets/audio/', BARK_SMALL_MODELS)
11
  print('TTS initialized successfully πŸ‘')
12
 
13
- # chat_model Init
14
- chat = chat_model(HF_API_KEY)
15
-
16
  # Log declaration
17
  log = log_handler('./log/log.txt')
18
 
@@ -43,29 +40,6 @@ def send_audio(text, chat_id):
43
  log.log_write('Something went wrong with send_audio:\n'+str(err))
44
  send_message(chat_id, text)
45
  return
46
-
47
- def handle_voice(message):
48
- whisper = whisper_api(HF_API_KEY)
49
- try:
50
- chat_id = message.chat.id
51
- file_info = bot.get_file(message.voice.file_id)
52
- file_path = file_info.file_path
53
- downloaded_file = bot.download_file(file_path)
54
- audio_file_path = './assets/audio/audio.ogg'
55
- with open(audio_file_path, 'wb') as f:
56
- f.write(downloaded_file)
57
-
58
- text = whisper.transcribe(audio_file_path)
59
- time.sleep(5)
60
- os.remove(audio_file_path)
61
- response = chat.query_bot(text, BOT_SYSTEM_INSTRUCTION, SYSTEM_REFRESH)
62
- send_audio(response, message.chat.id)
63
- send_message(chat_id, response)
64
- log.log_write(f'Date:{message.date} User: {message.text} Bot: {text}')
65
- except Exception as err:
66
- print('Error in handle_voice:\n'+str(err))
67
- log.fn_by_err(str(err))
68
- log.log_write('Error in handle_voice:\n'+str(err))
69
 
70
  if __name__ == "__main__":
71
  try:
 
1
  import os
2
+ from modules import TTS, log_handler
3
  from requests.exceptions import ReadTimeout
4
  import sys
5
  import io
 
10
  au_model = TTS('./assets/audio/', BARK_SMALL_MODELS)
11
  print('TTS initialized successfully πŸ‘')
12
 
 
 
 
13
  # Log declaration
14
  log = log_handler('./log/log.txt')
15
 
 
40
  log.log_write('Something went wrong with send_audio:\n'+str(err))
41
  send_message(chat_id, text)
42
  return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  if __name__ == "__main__":
45
  try: