1
- from datetime import datetime
2
- from textwrap import dedent
3
- from typing import TYPE_CHECKING
4
-
5
1
from aiogram import F
6
2
from aiogram import types
7
-
8
3
from bot_base .core import mark_command
9
4
from bot_base .core .telegram_bot import TelegramBot
10
- from bot_base .utils .text_utils import DEFAULT_CHUNK_SIZE , DEFAULT_CHUNK_OVERLAP , \
11
- split_text_with_overlap
5
+ from bot_base .utils .text_utils import (
6
+ DEFAULT_CHUNK_SIZE ,
7
+ DEFAULT_CHUNK_OVERLAP ,
8
+ split_text_with_overlap ,
9
+ )
10
+ from datetime import datetime
11
+ from textwrap import dedent
12
+ from typing import TYPE_CHECKING
12
13
from whisper_bot .core .app_config import WhisperTelegramBotConfig
13
14
from whisper_bot .utils .text_utils import (
14
15
merge_all_chunks ,
@@ -43,11 +44,14 @@ async def process_audio(self, message: types.Message):
43
44
raw_transcript = "\n \n " .join (chunks )
44
45
self .logger .info (f"Raw transcript" , data = raw_transcript )
45
46
if self .config .send_raw_transcript :
46
- filename = f"raw_transcript_{ datetime .now ().strftime ('%Y-%m-%d_%H-%M-%S' )} .txt"
47
+ filename = (
48
+ f"raw_transcript_{ datetime .now ().strftime ('%Y-%m-%d_%H-%M-%S' )} .txt"
49
+ )
47
50
await self .send_safe (
48
- chat_id = message .chat .id , text = raw_transcript ,
51
+ chat_id = message .chat .id ,
52
+ text = raw_transcript ,
49
53
reply_to_message_id = message .message_id ,
50
- filename = filename
54
+ filename = filename ,
51
55
)
52
56
53
57
# subsplit large chunks
@@ -58,8 +62,10 @@ async def process_audio(self, message: types.Message):
58
62
self .logger .info ("Transcript" , data = transcript )
59
63
filename = f"transcript_{ datetime .now ().strftime ('%Y-%m-%d_%H-%M-%S' )} .txt"
60
64
await self .send_safe (
61
- chat_id = message .chat .id , text = transcript , reply_to_message_id = message .message_id ,
62
- filename = filename
65
+ chat_id = message .chat .id ,
66
+ text = transcript ,
67
+ reply_to_message_id = message .message_id ,
68
+ filename = filename ,
63
69
)
64
70
65
71
await placeholder .delete ()
@@ -90,8 +96,9 @@ async def chat_message_handler(self, message: types.Message):
90
96
return message_text
91
97
92
98
@staticmethod
93
- def subsplit_large_chunks (chunks , chunk_limit = DEFAULT_CHUNK_SIZE ,
94
- overlap = DEFAULT_CHUNK_OVERLAP ):
99
+ def subsplit_large_chunks (
100
+ chunks , chunk_limit = DEFAULT_CHUNK_SIZE , overlap = DEFAULT_CHUNK_OVERLAP
101
+ ):
95
102
res_chunks = []
96
103
for chunk in chunks :
97
104
res_chunks += split_text_with_overlap (chunk , chunk_limit , overlap )
@@ -107,7 +114,8 @@ async def merge_chunks_command(self, message: types.Message):
107
114
text = await self ._extract_text_from_message (message )
108
115
109
116
# remove command from text
110
- if text .startswith ("/" ): _ , text = text .split (maxsplit = 1 )
117
+ if text .startswith ("/" ):
118
+ _ , text = text .split (maxsplit = 1 )
111
119
112
120
# step 2: split chunks
113
121
chunks = text .split ("\n \n " )
@@ -122,8 +130,10 @@ async def merge_chunks_command(self, message: types.Message):
122
130
# send back the result
123
131
filename = f"merged_text_{ datetime .now ().strftime ('%Y-%m-%d_%H-%M-%S' )} .txt"
124
132
await self .send_safe (
125
- chat_id = message .chat .id , text = result , reply_to_message_id = message .message_id ,
126
- filename = filename
133
+ chat_id = message .chat .id ,
134
+ text = result ,
135
+ reply_to_message_id = message .message_id ,
136
+ filename = filename ,
127
137
)
128
138
129
139
# ------------------------------------------------------------
@@ -141,7 +151,8 @@ async def format_text_command(self, message: types.Message):
141
151
text = await self ._extract_text_from_message (message )
142
152
143
153
# remove command from text
144
- if text .startswith ("/" ): _ , text = text .split (maxsplit = 1 )
154
+ if text .startswith ("/" ):
155
+ _ , text = text .split (maxsplit = 1 )
145
156
146
157
# format the text
147
158
result = await format_text_with_gpt (
@@ -155,8 +166,10 @@ async def format_text_command(self, message: types.Message):
155
166
# send back the result
156
167
filename = f"formatted_text_{ datetime .now ().strftime ('%Y-%m-%d_%H-%M-%S' )} .txt"
157
168
await self .send_safe (
158
- chat_id = message .chat .id , text = result , reply_to_message_id = message .message_id ,
159
- filename = filename
169
+ chat_id = message .chat .id ,
170
+ text = result ,
171
+ reply_to_message_id = message .message_id ,
172
+ filename = filename ,
160
173
)
161
174
162
175
@mark_command ("fix_grammar" )
@@ -167,7 +180,8 @@ async def fix_grammar_command(self, message: types.Message):
167
180
text = await self ._extract_text_from_message (message )
168
181
169
182
# remove command from text
170
- if text .startswith ("/" ): _ , text = text .split (maxsplit = 1 )
183
+ if text .startswith ("/" ):
184
+ _ , text = text .split (maxsplit = 1 )
171
185
172
186
# format the text
173
187
result = await format_text_with_gpt (
@@ -181,8 +195,10 @@ async def fix_grammar_command(self, message: types.Message):
181
195
# send back the result
182
196
filename = f"formatted_text_{ datetime .now ().strftime ('%Y-%m-%d_%H-%M-%S' )} .txt"
183
197
await self .send_safe (
184
- chat_id = message .chat .id , text = result , reply_to_message_id = message .message_id ,
185
- filename = filename
198
+ chat_id = message .chat .id ,
199
+ text = result ,
200
+ reply_to_message_id = message .message_id ,
201
+ filename = filename ,
186
202
)
187
203
188
204
# ------------------------------------------------------------
@@ -208,8 +224,10 @@ async def merge_and_format_command(self, message: types.Message):
208
224
# send back the result
209
225
filename = f"formatted_text_{ datetime .now ().strftime ('%Y-%m-%d_%H-%M-%S' )} .txt"
210
226
await self .send_safe (
211
- chat_id = message .chat .id , text = result , reply_to_message_id = message .message_id ,
212
- filename = filename
227
+ chat_id = message .chat .id ,
228
+ text = result ,
229
+ reply_to_message_id = message .message_id ,
230
+ filename = filename ,
213
231
)
214
232
215
233
# ------------------------------------------------------------
0 commit comments